From 89fa2e64bbf65d1a73460e63081911280b8e0225 Mon Sep 17 00:00:00 2001 From: Angelyr Date: Tue, 12 Dec 2023 19:55:03 -0500 Subject: [PATCH 01/14] print type, number of components --- src/describe.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index edd536158..be1d1664b 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -34,22 +34,31 @@ int main(int argc, char** argv) for(int dim=0; dim < mesh.dim(); dim++) oss << "(" << dim << ", " << counts[dim] << ", " << imb[dim] << ")\n"; - oss << "\nTags by Dimension: (Dim, Tag, Size per Entity)\n"; + oss << "\nTags by Dimension: (Dim, Tag, Type, Size per Number of Components)\n"; for (int dim=0; dim < mesh.dim(); dim++) for (int tag=0; tag < mesh.ntags(dim); tag++) { auto tagbase = mesh.get_tag(dim, tag); int size; - if (tagbase->type() == OMEGA_H_I8) - size = mesh.get_tag(dim, tagbase->name())->array().size(); - if (tagbase->type() == OMEGA_H_I32) - size = mesh.get_tag(dim, tagbase->name())->array().size(); - if (tagbase->type() == OMEGA_H_I64) - size = mesh.get_tag(dim, tagbase->name())->array().size(); - if (tagbase->type() == OMEGA_H_F64) - size = mesh.get_tag(dim, tagbase->name())->array().size(); + std::string type; + if (tagbase->type() == OMEGA_H_I8) { + size = Omega_h::as(tagbase)->array().size(); + type = "I8"; + } + if (tagbase->type() == OMEGA_H_I32) { + size = Omega_h::as(tagbase)->array().size(); + type = "I32"; + } + if (tagbase->type() == OMEGA_H_I64) { + size = Omega_h::as(tagbase)->array().size(); + type = "I64"; + } + if (tagbase->type() == OMEGA_H_F64) { + size = Omega_h::as(tagbase)->array().size(); + type = "F64"; + } - size /= mesh.nents(dim); - oss << "(" << dim << ", " << tagbase->name().c_str() << ", " << size << ")\n"; + size /= tagbase->ncomps(); + oss << "(" << dim << ", " << tagbase->name().c_str() << ", " << type << ", " << size << ")\n"; } std::cout << oss.str(); From fc0999301d8424274aa7067d24db9aeec4e6ebb4 Mon Sep 17 00:00:00 2001 From: Angelyr Date: Mon, 18 Dec 2023 14:25:20 -0500 Subject: [PATCH 02/14] refactor print tag info --- src/describe.cpp | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index be1d1664b..3c01da6a8 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -1,6 +1,15 @@ #include #include +#include +template +void printTagInfo(Omega_h::Mesh mesh, std::ostringstream& oss, int dim, int tag, std::string type) { + auto tagbase = mesh.get_tag(dim, tag); + auto array = Omega_h::as(tagbase)->array(); + int size = array.size(); + size /= tagbase->ncomps(); + oss << "(" << dim << ", " << tagbase->name().c_str() << ", " << type << ", " << size << ")\n"; +} int main(int argc, char** argv) { @@ -38,27 +47,14 @@ int main(int argc, char** argv) for (int dim=0; dim < mesh.dim(); dim++) for (int tag=0; tag < mesh.ntags(dim); tag++) { auto tagbase = mesh.get_tag(dim, tag); - int size; - std::string type; - if (tagbase->type() == OMEGA_H_I8) { - size = Omega_h::as(tagbase)->array().size(); - type = "I8"; - } - if (tagbase->type() == OMEGA_H_I32) { - size = Omega_h::as(tagbase)->array().size(); - type = "I32"; - } - if (tagbase->type() == OMEGA_H_I64) { - size = Omega_h::as(tagbase)->array().size(); - type = "I64"; - } - if (tagbase->type() == OMEGA_H_F64) { - size = Omega_h::as(tagbase)->array().size(); - type = "F64"; - } - - size /= tagbase->ncomps(); - oss << "(" << dim << ", " << tagbase->name().c_str() << ", " << type << ", " << size << ")\n"; + if (tagbase->type() == OMEGA_H_I8) + printTagInfo(mesh, oss, dim, tag, "I8"); + if (tagbase->type() == OMEGA_H_I32) + printTagInfo(mesh, oss, dim, tag, "I32"); + if (tagbase->type() == OMEGA_H_I64) + printTagInfo(mesh, oss, dim, tag, "I64"); + if (tagbase->type() == OMEGA_H_F64) + printTagInfo(mesh, oss, dim, tag, "F64"); } std::cout << oss.str(); From b0b12c569c8a4a49d6a6029c1ad62f56a70a6f5d Mon Sep 17 00:00:00 2001 From: Angelyr Date: Mon, 18 Dec 2023 15:08:49 -0500 Subject: [PATCH 03/14] print min and max --- src/describe.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index 3c01da6a8..d3b8c4aa3 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -1,14 +1,19 @@ #include #include #include +#include template void printTagInfo(Omega_h::Mesh mesh, std::ostringstream& oss, int dim, int tag, std::string type) { auto tagbase = mesh.get_tag(dim, tag); auto array = Omega_h::as(tagbase)->array(); - int size = array.size(); - size /= tagbase->ncomps(); - oss << "(" << dim << ", " << tagbase->name().c_str() << ", " << type << ", " << size << ")\n"; + + Omega_h::Real min = get_min(array); + Omega_h::Real max = get_max(array); + + oss << "(" << tagbase->name().c_str() << ", " << dim << ", " << type << ")\n"; + oss << "\tNum Components: " << tagbase->ncomps() << "\n"; + oss << "\tMin, Max: " << min << ", " << max << "\n\n"; } int main(int argc, char** argv) @@ -43,7 +48,7 @@ int main(int argc, char** argv) for(int dim=0; dim < mesh.dim(); dim++) oss << "(" << dim << ", " << counts[dim] << ", " << imb[dim] << ")\n"; - oss << "\nTags by Dimension: (Dim, Tag, Type, Size per Number of Components)\n"; + oss << "\nTag Properties: (Name, Dim, Type)\n"; for (int dim=0; dim < mesh.dim(); dim++) for (int tag=0; tag < mesh.ntags(dim); tag++) { auto tagbase = mesh.get_tag(dim, tag); From bfcf733fbde320dc56ed7bf7f869406530322476 Mon Sep 17 00:00:00 2001 From: Angelyr Date: Mon, 18 Dec 2023 18:08:26 -0500 Subject: [PATCH 04/14] print values --- src/describe.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/describe.cpp b/src/describe.cpp index d3b8c4aa3..36023df37 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -16,6 +16,14 @@ void printTagInfo(Omega_h::Mesh mesh, std::ostringstream& oss, int dim, int tag, oss << "\tMin, Max: " << min << ", " << max << "\n\n"; } +template +void printValue(Omega_h::Mesh mesh, std::string tagname, int dim, int value) { + auto array = mesh.get_array(dim, tagname); + auto each_eq_to = Omega_h::each_eq_to(array, value); + auto num = Omega_h::get_sum(each_eq_to); + std::cout << "Num entities: " << num << "\n"; +} + int main(int argc, char** argv) { auto lib = Omega_h::Library(&argc, &argv); @@ -82,5 +90,26 @@ int main(int argc, char** argv) << counts[3] << ")\n"; std::cout << oss.str(); } + + std::string input; + while(true) { + std::cout << "Get num entities with value: options [tagname dim value] or [exit]\n"; + + std::string name = ""; + int dim=0; + int value=0; + std::cin >> name; + if (name == "exit") break; + std::cin >> dim >> value; + auto tagbase = mesh.get_tagbase(dim, name); + if (tagbase->type() == OMEGA_H_I8) + printValue(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_I32) + printValue(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_I64) + printValue(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_F64) + printValue(mesh, name, dim, value); + } return 0; } From e8209b3282f6a945454f0e321003140a8cb04c4e Mon Sep 17 00:00:00 2001 From: Angelyr Date: Tue, 19 Dec 2023 14:12:01 -0500 Subject: [PATCH 05/14] command line print value --- src/describe.cpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index 36023df37..6d6e510f7 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -32,6 +32,21 @@ int main(int argc, char** argv) auto verbose = false; if (argc == 3) verbose = (std::string(argv[2]) == "on"); + if (argc > 3) { + std::string name = std::string(argv[3]); + int dim = atoi(argv[4]); + int value = atoi(argv[5]); + auto tagbase = mesh.get_tagbase(dim, name); + if (tagbase->type() == OMEGA_H_I8) + printValue(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_I32) + printValue(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_I64) + printValue(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_F64) + printValue(mesh, name, dim, value); + return 0; + } const int rank = comm->rank(); @@ -90,26 +105,5 @@ int main(int argc, char** argv) << counts[3] << ")\n"; std::cout << oss.str(); } - - std::string input; - while(true) { - std::cout << "Get num entities with value: options [tagname dim value] or [exit]\n"; - - std::string name = ""; - int dim=0; - int value=0; - std::cin >> name; - if (name == "exit") break; - std::cin >> dim >> value; - auto tagbase = mesh.get_tagbase(dim, name); - if (tagbase->type() == OMEGA_H_I8) - printValue(mesh, name, dim, value); - if (tagbase->type() == OMEGA_H_I32) - printValue(mesh, name, dim, value); - if (tagbase->type() == OMEGA_H_I64) - printValue(mesh, name, dim, value); - if (tagbase->type() == OMEGA_H_F64) - printValue(mesh, name, dim, value); - } return 0; } From 76c44de3d63fe029babe0218f3c75648b3033b9d Mon Sep 17 00:00:00 2001 From: Angelyr Date: Tue, 19 Dec 2023 14:59:21 -0500 Subject: [PATCH 06/14] print all all ranks --- src/describe.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index 6d6e510f7..e18a8720d 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -17,11 +17,10 @@ void printTagInfo(Omega_h::Mesh mesh, std::ostringstream& oss, int dim, int tag, } template -void printValue(Omega_h::Mesh mesh, std::string tagname, int dim, int value) { +int getNumEq(Omega_h::Mesh mesh, std::string tagname, int dim, int value) { auto array = mesh.get_array(dim, tagname); auto each_eq_to = Omega_h::each_eq_to(array, value); - auto num = Omega_h::get_sum(each_eq_to); - std::cout << "Num entities: " << num << "\n"; + return Omega_h::get_sum(each_eq_to); } int main(int argc, char** argv) @@ -32,21 +31,6 @@ int main(int argc, char** argv) auto verbose = false; if (argc == 3) verbose = (std::string(argv[2]) == "on"); - if (argc > 3) { - std::string name = std::string(argv[3]); - int dim = atoi(argv[4]); - int value = atoi(argv[5]); - auto tagbase = mesh.get_tagbase(dim, name); - if (tagbase->type() == OMEGA_H_I8) - printValue(mesh, name, dim, value); - if (tagbase->type() == OMEGA_H_I32) - printValue(mesh, name, dim, value); - if (tagbase->type() == OMEGA_H_I64) - printValue(mesh, name, dim, value); - if (tagbase->type() == OMEGA_H_F64) - printValue(mesh, name, dim, value); - return 0; - } const int rank = comm->rank(); @@ -105,5 +89,25 @@ int main(int argc, char** argv) << counts[3] << ")\n"; std::cout << oss.str(); } + + if (argc > 3) { + std::string name = std::string(argv[3]); + int dim = atoi(argv[4]); + int value = atoi(argv[5]); + auto tagbase = mesh.get_tagbase(dim, name); + int numEq = 0; + if (tagbase->type() == OMEGA_H_I8) + numEq = getNumEq(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_I32) + numEq = getNumEq(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_I64) + numEq = getNumEq(mesh, name, dim, value); + if (tagbase->type() == OMEGA_H_F64) + numEq = getNumEq(mesh, name, dim, value); + + comm->barrier(); + std::cout << "Rank, Num Entities Eq: " << rank << ", " << numEq << "\n"; + return 0; + } return 0; } From 3aaf99df7f4be786f1b4cbb4c25001a66e1d7327 Mon Sep 17 00:00:00 2001 From: Angelyr Date: Tue, 19 Dec 2023 15:37:01 -0500 Subject: [PATCH 07/14] refactor --- src/describe.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index e18a8720d..a08bb74f5 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -30,7 +30,7 @@ int main(int argc, char** argv) Omega_h::Mesh mesh = Omega_h::read_mesh_file(argv[1], lib.world()); auto verbose = false; - if (argc == 3) verbose = (std::string(argv[2]) == "on"); + if (argc >= 3) verbose = (std::string(argv[2]) == "on"); const int rank = comm->rank(); @@ -105,8 +105,9 @@ int main(int argc, char** argv) if (tagbase->type() == OMEGA_H_F64) numEq = getNumEq(mesh, name, dim, value); + if (!rank) std::cout << "\nInput: (" << name << " " << dim << " " << value <<"), Output: (Rank, Num Entities Equal to Value)\n"; comm->barrier(); - std::cout << "Rank, Num Entities Eq: " << rank << ", " << numEq << "\n"; + std::cout << "(" << rank << ", " << numEq << ")\n"; return 0; } return 0; From 6bafdefb49a8daced41b2f8e6894730d68dc3b54 Mon Sep 17 00:00:00 2001 From: Angelyr Date: Tue, 19 Dec 2023 15:56:29 -0500 Subject: [PATCH 08/14] changed comment --- src/describe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/describe.cpp b/src/describe.cpp index a08bb74f5..4411c5bef 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -55,7 +55,7 @@ int main(int argc, char** argv) for(int dim=0; dim < mesh.dim(); dim++) oss << "(" << dim << ", " << counts[dim] << ", " << imb[dim] << ")\n"; - oss << "\nTag Properties: (Name, Dim, Type)\n"; + oss << "\nTag Properties by Dimension: (Name, Dim, Type)\n"; for (int dim=0; dim < mesh.dim(); dim++) for (int tag=0; tag < mesh.ntags(dim); tag++) { auto tagbase = mesh.get_tag(dim, tag); From 5f78828b7b3630bb68dc652c1acd6d1b1bb4754a Mon Sep 17 00:00:00 2001 From: Angelyr Date: Thu, 21 Dec 2023 13:14:09 -0500 Subject: [PATCH 09/14] print in one line --- src/describe.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index 4411c5bef..99e43f01d 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -2,6 +2,7 @@ #include #include #include +#include template void printTagInfo(Omega_h::Mesh mesh, std::ostringstream& oss, int dim, int tag, std::string type) { @@ -11,9 +12,13 @@ void printTagInfo(Omega_h::Mesh mesh, std::ostringstream& oss, int dim, int tag, Omega_h::Real min = get_min(array); Omega_h::Real max = get_max(array); - oss << "(" << tagbase->name().c_str() << ", " << dim << ", " << type << ")\n"; - oss << "\tNum Components: " << tagbase->ncomps() << "\n"; - oss << "\tMin, Max: " << min << ", " << max << "\n\n"; + oss << std::setw(18) << std::left << tagbase->name().c_str() + << std::setw(5) << std::left << dim + << std::setw(7) << std::left << type + << std::setw(5) << std::left << tagbase->ncomps() + << std::setw(10) << std::left << min + << std::setw(10) << std::left << max + << "\n"; } template @@ -55,7 +60,7 @@ int main(int argc, char** argv) for(int dim=0; dim < mesh.dim(); dim++) oss << "(" << dim << ", " << counts[dim] << ", " << imb[dim] << ")\n"; - oss << "\nTag Properties by Dimension: (Name, Dim, Type)\n"; + oss << "\nTag Properties by Dimension: (Name, Dim, Type, Number of Components, Min. Value, Max. Value)\n"; for (int dim=0; dim < mesh.dim(); dim++) for (int tag=0; tag < mesh.ntags(dim); tag++) { auto tagbase = mesh.get_tag(dim, tag); From f4c954a9ae0b6557b9d6abc95ec3b118202fbe32 Mon Sep 17 00:00:00 2001 From: Angelyr Date: Thu, 21 Dec 2023 15:09:34 -0500 Subject: [PATCH 10/14] use omega_h cmdline --- src/describe.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index 99e43f01d..3f4018de1 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include template @@ -32,10 +33,22 @@ int main(int argc, char** argv) { auto lib = Omega_h::Library(&argc, &argv); auto comm = lib.world(); - Omega_h::Mesh mesh = Omega_h::read_mesh_file(argv[1], lib.world()); - auto verbose = false; - if (argc >= 3) verbose = (std::string(argv[2]) == "on"); + Omega_h::CmdLine cmdline; + cmdline.add_arg("mesh.osh"); + cmdline.add_flag("-v", "verbose"); + auto& tagInfoFlag = cmdline.add_flag("--tag-info", "space seperated \"name dim value\""); + tagInfoFlag.add_arg("name"); + tagInfoFlag.add_arg("dim"); + tagInfoFlag.add_arg("value"); + if (!cmdline.parse(comm, &argc, argv) || + !Omega_h::CmdLine::check_empty(comm, argc, argv)) { + cmdline.show_help(comm, argv); + return -1; + } + + std::string meshPath = cmdline.get("mesh.osh"); + Omega_h::Mesh mesh = Omega_h::read_mesh_file(meshPath, lib.world()); const int rank = comm->rank(); @@ -77,7 +90,7 @@ int main(int argc, char** argv) std::cout << oss.str(); } - if(verbose) { + if(cmdline.parsed("-v")) { comm->barrier(); // write the per-part data at the end if(!rank) { std::cout << "\nPer Rank Mesh Entity Count: (Rank: Entity Count by Dim <0,1,2,3>)\n"; @@ -95,10 +108,10 @@ int main(int argc, char** argv) std::cout << oss.str(); } - if (argc > 3) { - std::string name = std::string(argv[3]); - int dim = atoi(argv[4]); - int value = atoi(argv[5]); + if (cmdline.parsed("--tag-info")) { + std::string name = cmdline.get("--tag-info", "name"); + int dim = cmdline.get("--tag-info", "dim"); + int value = cmdline.get("--tag-info", "value"); auto tagbase = mesh.get_tagbase(dim, name); int numEq = 0; if (tagbase->type() == OMEGA_H_I8) From bef611bbf3affa32de6e24008fb3eab70a04c846 Mon Sep 17 00:00:00 2001 From: Angelyr Date: Thu, 21 Dec 2023 18:25:30 -0500 Subject: [PATCH 11/14] print owned --- src/describe.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/describe.cpp b/src/describe.cpp index 3f4018de1..e565d1262 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -106,6 +106,18 @@ int main(int argc, char** argv) << counts[2] << ", " << counts[3] << ")\n"; std::cout << oss.str(); + + comm->barrier(); + if (!rank) std::cout << "\nPer Rank Mesh Entity Owned: (Rank: Entity Owned by Dim <0,1,2,3>)\n"; + comm->barrier(); + oss.str(""); // clear the stream + for (int dim=0; dim < mesh.dim(); dim++) + counts[dim] = mesh.nents_owned(dim); + oss << "(" << rank << ": " << counts[0] << ", " + << counts[1] << ", " + << counts[2] << ", " + << counts[3] << ")\n"; + std::cout << oss.str(); } if (cmdline.parsed("--tag-info")) { From 33061298e7cea6361ffecd3ba872651c157ee68e Mon Sep 17 00:00:00 2001 From: Angelyr Date: Thu, 21 Dec 2023 19:23:07 -0500 Subject: [PATCH 12/14] print mpi char --- src/describe.cpp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index e565d1262..6a4429ae7 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -29,6 +29,16 @@ int getNumEq(Omega_h::Mesh mesh, std::string tagname, int dim, int value) { return Omega_h::get_sum(each_eq_to); } +void printMPIChar(int sender) { + MPI_Status status; + MPI_Probe(sender, 0, MPI_COMM_WORLD, &status); + int count; + MPI_Get_count(&status, MPI_CHAR, &count); + char buf [count]; + MPI_Recv(&buf, count, MPI_CHAR, sender, 0, MPI_COMM_WORLD, &status); + std::cout << buf; +} + int main(int argc, char** argv) { auto lib = Omega_h::Library(&argc, &argv); @@ -105,19 +115,24 @@ int main(int argc, char** argv) << counts[1] << ", " << counts[2] << ", " << counts[3] << ")\n"; - std::cout << oss.str(); + if (rank) { + MPI_Send(oss.str().c_str(), oss.str().size(), MPI_CHAR, 0, 0, MPI_COMM_WORLD); + } else for (int i=1; i < comm->size(); i++) { + std::cout << oss.str(); + printMPIChar(i); + } - comm->barrier(); - if (!rank) std::cout << "\nPer Rank Mesh Entity Owned: (Rank: Entity Owned by Dim <0,1,2,3>)\n"; - comm->barrier(); - oss.str(""); // clear the stream - for (int dim=0; dim < mesh.dim(); dim++) - counts[dim] = mesh.nents_owned(dim); - oss << "(" << rank << ": " << counts[0] << ", " - << counts[1] << ", " - << counts[2] << ", " - << counts[3] << ")\n"; - std::cout << oss.str(); + // comm->barrier(); + // if (!rank) std::cout << "\nPer Rank Mesh Entity Owned: (Rank: Entity Owned by Dim <0,1,2,3>)\n"; + // comm->barrier(); + // oss.str(""); // clear the stream + // for (int dim=0; dim < mesh.dim(); dim++) + // counts[dim] = mesh.nents_owned(dim); + // oss << "(" << rank << ": " << counts[0] << ", " + // << counts[1] << ", " + // << counts[2] << ", " + // << counts[3] << ")\n"; + // std::cout << oss.str(); } if (cmdline.parsed("--tag-info")) { From 0dfc40f19977e252563939b66eefedbc570f436d Mon Sep 17 00:00:00 2001 From: Angelyr Date: Thu, 21 Dec 2023 19:39:41 -0500 Subject: [PATCH 13/14] printMPIChar twice --- src/describe.cpp | 51 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/describe.cpp b/src/describe.cpp index 6a4429ae7..725a3b0f7 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -29,14 +29,20 @@ int getNumEq(Omega_h::Mesh mesh, std::string tagname, int dim, int value) { return Omega_h::get_sum(each_eq_to); } -void printMPIChar(int sender) { - MPI_Status status; - MPI_Probe(sender, 0, MPI_COMM_WORLD, &status); - int count; - MPI_Get_count(&status, MPI_CHAR, &count); - char buf [count]; - MPI_Recv(&buf, count, MPI_CHAR, sender, 0, MPI_COMM_WORLD, &status); - std::cout << buf; +void printMPIChar(std::string output, int comm_size, int comm_rank) { + + if (comm_rank) { + MPI_Send(output.c_str(), output.size(), MPI_CHAR, 0, 0, MPI_COMM_WORLD); + } else for (int sender=1; sender < comm_size; sender++) { + std::cout << output; + MPI_Status status; + MPI_Probe(sender, 0, MPI_COMM_WORLD, &status); + int count; + MPI_Get_count(&status, MPI_CHAR, &count); + char buf [count]; + MPI_Recv(&buf, count, MPI_CHAR, sender, 0, MPI_COMM_WORLD, &status); + std::cout << buf; + } } int main(int argc, char** argv) @@ -105,7 +111,6 @@ int main(int argc, char** argv) if(!rank) { std::cout << "\nPer Rank Mesh Entity Count: (Rank: Entity Count by Dim <0,1,2,3>)\n"; } - comm->barrier(); // write the per-part data at the end oss.str(""); // clear the stream std::array counts = {0,0,0,0}; @@ -115,24 +120,18 @@ int main(int argc, char** argv) << counts[1] << ", " << counts[2] << ", " << counts[3] << ")\n"; - if (rank) { - MPI_Send(oss.str().c_str(), oss.str().size(), MPI_CHAR, 0, 0, MPI_COMM_WORLD); - } else for (int i=1; i < comm->size(); i++) { - std::cout << oss.str(); - printMPIChar(i); - } + printMPIChar(oss.str(), comm->size(), rank); - // comm->barrier(); - // if (!rank) std::cout << "\nPer Rank Mesh Entity Owned: (Rank: Entity Owned by Dim <0,1,2,3>)\n"; - // comm->barrier(); - // oss.str(""); // clear the stream - // for (int dim=0; dim < mesh.dim(); dim++) - // counts[dim] = mesh.nents_owned(dim); - // oss << "(" << rank << ": " << counts[0] << ", " - // << counts[1] << ", " - // << counts[2] << ", " - // << counts[3] << ")\n"; - // std::cout << oss.str(); + comm->barrier(); + if (!rank) std::cout << "\nPer Rank Mesh Entity Owned: (Rank: Entity Owned by Dim <0,1,2,3>)\n"; + oss.str(""); // clear the stream + for (int dim=0; dim < mesh.dim(); dim++) + counts[dim] = mesh.nents_owned(dim); + oss << "(" << rank << ": " << counts[0] << ", " + << counts[1] << ", " + << counts[2] << ", " + << counts[3] << ")\n"; + printMPIChar(oss.str(), comm->size(), rank); } if (cmdline.parsed("--tag-info")) { From 9c1e765bcc56d4356905d9392d9cdd684aa3c4d9 Mon Sep 17 00:00:00 2001 From: Angelyr Date: Thu, 21 Dec 2023 20:20:52 -0500 Subject: [PATCH 14/14] check mpi usage --- src/describe.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/describe.cpp b/src/describe.cpp index 725a3b0f7..b04a0da0c 100644 --- a/src/describe.cpp +++ b/src/describe.cpp @@ -30,7 +30,7 @@ int getNumEq(Omega_h::Mesh mesh, std::string tagname, int dim, int value) { } void printMPIChar(std::string output, int comm_size, int comm_rank) { - +#ifdef OMEGA_H_USE_MPI if (comm_rank) { MPI_Send(output.c_str(), output.size(), MPI_CHAR, 0, 0, MPI_COMM_WORLD); } else for (int sender=1; sender < comm_size; sender++) { @@ -43,6 +43,9 @@ void printMPIChar(std::string output, int comm_size, int comm_rank) { MPI_Recv(&buf, count, MPI_CHAR, sender, 0, MPI_COMM_WORLD, &status); std::cout << buf; } +#else + std::cout << output; +#endif } int main(int argc, char** argv)