]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Sort the member functions of ConsensusAlgorithms::NBX. 13214/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 11 Jan 2022 06:35:28 +0000 (23:35 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 11 Jan 2022 06:35:28 +0000 (23:35 -0700)
In particular, sort them in the order in which they are called in the NBX::run() function.

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

index b35bf3869bac8b1aab9c94fb636513684b9f9529..15461effabd244378c24e4ede3f670acad68c21c 100644 (file)
@@ -145,39 +145,58 @@ namespace Utilities
 
 
       template <typename T1, typename T2>
-      bool
-      NBX<T1, T2>::all_locally_originated_receives_are_completed()
+      void
+      NBX<T1, T2>::start_communication()
       {
 #ifdef DEAL_II_WITH_MPI
-        int        all_receive_requests_are_done;
-        const auto ierr = MPI_Testall(recv_requests.size(),
-                                      recv_requests.data(),
-                                      &all_receive_requests_are_done,
-                                      MPI_STATUSES_IGNORE);
-        AssertThrowMPI(ierr);
+        // 1)
+        targets              = this->process.compute_targets();
+        const auto n_targets = targets.size();
 
-        return all_receive_requests_are_done != 0;
-#else
-        return true;
-#endif
-      }
+        const int tag_request = Utilities::MPI::internal::Tags::
+          consensus_algorithm_nbx_answer_request;
+        const int tag_deliver = Utilities::MPI::internal::Tags::
+          consensus_algorithm_nbx_process_deliver;
 
+        // 2) allocate memory
+        recv_buffers.resize(n_targets);
+        recv_requests.resize(n_targets);
+        send_requests.resize(n_targets);
+        send_buffers.resize(n_targets);
 
+        {
+          // 4) send and receive
+          for (unsigned int index = 0; index < n_targets; ++index)
+            {
+              const unsigned int rank = targets[index];
 
-      template <typename T1, typename T2>
-      void
-      NBX<T1, T2>::signal_finish()
-      {
-#ifdef DEAL_II_WITH_MPI
-#  if DEAL_II_MPI_VERSION_GTE(3, 0)
-        const auto ierr = MPI_Ibarrier(this->comm, &barrier_request);
-        AssertThrowMPI(ierr);
-#  else
-        AssertThrow(
-          false,
-          ExcMessage(
-            "ConsensusAlgorithms::NBX uses MPI 3.0 features. You should compile with at least MPI 3.0."));
-#  endif
+              auto &send_buffer = send_buffers[index];
+              this->process.create_request(rank, send_buffer);
+
+              // Post a request to send data
+              auto ierr = MPI_Isend(send_buffer.data(),
+                                    send_buffer.size() * sizeof(T1),
+                                    MPI_BYTE,
+                                    rank,
+                                    tag_request,
+                                    this->comm,
+                                    &send_requests[index]);
+              AssertThrowMPI(ierr);
+
+              // Post a request to receive data from the same
+              // process we sent information to above:
+              auto &recv_buffer = recv_buffers[index];
+              this->process.prepare_buffer_for_answer(rank, recv_buffer);
+              ierr = MPI_Irecv(recv_buffer.data(),
+                               recv_buffer.size() * sizeof(T2),
+                               MPI_BYTE,
+                               rank,
+                               tag_deliver,
+                               this->comm,
+                               &recv_requests[index]);
+              AssertThrowMPI(ierr);
+            }
+        }
 #endif
       }
 
@@ -185,15 +204,17 @@ namespace Utilities
 
       template <typename T1, typename T2>
       bool
-      NBX<T1, T2>::all_remotely_originated_receives_are_completed()
+      NBX<T1, T2>::all_locally_originated_receives_are_completed()
       {
 #ifdef DEAL_II_WITH_MPI
-        int        all_ranks_reached_barrier;
-        const auto ierr = MPI_Test(&barrier_request,
-                                   &all_ranks_reached_barrier,
-                                   MPI_STATUSES_IGNORE);
+        int        all_receive_requests_are_done;
+        const auto ierr = MPI_Testall(recv_requests.size(),
+                                      recv_requests.data(),
+                                      &all_receive_requests_are_done,
+                                      MPI_STATUSES_IGNORE);
         AssertThrowMPI(ierr);
-        return all_ranks_reached_barrier != 0;
+
+        return all_receive_requests_are_done != 0;
 #else
         return true;
 #endif
@@ -282,57 +303,36 @@ namespace Utilities
 
       template <typename T1, typename T2>
       void
-      NBX<T1, T2>::start_communication()
+      NBX<T1, T2>::signal_finish()
       {
 #ifdef DEAL_II_WITH_MPI
-        // 1)
-        targets              = this->process.compute_targets();
-        const auto n_targets = targets.size();
-
-        const int tag_request = Utilities::MPI::internal::Tags::
-          consensus_algorithm_nbx_answer_request;
-        const int tag_deliver = Utilities::MPI::internal::Tags::
-          consensus_algorithm_nbx_process_deliver;
-
-        // 2) allocate memory
-        recv_buffers.resize(n_targets);
-        recv_requests.resize(n_targets);
-        send_requests.resize(n_targets);
-        send_buffers.resize(n_targets);
-
-        {
-          // 4) send and receive
-          for (unsigned int index = 0; index < n_targets; ++index)
-            {
-              const unsigned int rank = targets[index];
+#  if DEAL_II_MPI_VERSION_GTE(3, 0)
+        const auto ierr = MPI_Ibarrier(this->comm, &barrier_request);
+        AssertThrowMPI(ierr);
+#  else
+        AssertThrow(
+          false,
+          ExcMessage(
+            "ConsensusAlgorithms::NBX uses MPI 3.0 features. You should compile with at least MPI 3.0."));
+#  endif
+#endif
+      }
 
-              auto &send_buffer = send_buffers[index];
-              this->process.create_request(rank, send_buffer);
 
-              // Post a request to send data
-              auto ierr = MPI_Isend(send_buffer.data(),
-                                    send_buffer.size() * sizeof(T1),
-                                    MPI_BYTE,
-                                    rank,
-                                    tag_request,
-                                    this->comm,
-                                    &send_requests[index]);
-              AssertThrowMPI(ierr);
 
-              // Post a request to receive data from the same
-              // process we sent information to above:
-              auto &recv_buffer = recv_buffers[index];
-              this->process.prepare_buffer_for_answer(rank, recv_buffer);
-              ierr = MPI_Irecv(recv_buffer.data(),
-                               recv_buffer.size() * sizeof(T2),
-                               MPI_BYTE,
-                               rank,
-                               tag_deliver,
-                               this->comm,
-                               &recv_requests[index]);
-              AssertThrowMPI(ierr);
-            }
-        }
+      template <typename T1, typename T2>
+      bool
+      NBX<T1, T2>::all_remotely_originated_receives_are_completed()
+      {
+#ifdef DEAL_II_WITH_MPI
+        int        all_ranks_reached_barrier;
+        const auto ierr = MPI_Test(&barrier_request,
+                                   &all_ranks_reached_barrier,
+                                   MPI_STATUSES_IGNORE);
+        AssertThrowMPI(ierr);
+        return all_ranks_reached_barrier != 0;
+#else
+        return true;
 #endif
       }
 

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.