From: Daniel Arndt Date: Tue, 27 Sep 2016 16:39:08 +0000 (+0200) Subject: Make sure to receive messages from the correct round X-Git-Tag: v8.5.0-rc1~615^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=992926c94fd0c62125990ecb56838ab3da5c32f8;p=dealii.git Make sure to receive messages from the correct round --- diff --git a/source/fe/fe_tools_extrapolate.cc b/source/fe/fe_tools_extrapolate.cc index 6c82be1bfb..9dae497d7c 100755 --- a/source/fe/fe_tools_extrapolate.cc +++ b/source/fe/fe_tools_extrapolate.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -342,6 +343,9 @@ namespace FETools // stores the indices of dofs on more refined ghosted cells along // with the maximum level std::map dofs_on_refined_neighbors; + + // counts the send/receive round we are in + unsigned int round; }; template <> @@ -409,6 +413,7 @@ namespace FETools template ExtrapolateImplementation:: ExtrapolateImplementation () + : round(0) {} @@ -1069,7 +1074,7 @@ namespace FETools MPI_Isend (&(*buffer)[0], buffer->size(), MPI_BYTE, it->receiver, - 123, + round, communicator, &requests[idx]); } @@ -1086,7 +1091,7 @@ namespace FETools { MPI_Status status; int len; - MPI_Probe(MPI_ANY_SOURCE, 123, communicator, &status); + MPI_Probe(MPI_ANY_SOURCE, round, communicator, &status); MPI_Get_count(&status, MPI_BYTE, &len); receive.resize (len); @@ -1191,31 +1196,27 @@ namespace FETools computed_cells, cells_to_send; - // Compute all the cells needed - // from other processes. + // reset the round count we will use in send_cells + round = 0; + + // Compute all the cells needed from other processes. compute_needs (dof2, cells_we_need); - // Send the cells needed to there - // owners and receive a list of cells other - // processes need from us. + // Send the cells needed to their owners and receive + // a list of cells other processes need from us. send_cells (cells_we_need, received_needs); - // The list of received needs can contain - // some cells more than once because different - // processes may need data from the same cell. - // To compute data only once, generate a vector - // with unique entries and distribute the computed - // data afterwards back to a vector with correct - // receivers. - // Computing cell_data can cause a need for - // data from some new cells. - // If a cell is computed, send it back to - // their senders, maybe receive new needs and - // compute again, do not wait that all cells - // are computed or all needs are collected. - // Otherwise we can run into a deadlock if - // a cell needed from another process, - // itself needs some data from us. + // The list of received needs can contain some cells more than once + // because different processes may need data from the same cell. + // To compute data only once, generate a vector with unique entries + // and distribute the computed data afterwards back to a vector with + // correct receivers. + // Computing cell_data can cause a need for data from some new cells. + // If a cell is computed, send it back to their senders, maybe receive + // new needs and compute again, do not wait that all cells are computed + // or all needs are collected. + // Otherwise we can run into a deadlock if a cell needed from another + // process itself needs some data from us. unsigned int ready = 0; do { @@ -1231,14 +1232,11 @@ namespace FETools comp != computed_cells.end (); ++comp) { - // store computed cells + // store computed cells... cell_data_insert (*comp, available_cells); - // and generate a vector - // of computed cells with - // correct receivers - // then delete this received - // need from the list + // ...and generate a vector of computed cells with correct + // receivers, then delete this received need from the list typename std::vector::iterator recv=received_needs.begin(); while (recv != received_needs.end()) { @@ -1254,9 +1252,13 @@ namespace FETools } } + // increase the round counter, such that we are sure to only send + // and receive data from the correct call + ++round; + send_cells (cells_to_send, received_cells); - // strore received cell_data + // store received cell_data for (typename std::vector::const_iterator recv=received_cells.begin (); recv != received_cells.end (); ++recv) @@ -1264,8 +1266,11 @@ namespace FETools cell_data_insert (*recv, available_cells); } - // finally send and receive new - // needs and start a new round + // increase the round counter, such that we are sure to only send + // and receive data from the correct call + ++round; + + // finally send and receive new needs and start a new round send_cells (new_needs, received_needs); } while (ready != 0);