From: Wolfgang Bangerth Date: Wed, 11 May 2022 16:02:47 +0000 (-0600) Subject: Rename the template type arguments of the consensus algorithms. X-Git-Tag: v9.4.0-rc1~229^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13720%2Fhead;p=dealii.git Rename the template type arguments of the consensus algorithms. --- diff --git a/include/deal.II/base/mpi_consensus_algorithms.h b/include/deal.II/base/mpi_consensus_algorithms.h index af6fcee110..d01ac63e97 100644 --- a/include/deal.II/base/mpi_consensus_algorithms.h +++ b/include/deal.II/base/mpi_consensus_algorithms.h @@ -117,8 +117,8 @@ namespace Utilities * considered as a request message by the receiving rank. * - receive message: The answer to a send/request message. * - * @tparam T1 The type of the elements of the vector to sent. - * @tparam T2 The type of the elements of the vector to received. + * @tparam RequestType The type of the elements of the vector to sent. + * @tparam AnswerType The type of the elements of the vector to received. * * @note Since the payloads of the messages are optional, users have * to deal with buffers themselves. The ConsensusAlgorithm classes @@ -126,7 +126,7 @@ namespace Utilities * to be sent can be inserted to or read from, and (2) communicate * these vectors blindly. */ - template + template class Process { public: @@ -155,8 +155,8 @@ namespace Utilities * @note The buffer is empty. Before using it, you have to set its size. */ virtual void - create_request(const unsigned int other_rank, - std::vector & send_buffer); + create_request(const unsigned int other_rank, + std::vector &send_buffer); /** * Prepare the buffer where the payload of the answer of the request to @@ -171,9 +171,9 @@ namespace Utilities * its size. */ virtual void - answer_request(const unsigned int other_rank, - const std::vector &buffer_recv, - std::vector & request_buffer); + answer_request(const unsigned int other_rank, + const std::vector &buffer_recv, + std::vector & request_buffer); /** * Process the payload of the answer of the request to the process with @@ -183,8 +183,8 @@ namespace Utilities * @param[in] recv_buffer data to be sent part of the request (optional) */ virtual void - read_answer(const unsigned int other_rank, - const std::vector &recv_buffer); + read_answer(const unsigned int other_rank, + const std::vector &recv_buffer); }; @@ -199,10 +199,10 @@ namespace Utilities * to actually compute such communication patterns and perform the * communication. * - * @tparam T1 The type of the elements of the vector to be sent. - * @tparam T2 The type of the elements of the vector to be received. + * @tparam RequestType The type of the elements of the vector to be sent. + * @tparam AnswerType The type of the elements of the vector to be received. */ - template + template class Interface { public: @@ -224,7 +224,8 @@ namespace Utilities * function that takes an argument. */ DEAL_II_DEPRECATED - Interface(Process &process, const MPI_Comm &comm); + Interface(Process &process, + const MPI_Comm & comm); /** * Destructor. Made `virtual` to ensure that one can work with @@ -254,7 +255,7 @@ namespace Utilities * that takes a number of `std::function` arguments. */ std::vector - run(Process &process, const MPI_Comm &comm); + run(Process &process, const MPI_Comm &comm); /** * Run the consensus algorithm and return a vector of process ranks @@ -281,14 +282,15 @@ namespace Utilities */ virtual std::vector run(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - & answer_request, + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, const std::function &)> &process_answer, - const MPI_Comm & comm) = 0; + const std::vector &)> + & process_answer, + const MPI_Comm &comm) = 0; private: /** @@ -299,7 +301,7 @@ namespace Utilities * otherwise */ DEAL_II_DEPRECATED - Process *process; + Process *process; /** * MPI communicator. @@ -322,11 +324,11 @@ namespace Utilities * @note This class closely follows @cite hoefler2010scalable, but our * implementation also deals with payloads. * - * @tparam T1 The type of the elements of the vector to be sent. - * @tparam T2 The type of the elements of the vector to be received. + * @tparam RequestType The type of the elements of the vector to be sent. + * @tparam AnswerType The type of the elements of the vector to be received. */ - template - class NBX : public Interface + template + class NBX : public Interface { public: /** @@ -347,7 +349,7 @@ namespace Utilities * function that takes an argument. */ DEAL_II_DEPRECATED - NBX(Process &process, const MPI_Comm &comm); + NBX(Process &process, const MPI_Comm &comm); /** * Destructor. @@ -355,28 +357,29 @@ namespace Utilities virtual ~NBX() = default; // Import the declarations from the base class. - using Interface::run; + using Interface::run; /** * @copydoc Interface::run() */ virtual std::vector run(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - & answer_request, + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, const std::function &)> &process_answer, - const MPI_Comm & comm) override; + const std::vector &)> + & process_answer, + const MPI_Comm &comm) override; private: #ifdef DEAL_II_WITH_MPI /** * Buffers for sending requests. */ - std::vector> send_buffers; + std::vector> send_buffers; /** * Requests for sending requests. @@ -390,7 +393,7 @@ namespace Utilities * resized and consequently its elements (the pointers) are moved * around. */ - std::vector>> request_buffers; + std::vector>> request_buffers; /** * Requests for sending answers to requests. @@ -418,7 +421,8 @@ namespace Utilities */ bool all_locally_originated_receives_are_completed( - const std::function &)> + const std::function &)> & process_answer, const MPI_Comm &comm); @@ -444,10 +448,10 @@ namespace Utilities */ void maybe_answer_one_request( - const std::function(const unsigned int, - const std::vector &)> - & answer_request, - const MPI_Comm &comm); + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const MPI_Comm & comm); /** * Start to send all requests via ISend and post IRecvs for the incoming @@ -456,7 +460,7 @@ namespace Utilities void start_communication( const std::vector &targets, - const std::function(const unsigned int)> + const std::function(const unsigned int)> & create_request, const MPI_Comm &comm); @@ -480,18 +484,19 @@ namespace Utilities * @note This class closely follows @cite hoefler2010scalable, but our * implementation also deals with payloads. * - * @tparam T1 The type of the elements of the vector to be sent. - * @tparam T2 The type of the elements of the vector to be received. + * @tparam RequestType The type of the elements of the vector to be sent. + * @tparam AnswerType The type of the elements of the vector to be received. */ - template + template std::vector nbx(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm); @@ -518,11 +523,11 @@ namespace Utilities * in the ConsensusAlgorithms::NBX class (a sister class to the * current one). * - * @tparam T1 The type of the elements of the vector to be sent. - * @tparam T2 The type of the elements of the vector to be received. + * @tparam RequestType The type of the elements of the vector to be sent. + * @tparam AnswerType The type of the elements of the vector to be received. */ - template - class PEX : public Interface + template + class PEX : public Interface { public: /** @@ -544,7 +549,7 @@ namespace Utilities * function that takes an argument. */ DEAL_II_DEPRECATED - PEX(Process &process, const MPI_Comm &comm); + PEX(Process &process, const MPI_Comm &comm); /** * Destructor. @@ -552,33 +557,34 @@ namespace Utilities virtual ~PEX() = default; // Import the declarations from the base class. - using Interface::run; + using Interface::run; /** * @copydoc Interface::run() */ virtual std::vector run(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - & answer_request, + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, const std::function &)> &process_answer, - const MPI_Comm & comm) override; + const std::vector &)> + & process_answer, + const MPI_Comm &comm) override; private: #ifdef DEAL_II_WITH_MPI /** * Buffers for sending requests. */ - std::vector> send_buffers; + std::vector> send_buffers; /** * Buffers for receiving answers to requests. */ - std::vector> recv_buffers; + std::vector> recv_buffers; /** * MPI request objects for sending request messages. @@ -588,7 +594,7 @@ namespace Utilities /** * Buffers for sending answers to requests. */ - std::vector> requests_buffers; + std::vector> requests_buffers; /** * Requests for sending answers to requests. @@ -607,7 +613,7 @@ namespace Utilities unsigned int start_communication( const std::vector &targets, - const std::function(const unsigned int)> + const std::function(const unsigned int)> & create_request, const MPI_Comm &comm); @@ -616,12 +622,11 @@ namespace Utilities * process the request and send an answer. */ void - answer_one_request( - const unsigned int index, - const std::function(const unsigned int, - const std::vector &)> - & answer_request, - const MPI_Comm &comm); + answer_one_request(const unsigned int index, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const MPI_Comm & comm); /** * Receive and process all of the incoming responses to the @@ -630,7 +635,8 @@ namespace Utilities void process_incoming_answers( const unsigned int n_targets, - const std::function &)> + const std::function &)> & process_answer, const MPI_Comm &comm); @@ -667,18 +673,19 @@ namespace Utilities * in the ConsensusAlgorithms::NBX class (a sister class to the * current one). * - * @tparam T1 The type of the elements of the vector to be sent. - * @tparam T2 The type of the elements of the vector to be received. + * @tparam RequestType The type of the elements of the vector to be sent. + * @tparam AnswerType The type of the elements of the vector to be received. */ - template + template std::vector pex(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm); @@ -687,8 +694,8 @@ namespace Utilities * A serial fall back for the above classes to allow programming * independently of whether MPI is used or not. */ - template - class Serial : public Interface + template + class Serial : public Interface { public: /** @@ -709,24 +716,25 @@ namespace Utilities * function that takes an argument. */ DEAL_II_DEPRECATED - Serial(Process &process, const MPI_Comm &comm); + Serial(Process &process, const MPI_Comm &comm); // Import the declarations from the base class. - using Interface::run; + using Interface::run; /** * @copydoc Interface::run() */ virtual std::vector run(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - & answer_request, + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, const std::function &)> &process_answer, - const MPI_Comm & comm) override; + const std::vector &)> + & process_answer, + const MPI_Comm &comm) override; }; @@ -738,18 +746,19 @@ namespace Utilities * where the communicator provided has only one rank (or when * MPI is simply not used at all). * - * @tparam T1 The type of the elements of the vector to be sent. - * @tparam T2 The type of the elements of the vector to be received. + * @tparam RequestType The type of the elements of the vector to be sent. + * @tparam AnswerType The type of the elements of the vector to be received. */ - template + template std::vector pex(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm); @@ -764,11 +773,11 @@ namespace Utilities * goal is to always use the most efficient algorithm for however many * processes participate in the communication. * - * @tparam T1 The type of the elements of the vector to be sent. - * @tparam T2 The type of the elements of the vector to be received. + * @tparam RequestType The type of the elements of the vector to be sent. + * @tparam AnswerType The type of the elements of the vector to be received. */ - template - class Selector : public Interface + template + class Selector : public Interface { public: /** @@ -789,7 +798,8 @@ namespace Utilities * function that takes an argument. */ DEAL_II_DEPRECATED - Selector(Process &process, const MPI_Comm &comm); + Selector(Process &process, + const MPI_Comm & comm); /** * Destructor. @@ -797,7 +807,7 @@ namespace Utilities virtual ~Selector() = default; // Import the declarations from the base class. - using Interface::run; + using Interface::run; /** * @copydoc Interface::run() @@ -806,18 +816,19 @@ namespace Utilities */ virtual std::vector run(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - & answer_request, + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, const std::function &)> &process_answer, - const MPI_Comm & comm) override; + const std::vector &)> + & process_answer, + const MPI_Comm &comm) override; private: // Pointer to the actual ConsensusAlgorithms::Interface implementation. - std::shared_ptr> consensus_algo; + std::shared_ptr> consensus_algo; }; @@ -833,21 +844,21 @@ namespace Utilities * goal is to always use the most efficient algorithm for however many * processes participate in the communication. * - * @tparam T1 The type of the elements of the vector to be sent. - * @tparam T2 The type of the elements of the vector to be received. + * @tparam RequestType The type of the elements of the vector to be sent. + * @tparam AnswerType The type of the elements of the vector to be received. */ - template + template std::vector - selector( - const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> - & process_answer, - const MPI_Comm &comm); + selector(const std::vector &targets, + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> + & process_answer, + const MPI_Comm &comm); @@ -857,8 +868,8 @@ namespace Utilities * The advantage of this class is that users do not have to write their * own implementation but can register lambda functions directly. */ - template - class AnonymousProcess : public Process + template + class AnonymousProcess : public Process { public: /** @@ -873,13 +884,15 @@ namespace Utilities AnonymousProcess( const std::function()> &function_compute_targets, - const std::function &)> + const std::function &)> &function_create_request = {}, const std::function &, - std::vector &)> + const std::vector &, + std::vector &)> &function_answer_request = {}, - const std::function &)> + const std::function &)> &function_read_answer = {}); /** @@ -892,33 +905,34 @@ namespace Utilities * @copydoc Process::create_request() */ void - create_request(const unsigned int other_rank, - std::vector & send_buffer) override; + create_request(const unsigned int other_rank, + std::vector &send_buffer) override; /** * @copydoc Process::answer_request() */ void - answer_request(const unsigned int other_rank, - const std::vector &buffer_recv, - std::vector & request_buffer) override; + answer_request(const unsigned int other_rank, + const std::vector &buffer_recv, + std::vector & request_buffer) override; /** * @copydoc Process::read_answer() */ void - read_answer(const unsigned int other_rank, - const std::vector &recv_buffer) override; + read_answer(const unsigned int other_rank, + const std::vector &recv_buffer) override; private: const std::function()> function_compute_targets; - const std::function &)> + const std::function &)> function_create_request; - const std::function< - void(const unsigned int, const std::vector &, std::vector &)> + const std::function &, + std::vector &)> function_answer_request; - const std::function &)> + const std::function &)> function_read_answer; }; @@ -926,89 +940,95 @@ namespace Utilities #ifndef DOXYGEN // Implementation of the functions in this namespace. - template + template std::vector nbx(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm) { - return NBX().run( + return NBX().run( targets, create_request, answer_request, process_answer, comm); } - template + template std::vector pex(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm) { - return PEX().run( + return PEX().run( targets, create_request, answer_request, process_answer, comm); } - template + template std::vector serial(const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - & answer_request, + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, const std::function &)> &process_answer, - const MPI_Comm & comm) + const std::vector &)> + & process_answer, + const MPI_Comm &comm) { - return Serial().run( + return Serial().run( targets, create_request, answer_request, process_answer, comm); } - template + template std::vector - selector( - const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> - & process_answer, - const MPI_Comm &comm) + selector(const std::vector &targets, + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> + & process_answer, + const MPI_Comm &comm) { - return Selector().run( + return Selector().run( targets, create_request, answer_request, process_answer, comm); } - template - AnonymousProcess::AnonymousProcess( + template + AnonymousProcess::AnonymousProcess( const std::function()> &function_compute_targets, - const std::function &)> - & function_create_request, const std::function &, - std::vector &)> &function_answer_request, - const std::function &)> + std::vector &)> + &function_create_request, + const std::function &, + std::vector &)> + &function_answer_request, + const std::function &)> &function_read_answer) : function_compute_targets(function_compute_targets) , function_create_request(function_create_request) @@ -1018,19 +1038,20 @@ namespace Utilities - template + template std::vector - AnonymousProcess::compute_targets() + AnonymousProcess::compute_targets() { return function_compute_targets(); } - template + template void - AnonymousProcess::create_request(const unsigned int other_rank, - std::vector & send_buffer) + AnonymousProcess::create_request( + const unsigned int other_rank, + std::vector &send_buffer) { if (function_create_request) function_create_request(other_rank, send_buffer); @@ -1038,12 +1059,12 @@ namespace Utilities - template + template void - AnonymousProcess::answer_request( - const unsigned int other_rank, - const std::vector &buffer_recv, - std::vector & request_buffer) + AnonymousProcess::answer_request( + const unsigned int other_rank, + const std::vector &buffer_recv, + std::vector & request_buffer) { if (function_answer_request) function_answer_request(other_rank, buffer_recv, request_buffer); @@ -1051,10 +1072,11 @@ namespace Utilities - template + template void - AnonymousProcess::read_answer(const unsigned int other_rank, - const std::vector &recv_buffer) + AnonymousProcess::read_answer( + const unsigned int other_rank, + const std::vector &recv_buffer) { if (function_read_answer) function_read_answer(other_rank, recv_buffer); diff --git a/include/deal.II/base/mpi_consensus_algorithms.templates.h b/include/deal.II/base/mpi_consensus_algorithms.templates.h index acd4e44d4a..1ebfa7d8a6 100644 --- a/include/deal.II/base/mpi_consensus_algorithms.templates.h +++ b/include/deal.II/base/mpi_consensus_algorithms.templates.h @@ -72,55 +72,61 @@ namespace Utilities - template + template void - Process::answer_request(const unsigned int, - const std::vector &, - std::vector &) + Process::answer_request( + const unsigned int, + const std::vector &, + std::vector &) { // nothing to do } - template + template void - Process::create_request(const unsigned int, std::vector &) + Process::create_request( + const unsigned int, + std::vector &) { // nothing to do } - template + template void - Process::read_answer(const unsigned int, const std::vector &) + Process::read_answer( + const unsigned int, + const std::vector &) { // nothing to do } - template - Interface::Interface(Process &process, - const MPI_Comm & comm) + template + Interface::Interface( + Process &process, + const MPI_Comm & comm) : process(&process) , comm(comm) {} - template - Interface::Interface() + template + Interface::Interface() : process(nullptr) , comm(MPI_COMM_NULL) {} - template + template std::vector - Interface::run() + Interface::run() { Assert(process != nullptr, ExcMessage("This function can only be called if the " @@ -132,9 +138,11 @@ namespace Utilities - template + template std::vector - Interface::run(Process &process, const MPI_Comm &comm) + Interface::run( + Process &process, + const MPI_Comm & comm) { // Unpack the 'process' object and call the function that takes // function objects for all operations. @@ -142,19 +150,20 @@ namespace Utilities process.compute_targets(), /* create_request: */ [&process](const unsigned int target) { - std::vector request; + std::vector request; process.create_request(target, request); return request; }, /* answer_request: */ - [&process](const unsigned int source, - const std::vector &request) { - std::vector answer; + [&process](const unsigned int source, + const std::vector &request) { + std::vector answer; process.answer_request(source, request, answer); return answer; }, /* process_answer: */ - [&process](const unsigned int target, const std::vector &answer) { + [&process](const unsigned int target, + const std::vector &answer) { process.read_answer(target, answer); }, comm); @@ -162,23 +171,26 @@ namespace Utilities - template - NBX::NBX(Process &process, const MPI_Comm &comm) - : Interface(process, comm) + template + NBX::NBX( + Process &process, + const MPI_Comm & comm) + : Interface(process, comm) {} - template + template std::vector - NBX::run( + NBX::run( const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm) { @@ -231,11 +243,11 @@ namespace Utilities - template + template void - NBX::start_communication( + NBX::start_communication( const std::vector &targets, - const std::function(const unsigned int)> + const std::function(const unsigned int)> & create_request, const MPI_Comm &comm) { @@ -258,12 +270,12 @@ namespace Utilities AssertIndexRange(rank, Utilities::MPI::n_mpi_processes(comm)); auto &send_buffer = send_buffers[index]; - send_buffer = - (create_request ? create_request(rank) : std::vector()); + send_buffer = (create_request ? create_request(rank) : + std::vector()); // Post a request to send data auto ierr = MPI_Isend(send_buffer.data(), - send_buffer.size() * sizeof(T1), + send_buffer.size() * sizeof(RequestType), MPI_BYTE, rank, tag_request, @@ -285,12 +297,14 @@ namespace Utilities - template + template bool - NBX::all_locally_originated_receives_are_completed( - const std::function &)> - & process_answer, - const MPI_Comm &comm) + NBX:: + all_locally_originated_receives_are_completed( + const std::function &)> + & process_answer, + const MPI_Comm &comm) { #ifdef DEAL_II_WITH_MPI // We know that all requests have come in when we have pending @@ -333,20 +347,23 @@ namespace Utilities MPI_Get_count(&status, MPI_BYTE, &message_size); AssertThrowMPI(ierr); } - Assert(message_size % sizeof(T2) == 0, ExcInternalError()); - std::vector recv_buffer(message_size / sizeof(T2)); + Assert(message_size % sizeof(AnswerType) == 0, + ExcInternalError()); + std::vector recv_buffer(message_size / + sizeof(AnswerType)); { 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, - target, - tag_deliver, - comm, - MPI_STATUS_IGNORE); + const int ierr = + MPI_Recv(recv_buffer.data(), + recv_buffer.size() * sizeof(AnswerType), + MPI_BYTE, + target, + tag_deliver, + comm, + MPI_STATUS_IGNORE); AssertThrowMPI(ierr); } @@ -379,13 +396,13 @@ namespace Utilities - template + template void - NBX::maybe_answer_one_request( - const std::function(const unsigned int, - const std::vector &)> - & answer_request, - const MPI_Comm &comm) + NBX::maybe_answer_one_request( + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const MPI_Comm & comm) { #ifdef DEAL_II_WITH_MPI @@ -424,8 +441,10 @@ namespace Utilities AssertThrowMPI(ierr); // allocate memory for incoming message - Assert(number_amount % sizeof(T1) == 0, ExcInternalError()); - std::vector buffer_recv(number_amount / sizeof(T1)); + Assert(number_amount % sizeof(RequestType) == 0, + ExcInternalError()); + std::vector buffer_recv(number_amount / + sizeof(RequestType)); ierr = MPI_Recv(buffer_recv.data(), number_amount, MPI_BYTE, @@ -437,7 +456,8 @@ namespace Utilities // Allocate memory for an answer message to the current request, // and ask the 'process' object to produce an answer: - request_buffers.emplace_back(std::make_unique>()); + request_buffers.emplace_back( + std::make_unique>()); auto &request_buffer = *request_buffers.back(); if (answer_request) request_buffer = answer_request(other_rank, buffer_recv); @@ -445,7 +465,7 @@ namespace Utilities // Then initiate sending the answer back to the requester. request_requests.emplace_back(std::make_unique()); ierr = MPI_Isend(request_buffer.data(), - request_buffer.size() * sizeof(T2), + request_buffer.size() * sizeof(AnswerType), MPI_BYTE, other_rank, tag_deliver, @@ -461,9 +481,9 @@ namespace Utilities - template + template void - NBX::signal_finish(const MPI_Comm &comm) + NBX::signal_finish(const MPI_Comm &comm) { #ifdef DEAL_II_WITH_MPI const auto ierr = MPI_Ibarrier(comm, &barrier_request); @@ -475,9 +495,10 @@ namespace Utilities - template + template bool - NBX::all_remotely_originated_receives_are_completed() + NBX::all_remotely_originated_receives_are_completed() { #ifdef DEAL_II_WITH_MPI int all_ranks_reached_barrier; @@ -493,9 +514,10 @@ namespace Utilities - template + template void - NBX::clean_up_and_end_communication(const MPI_Comm &comm) + NBX::clean_up_and_end_communication( + const MPI_Comm &comm) { (void)comm; #ifdef DEAL_II_WITH_MPI @@ -530,23 +552,26 @@ namespace Utilities - template - PEX::PEX(Process &process, const MPI_Comm &comm) - : Interface(process, comm) + template + PEX::PEX( + Process &process, + const MPI_Comm & comm) + : Interface(process, comm) {} - template + template std::vector - PEX::run( + PEX::run( const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm) { @@ -580,11 +605,11 @@ namespace Utilities - template + template unsigned int - PEX::start_communication( + PEX::start_communication( const std::vector &targets, - const std::function(const unsigned int)> + const std::function(const unsigned int)> & create_request, const MPI_Comm &comm) { @@ -616,12 +641,12 @@ namespace Utilities // pack data which should be sent auto &send_buffer = send_buffers[i]; - send_buffer = - (create_request ? create_request(rank) : std::vector()); + send_buffer = (create_request ? create_request(rank) : + std::vector()); // start to send data auto ierr = MPI_Isend(send_buffer.data(), - send_buffer.size() * sizeof(T1), + send_buffer.size() * sizeof(RequestType), MPI_BYTE, rank, tag_request, @@ -641,14 +666,14 @@ namespace Utilities - template + template void - PEX::answer_one_request( - const unsigned int index, - const std::function(const unsigned int, - const std::vector &)> - & answer_request, - const MPI_Comm &comm) + PEX::answer_one_request( + const unsigned int index, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const MPI_Comm & comm) { #ifdef DEAL_II_WITH_MPI const int tag_request = Utilities::MPI::internal::Tags:: @@ -673,15 +698,15 @@ namespace Utilities "received. This algorithm does not expect this to happen.")); requesting_processes.insert(other_rank); - std::vector buffer_recv; + std::vector buffer_recv; // Actually get the incoming message: int number_amount; ierr = MPI_Get_count(&status, MPI_BYTE, &number_amount); AssertThrowMPI(ierr); - Assert(number_amount % sizeof(T1) == 0, ExcInternalError()); + Assert(number_amount % sizeof(RequestType) == 0, ExcInternalError()); - buffer_recv.resize(number_amount / sizeof(T1)); + buffer_recv.resize(number_amount / sizeof(RequestType)); ierr = MPI_Recv(buffer_recv.data(), number_amount, MPI_BYTE, @@ -696,10 +721,10 @@ namespace Utilities auto &request_buffer = requests_buffers[index]; request_buffer = (answer_request ? answer_request(other_rank, buffer_recv) : - std::vector()); + std::vector()); ierr = MPI_Isend(request_buffer.data(), - request_buffer.size() * sizeof(T2), + request_buffer.size() * sizeof(AnswerType), MPI_BYTE, other_rank, tag_deliver, @@ -715,11 +740,12 @@ namespace Utilities - template + template void - PEX::process_incoming_answers( + PEX::process_incoming_answers( const unsigned int n_targets, - const std::function &)> + const std::function &)> & process_answer, const MPI_Comm &comm) { @@ -747,15 +773,16 @@ namespace Utilities const int ierr = MPI_Get_count(&status, MPI_BYTE, &message_size); AssertThrowMPI(ierr); } - Assert(message_size % sizeof(T2) == 0, ExcInternalError()); - std::vector recv_buffer(message_size / sizeof(T2)); + Assert(message_size % sizeof(AnswerType) == 0, ExcInternalError()); + std::vector recv_buffer(message_size / + sizeof(AnswerType)); // Now actually receive the answer. Because the MPI_Probe // above blocks until we have a message, we know that the // following MPI_Recv call will immediately succeed. { const int ierr = MPI_Recv(recv_buffer.data(), - recv_buffer.size() * sizeof(T2), + recv_buffer.size() * sizeof(AnswerType), MPI_BYTE, other_rank, tag_deliver, @@ -776,9 +803,9 @@ namespace Utilities - template + template void - PEX::clean_up_and_end_communication() + PEX::clean_up_and_end_communication() { #ifdef DEAL_II_WITH_MPI // Finalize all MPI_Request objects for both the @@ -804,23 +831,26 @@ namespace Utilities - template - Serial::Serial(Process &process, const MPI_Comm &comm) - : Interface(process, comm) + template + Serial::Serial( + Process &process, + const MPI_Comm & comm) + : Interface(process, comm) {} - template + template std::vector - Serial::run( + Serial::run( const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm) { @@ -844,10 +874,11 @@ namespace Utilities // Since the caller indicates that there is a target, and since we // know that it is the current process, let the process send // something to itself. - const std::vector request = - (create_request ? create_request(0) : std::vector()); - const std::vector answer = - (answer_request ? answer_request(0, request) : std::vector()); + const std::vector request = + (create_request ? create_request(0) : std::vector()); + const std::vector answer = + (answer_request ? answer_request(0, request) : + std::vector()); if (process_answer) process_answer(0, answer); @@ -858,23 +889,26 @@ namespace Utilities - template - Selector::Selector(Process &process, const MPI_Comm &comm) - : Interface(process, comm) + template + Selector::Selector( + Process &process, + const MPI_Comm & comm) + : Interface(process, comm) {} - template + template std::vector - Selector::run( + Selector::run( const std::vector &targets, - const std::function(const unsigned int)> - &create_request, - const std::function(const unsigned int, - const std::vector &)> - &answer_request, - const std::function &)> + const std::function(const unsigned int)> + & create_request, + const std::function( + const unsigned int, + const std::vector &)> &answer_request, + const std::function &)> & process_answer, const MPI_Comm &comm) { @@ -893,13 +927,13 @@ namespace Utilities # else if (n_procs > 99) # endif - consensus_algo.reset(new NBX()); + consensus_algo.reset(new NBX()); else #endif if (n_procs > 1) - consensus_algo.reset(new PEX()); + consensus_algo.reset(new PEX()); else - consensus_algo.reset(new Serial()); + consensus_algo.reset(new Serial()); return consensus_algo->run( targets, create_request, answer_request, process_answer, comm);