From 1a3671624698cbff4aab9f8f1c7eb88def5ef49b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 12 Jan 2022 21:10:38 -0700 Subject: [PATCH] Sort PEX member functions in the order in which they are called. --- .../deal.II/base/mpi_consensus_algorithms.h | 14 +- .../base/mpi_consensus_algorithms.templates.h | 122 +++++++++--------- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/include/deal.II/base/mpi_consensus_algorithms.h b/include/deal.II/base/mpi_consensus_algorithms.h index 814bc1610e..f60b69312e 100644 --- a/include/deal.II/base/mpi_consensus_algorithms.h +++ b/include/deal.II/base/mpi_consensus_algorithms.h @@ -484,13 +484,6 @@ namespace Utilities */ std::set requesting_processes; - /** - * The ith request message from another rank has been received: process - * the request and send an answer. - */ - void - answer_requests(int index); - /** * Start to send all requests via ISend and post IRecvs for the incoming * answer messages. @@ -498,6 +491,13 @@ namespace Utilities unsigned int start_communication(); + /** + * The ith request message from another rank has been received: process + * the request and send an answer. + */ + void + answer_requests(int index); + /** * After all answers have been exchanged, the MPI data structures can be * freed and the received answers can be processed. diff --git a/include/deal.II/base/mpi_consensus_algorithms.templates.h b/include/deal.II/base/mpi_consensus_algorithms.templates.h index 78f97ba518..ffdecedb09 100644 --- a/include/deal.II/base/mpi_consensus_algorithms.templates.h +++ b/include/deal.II/base/mpi_consensus_algorithms.templates.h @@ -422,67 +422,6 @@ namespace Utilities - template - void - PEX::answer_requests(int index) - { -#ifdef DEAL_II_WITH_MPI - const int tag_request = Utilities::MPI::internal::Tags:: - consensus_algorithm_pex_answer_request; - const int tag_deliver = Utilities::MPI::internal::Tags:: - consensus_algorithm_pex_process_deliver; - - MPI_Status status; - auto ierr = MPI_Probe(MPI_ANY_SOURCE, tag_request, this->comm, &status); - AssertThrowMPI(ierr); - - // get rank of incoming message - const auto other_rank = status.MPI_SOURCE; - - Assert(requesting_processes.find(other_rank) == - requesting_processes.end(), - ExcMessage("Process is requesting a second time!")); - requesting_processes.insert(other_rank); - - std::vector buffer_recv; - - // get size of incoming message - int number_amount; - ierr = MPI_Get_count(&status, MPI_BYTE, &number_amount); - AssertThrowMPI(ierr); - - // allocate memory for incoming message - Assert(number_amount % sizeof(T1) == 0, ExcInternalError()); - buffer_recv.resize(number_amount / sizeof(T1)); - ierr = MPI_Recv(buffer_recv.data(), - number_amount, - MPI_BYTE, - other_rank, - tag_request, - this->comm, - &status); - AssertThrowMPI(ierr); - - // process request - auto &request_buffer = requests_buffers[index]; - this->process.answer_request(other_rank, buffer_recv, request_buffer); - - // start to send answer back - ierr = MPI_Isend(request_buffer.data(), - request_buffer.size() * sizeof(T2), - MPI_BYTE, - other_rank, - tag_deliver, - this->comm, - &requests_answers[index]); - AssertThrowMPI(ierr); -#else - (void)index; -#endif - } - - - template unsigned int PEX::start_communication() @@ -552,6 +491,67 @@ namespace Utilities + template + void + PEX::answer_requests(int index) + { +#ifdef DEAL_II_WITH_MPI + const int tag_request = Utilities::MPI::internal::Tags:: + consensus_algorithm_pex_answer_request; + const int tag_deliver = Utilities::MPI::internal::Tags:: + consensus_algorithm_pex_process_deliver; + + MPI_Status status; + auto ierr = MPI_Probe(MPI_ANY_SOURCE, tag_request, this->comm, &status); + AssertThrowMPI(ierr); + + // get rank of incoming message + const auto other_rank = status.MPI_SOURCE; + + Assert(requesting_processes.find(other_rank) == + requesting_processes.end(), + ExcMessage("Process is requesting a second time!")); + requesting_processes.insert(other_rank); + + std::vector buffer_recv; + + // get size of incoming message + int number_amount; + ierr = MPI_Get_count(&status, MPI_BYTE, &number_amount); + AssertThrowMPI(ierr); + + // allocate memory for incoming message + Assert(number_amount % sizeof(T1) == 0, ExcInternalError()); + buffer_recv.resize(number_amount / sizeof(T1)); + ierr = MPI_Recv(buffer_recv.data(), + number_amount, + MPI_BYTE, + other_rank, + tag_request, + this->comm, + &status); + AssertThrowMPI(ierr); + + // process request + auto &request_buffer = requests_buffers[index]; + this->process.answer_request(other_rank, buffer_recv, request_buffer); + + // start to send answer back + ierr = MPI_Isend(request_buffer.data(), + request_buffer.size() * sizeof(T2), + MPI_BYTE, + other_rank, + tag_deliver, + this->comm, + &requests_answers[index]); + AssertThrowMPI(ierr); +#else + (void)index; +#endif + } + + + template void PEX::clean_up_and_end_communication() -- 2.39.5