Skip to content

Commit

Permalink
Incorporate recommended improvements from KT.
Browse files Browse the repository at this point in the history
+ Replace push_back with emplace_back in dual ghost map generation.
+ Add unit tests of [in]determinate_allgatherv specializations.
+ Fix else branch (missing) in logic for other gatherv unit tests.
  • Loading branch information
RyanWollaeger committed Jul 6, 2021
1 parent 47063e1 commit 113d7e6
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 20 deletions.
124 changes: 108 additions & 16 deletions src/c4/test/tstGatherScatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void tstIndeterminateGatherScatterv(UnitTest &ut) {
for (unsigned p = 0; p < number_of_processors; ++p) {
if (receive[p].size() != p) {
FAILMSG("NOT correct number of elements in gatherv");
} else {
for (unsigned i = 0; i < p; ++i) {
if (receive[p][i] != p)
FAILMSG("NOT correct values in gatherv");
Expand Down Expand Up @@ -137,6 +138,7 @@ void tstIndeterminateGatherScatterv(UnitTest &ut) {
for (unsigned p = 0; p < number_of_processors; ++p) {
if (receive[p].size() != p) {
FAILMSG("NOT correct number of elements in gatherv");
} else {
for (unsigned i = 0; i < p; ++i) {
if (!rtt_dsxx::soft_equiv(receive[p][i], static_cast<double>(p)))
FAILMSG("NOT correct values in gatherv");
Expand Down Expand Up @@ -175,6 +177,7 @@ void tstIndeterminateGatherScatterv(UnitTest &ut) {
for (unsigned p = 0; p < number_of_processors; ++p) {
if (receive[p].size() != p) {
FAILMSG("NOT correct number of elements in gatherv");
} else {
for (unsigned i = 0; i < p; ++i) {
if (receive[p][i] != static_cast<int>(p))
FAILMSG("NOT correct values in gatherv");
Expand Down Expand Up @@ -206,21 +209,15 @@ void tstIndeterminateGatherScatterv(UnitTest &ut) {
indeterminate_gatherv(emptysend, emptyreceive);
PASSMSG("No exception thrown for indeterminate_gatherv with empty containers.");

if (emptysend.size() != 0)
ITFAILS;
if (emptyreceive.size() != number_of_processors)
ITFAILS;
if (emptyreceive[pid].size() != 0)
ITFAILS;
FAIL_IF(emptysend.size() != 0);
FAIL_IF(emptyreceive.size() != number_of_processors);
FAIL_IF(emptyreceive[pid].size() != 0);

indeterminate_scatterv(emptyreceive, emptysend);

if (emptysend.size() != 0)
ITFAILS;
if (emptyreceive.size() != number_of_processors)
ITFAILS;
if (emptyreceive[pid].size() != 0)
ITFAILS;
FAIL_IF(emptysend.size() != 0);
FAIL_IF(emptyreceive.size() != number_of_processors);
FAIL_IF(emptyreceive[pid].size() != 0);
}

return;
Expand Down Expand Up @@ -249,6 +246,7 @@ void tstDeterminateGatherScatterv(UnitTest &ut) {
for (unsigned p = 0; p < number_of_processors; ++p) {
if (receive[p].size() != p) {
FAILMSG("NOT correct number of elements in gatherv");
} else {
for (unsigned i = 0; i < p; ++i) {
if (receive[p][i] != p)
FAILMSG("NOT correct values in gatherv");
Expand Down Expand Up @@ -292,6 +290,7 @@ void tstDeterminateGatherScatterv(UnitTest &ut) {
for (unsigned p = 0; p < number_of_processors; ++p) {
if (receive[p].size() != p) {
FAILMSG("NOT correct number of elements in gatherv");
} else {
for (unsigned i = 0; i < p; ++i) {
if (!rtt_dsxx::soft_equiv(receive[p][i], static_cast<double>(p)))
FAILMSG("NOT correct values in gatherv");
Expand Down Expand Up @@ -335,6 +334,7 @@ void tstDeterminateGatherScatterv(UnitTest &ut) {
for (unsigned p = 0; p < number_of_processors; ++p) {
if (receive[p].size() != p) {
FAILMSG("NOT correct number of elements in gatherv");
} else {
for (unsigned i = 0; i < p; ++i) {
if (receive[p][i] != static_cast<int>(p))
FAILMSG("NOT correct values in gatherv");
Expand Down Expand Up @@ -378,6 +378,7 @@ void tstDeterminateGatherScatterv(UnitTest &ut) {
for (unsigned p = 0; p < number_of_processors; ++p) {
if (receive[p].size() != p) {
FAILMSG("NOT correct number of elements in gatherv");
} else {
for (unsigned i = 0; i < p; ++i) {
if (receive[p][i] != 'A')
FAILMSG("NOT correct values in gatherv");
Expand Down Expand Up @@ -414,8 +415,7 @@ void topology_report(UnitTest &ut) {
// Look at the data found on the IO proc.
if (my_mpi_rank == 0) {

if (procnames[my_mpi_rank].size() != namelen)
ITFAILS;
FAIL_IF(procnames[my_mpi_rank].size() != namelen);

// Count unique processors
vector<string> unique_processor_names;
Expand All @@ -434,8 +434,7 @@ void topology_report(UnitTest &ut) {

for (size_t i = 0; i < mpi_ranks; ++i) {
std::cout << "\n - MPI rank " << i << " is on " << procnames[i];
if (procnames[i].size() < 1)
ITFAILS;
FAIL_IF(procnames[i].size() < 1);
}
std::cout << std::endl;

Expand Down Expand Up @@ -464,6 +463,97 @@ void topology_report(UnitTest &ut) {
return;
}

//------------------------------------------------------------------------------------------------//
void tstDeterminateAllGatherv(UnitTest &ut) {
unsigned const pid = node();
unsigned const number_of_processors = nodes();

{ // T=unsigned
vector<unsigned> send(pid, pid);

// determinate_allgatherv already has the data sizes from the other MPI/C4 ranks/nodes
vector<vector<unsigned>> receive(number_of_processors);
for (unsigned p = 0; p < number_of_processors; ++p)
receive[p].resize(p);

// gather data from all nodes to all nodes at rank index in receive vector
determinate_allgatherv(send, receive);
PASSMSG("No exception thrown");

// check values gathered from each rank (and check on each rank of course)
for (unsigned p = 0; p < number_of_processors; ++p) {
for (unsigned i = 0; i < p; ++i) {
if (receive[p][i] != p)
FAILMSG("NOT correct values in allgatherv");
}
}
}

{ // T=double
vector<double> send(pid, static_cast<double>(pid));

// determinate_allgatherv already has the data sizes from the other MPI/C4 ranks/nodes
vector<vector<double>> receive(number_of_processors);
for (unsigned p = 0; p < number_of_processors; ++p)
receive[p].resize(p);

// gather data from all nodes to all nodes at rank index in receive vector
determinate_allgatherv(send, receive);
PASSMSG("No exception thrown");

// check values gathered from each rank (and check on each rank of course)
for (unsigned p = 0; p < number_of_processors; ++p) {
const double p_dbl = static_cast<double>(p);
for (unsigned i = 0; i < p; ++i) {
if (receive[p][i] != p_dbl)
FAILMSG("NOT correct values in allgatherv");
}
}
}

// successful test output
if (ut.numFails == 0)
PASSMSG("tstDeterminateAllGatherv tests ok.");
return;
}

//------------------------------------------------------------------------------------------------//
void tstIndeterminateAllGatherv(UnitTest &ut) {
unsigned const pid = node();
unsigned const number_of_processors = nodes();

// T=unsigned
vector<unsigned> send(pid, pid);
vector<vector<unsigned>> receive;

// gather data from all nodes to all nodes at rank index in receive vector
indeterminate_allgatherv(send, receive);
PASSMSG("No exception thrown");

// check the size of the receiving vector is now the number of MPI/C4 ranks/nodes
if (receive.size() == number_of_processors)
PASSMSG("correct number of processors in allgatherv");
else
FAILMSG("NOT correct number of processors in allgatherv");

// check values gathered from each rank (and check on each rank of course)
for (unsigned p = 0; p < number_of_processors; ++p) {
if (receive[p].size() != p) {
FAILMSG("NOT correct number of elements in allgatherv");
} else {
for (unsigned i = 0; i < p; ++i) {
if (receive[p][i] != p)
FAILMSG("NOT correct values in allgatherv");
}
}
}

// successful test output
if (ut.numFails == 0)
PASSMSG("tstIndeterminateAllGatherv tests ok.");
return;
}

//------------------------------------------------------------------------------------------------//
int main(int argc, char *argv[]) {
rtt_c4::ParallelUnitTest ut(argc, argv, release);
Expand All @@ -473,6 +563,8 @@ int main(int argc, char *argv[]) {
tstIndeterminateGatherScatterv(ut);
tstDeterminateGatherScatterv(ut);
topology_report(ut);
tstDeterminateAllGatherv(ut);
tstIndeterminateAllGatherv(ut);
}
UT_EPILOG(ut);
}
Expand Down
8 changes: 4 additions & 4 deletions src/mesh/Draco_Mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,14 @@ void Draco_Mesh::compute_node_to_cell_linkage(
cellnodes_per_serial_per_rank[rank][3 * i + 2]};

// accumulate local cells and neighbor nodes (for rank) adjacent to this global node
ghost_dualmap_per_rank[rank][global_node].push_back(std::make_pair(local_cell, node_nbrs));
ghost_dualmap_per_rank[rank][global_node].emplace_back(std::make_pair(local_cell, node_nbrs));

// accumulate neighbor node coordinates (in same order as node indices about global_node)
const std::array<double, 2> crd_nbr1 = {coord_nbrs_per_serial_per_rank[rank][4 * i],
coord_nbrs_per_serial_per_rank[rank][4 * i + 1]};
const std::array<double, 2> crd_nbr2 = {coord_nbrs_per_serial_per_rank[rank][4 * i + 2],
coord_nbrs_per_serial_per_rank[rank][4 * i + 3]};
ghost_coord_nbrs_per_rank[rank][global_node].push_back(std::make_pair(crd_nbr1, crd_nbr2));
ghost_coord_nbrs_per_rank[rank][global_node].emplace_back(std::make_pair(crd_nbr1, crd_nbr2));
}
}

Expand Down Expand Up @@ -690,11 +690,11 @@ void Draco_Mesh::compute_node_to_cell_linkage(

// append each local-cell-rank pair to dual ghost layout
for (auto local_cellnodes : ghost_dualmap_per_rank[rank].at(gl_node))
node_to_ghost_cell_linkage[node].push_back(std::make_pair(local_cellnodes, rank));
node_to_ghost_cell_linkage[node].emplace_back(std::make_pair(local_cellnodes, rank));

// append each ghost coordinate pair bounding a ghost cell neighboring this node
for (auto coord_nbrs : ghost_coord_nbrs_per_rank[rank].at(gl_node))
node_to_ghost_coord_linkage[node].push_back(coord_nbrs);
node_to_ghost_coord_linkage[node].emplace_back(coord_nbrs);
}
}

Expand Down

0 comments on commit 113d7e6

Please sign in to comment.