From: Wolfgang Bangerth Date: Tue, 11 Jan 2022 06:35:28 +0000 (-0700) Subject: Sort the member functions of ConsensusAlgorithms::NBX. X-Git-Tag: v9.4.0-rc1~627^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13214%2Fhead;p=dealii.git Sort the member functions of ConsensusAlgorithms::NBX. In particular, sort them in the order in which they are called in the NBX::run() function. --- diff --git a/include/deal.II/base/mpi_consensus_algorithms.templates.h b/include/deal.II/base/mpi_consensus_algorithms.templates.h index b35bf3869b..15461effab 100644 --- a/include/deal.II/base/mpi_consensus_algorithms.templates.h +++ b/include/deal.II/base/mpi_consensus_algorithms.templates.h @@ -145,39 +145,58 @@ namespace Utilities template - bool - NBX::all_locally_originated_receives_are_completed() + void + NBX::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 - void - NBX::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 bool - NBX::all_remotely_originated_receives_are_completed() + NBX::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 void - NBX::start_communication() + NBX::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 + bool + NBX::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 }