Skip to content

Commit

Permalink
Merge pull request #76 from SCOREC/cws/describeVerbose
Browse files Browse the repository at this point in the history
verbose mode to print per rank counts
  • Loading branch information
cwsmith authored Dec 11, 2023
2 parents 8a187da + 0ea05aa commit f83c805
Showing 1 changed file with 61 additions and 32 deletions.
93 changes: 61 additions & 32 deletions src/describe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,72 @@
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());
std::ostringstream oss;

#ifdef OMEGA_H_USE_MPI
int comm_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
oss << "\nComm Rank: " << comm_rank << "\n";
#endif
auto verbose = false;
if (argc == 3) verbose = (std::string(argv[2]) == "on");

const int rank = comm->rank();

oss << "\nMesh Entity Count by Dimension: (Dim, Entities Count)\n";
std::array<Omega_h::GO, 4> counts;
for(int dim=0; dim < mesh.dim(); dim++)
oss << "(" << dim << ", " << mesh.nents(dim) << ")\n";
counts[dim] = mesh.nglobal_ents(dim);

oss << "\nImbalance by Dimension: (Dim, Imbalance)\n";
std::array<double, 4> imb;
for(int dim=0; dim < mesh.dim(); dim++)
oss << "(" << dim << ", " << mesh.imbalance(dim) << ")\n";

oss << "\nMesh Family: " << Omega_h::topological_singular_name(mesh.family(), mesh.dim()-1) << "\n";

oss << "\nTags by Dimension: (Dim, Tag, Size per Entity)\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<Omega_h::I8>(dim, tagbase->name())->array().size();
if (tagbase->type() == OMEGA_H_I32)
size = mesh.get_tag<Omega_h::I32>(dim, tagbase->name())->array().size();
if (tagbase->type() == OMEGA_H_I64)
size = mesh.get_tag<Omega_h::I64>(dim, tagbase->name())->array().size();
if (tagbase->type() == OMEGA_H_F64)
size = mesh.get_tag<Omega_h::Real>(dim, tagbase->name())->array().size();

size /= mesh.nents(dim);
oss << "(" << dim << ", " << tagbase->name().c_str() << ", " << size << ")\n";
imb[dim] = mesh.imbalance(dim);

std::ostringstream oss;
// always print two places to the right of the decimal
// for floating point types (i.e., imbalance)
oss.precision(2);
oss << std::fixed;

if(!rank) {
oss << "\nMesh Entity Type: " << Omega_h::topological_singular_name(mesh.family(), mesh.dim()-1) << "\n";

oss << "\nGlobal Mesh Entity Count and Imbalance (max/avg): (Dim, Entity Count, Imbalance)\n";
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";
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<Omega_h::I8>(dim, tagbase->name())->array().size();
if (tagbase->type() == OMEGA_H_I32)
size = mesh.get_tag<Omega_h::I32>(dim, tagbase->name())->array().size();
if (tagbase->type() == OMEGA_H_I64)
size = mesh.get_tag<Omega_h::I64>(dim, tagbase->name())->array().size();
if (tagbase->type() == OMEGA_H_F64)
size = mesh.get_tag<Omega_h::Real>(dim, tagbase->name())->array().size();

size /= mesh.nents(dim);
oss << "(" << dim << ", " << tagbase->name().c_str() << ", " << size << ")\n";
}

std::cout << oss.str();
}

oss << "\n--------------------------------------------------------\n";
std::cout << oss.str();
}
if(verbose) {
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";
}
comm->barrier(); // write the per-part data at the end
oss.str(""); // clear the stream

std::array<Omega_h::LO, 4> counts = {0,0,0,0};
for(int dim=0; dim < mesh.dim(); dim++)
counts[dim] = mesh.nents(dim);
oss << "(" << rank << ": " << counts[0] << ", "
<< counts[1] << ", "
<< counts[2] << ", "
<< counts[3] << ")\n";
std::cout << oss.str();
}
return 0;
}

0 comments on commit f83c805

Please sign in to comment.