From: Wolfgang Bangerth Date: Tue, 18 Jan 2022 20:45:23 +0000 (-0700) Subject: Only keep track on the number of outstanding answers. X-Git-Tag: v9.4.0-rc1~593^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf19cc5f46231f99f3d3a29dad836e5ca4c275e4;p=dealii.git Only keep track on the number of outstanding answers. No longer store the ranks of the processes that we want to get something from. --- diff --git a/include/deal.II/base/mpi_consensus_algorithms.h b/include/deal.II/base/mpi_consensus_algorithms.h index dcb0a46ff2..9cb549760e 100644 --- a/include/deal.II/base/mpi_consensus_algorithms.h +++ b/include/deal.II/base/mpi_consensus_algorithms.h @@ -331,9 +331,9 @@ namespace Utilities std::vector> request_requests; /** - * The ranks of processes from which we are still expecting answers. + * The number of processes from which we are still expecting answers. */ - std::set outstanding_answers; + unsigned int n_outstanding_answers; // request for barrier MPI_Request barrier_request; diff --git a/include/deal.II/base/mpi_consensus_algorithms.templates.h b/include/deal.II/base/mpi_consensus_algorithms.templates.h index 831bde91a0..802c1c4fbb 100644 --- a/include/deal.II/base/mpi_consensus_algorithms.templates.h +++ b/include/deal.II/base/mpi_consensus_algorithms.templates.h @@ -197,7 +197,6 @@ namespace Utilities // 2) allocate memory send_requests.resize(n_targets); send_buffers.resize(n_targets); - outstanding_answers.clear(); { // 4) send and receive @@ -219,9 +218,11 @@ namespace Utilities this->comm, &send_requests[index]); AssertThrowMPI(ierr); - - outstanding_answers.insert(rank); } + + // Also record that we expect an answer from each target we sent + // a request to: + n_outstanding_answers = n_targets; } #endif } @@ -240,7 +241,7 @@ namespace Utilities // immediately with a return code that indicates whether // it has found a message from any process with a given // tag. - if (outstanding_answers.size() == 0) + if (n_outstanding_answers == 0) return true; else { @@ -267,15 +268,6 @@ namespace Utilities // one rank. Let us process it, after double checking // that it is indeed one we were still expecting: const auto target = status.MPI_SOURCE; - Assert(outstanding_answers.find(target) != - outstanding_answers.end(), - ExcMessage( - "We were expecting a message from an MPI rank " - "for which we know that messages are outstanding. But " - "we got one from an unexpected source.")); - - const int tag_deliver = Utilities::MPI::internal::Tags:: - consensus_algorithm_nbx_process_deliver; // Then query the size of the message, allocate enough memory, // receive the data, and process it. @@ -289,6 +281,9 @@ namespace Utilities std::vector recv_buffer(message_size / sizeof(T2)); { + const int tag_deliver = Utilities::MPI::internal::Tags:: + consensus_algorithm_nbx_process_deliver; + const int ierr = MPI_Recv(recv_buffer.data(), recv_buffer.size() * sizeof(T2), MPI_BYTE, @@ -303,7 +298,7 @@ namespace Utilities // Finally, remove this rank from the list of outstanding // targets: - outstanding_answers.erase(target); + --n_outstanding_answers; // We could do another go-around from the top of this // else-branch to see whether there are actually other messages @@ -313,7 +308,7 @@ namespace Utilities // places. So let it be enough for now. If there are outstanding // answers, we will get back to this function before long and // can take care of them then. - return (outstanding_answers.size() == 0); + return (n_outstanding_answers == 0); } }