]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Only keep track on the number of outstanding answers. 13219/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 18 Jan 2022 20:45:23 +0000 (13:45 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 18 Jan 2022 20:47:51 +0000 (13:47 -0700)
No longer store the ranks of the processes that we want to get something from.

include/deal.II/base/mpi_consensus_algorithms.h
include/deal.II/base/mpi_consensus_algorithms.templates.h

index dcb0a46ff26b4801e1c1aef3e6490f6d9b358e1a..9cb549760ed9aa7887942724ece2ba5d9e077389 100644 (file)
@@ -331,9 +331,9 @@ namespace Utilities
         std::vector<std::unique_ptr<MPI_Request>> 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<unsigned int> outstanding_answers;
+        unsigned int n_outstanding_answers;
 
         // request for barrier
         MPI_Request barrier_request;
index 831bde91a0c8c8dcb27ea80c3f9b0192e5152c54..802c1c4fbbd34e7f43f9ed5b03662d9de502f4e0 100644 (file)
@@ -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<T2> 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);
               }
           }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.