From 6d70688e1b102c7df3ab3651d328fe7467a6888d Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 7 Nov 2024 15:13:57 -0700 Subject: [PATCH] No longer base ConsensusAlgorithmsPayload on MPI::ConsensusAlgorithms::Process. --- source/base/mpi.cc | 84 +++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 4b5f710882..62628ed8b3 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -881,12 +881,12 @@ namespace Utilities * payload. */ class ConsensusAlgorithmsPayload - : public ConsensusAlgorithms::Process< - std::vector< - std::pair>, - std::vector> { public: + using RequestType = std::vector< + std::pair>; + using AnswerType = std::vector; + /** * Constructor. */ @@ -975,37 +975,37 @@ namespace Utilities * keeping track of who requested a particular index in case that * information is also desired). */ - virtual void + void answer_request( const unsigned int other_rank, const std::vector> &buffer_recv, - std::vector &request_buffer) override; + std::vector &request_buffer); /** * Implementation of * Utilities::MPI::ConsensusAlgorithms::Process::compute_targets(). */ - virtual std::vector - compute_targets() override; + std::vector + compute_targets(); /** * Implementation of * Utilities::MPI::ConsensusAlgorithms::Process::create_request(). */ - virtual void - create_request(const unsigned int other_rank, - std::vector> - &send_buffer) override; + void + create_request( + const unsigned int other_rank, + std::vector> &send_buffer); /** * Implementation of * Utilities::MPI::ConsensusAlgorithms::Process::read_answer(). */ - virtual void + void read_answer(const unsigned int other_rank, - const std::vector &recv_buffer) override; + const std::vector &recv_buffer); /** * Resolve the origin of the requests by sending the information @@ -1838,12 +1838,27 @@ namespace Utilities // Communicate with the process who owns the index in the static // partition (i.e. in the dictionary). This process returns the actual // owner of the index. - ConsensusAlgorithms::Selector< - std::vector< - std::pair>, - std::vector> - consensus_algorithm; - consensus_algorithm.run(process, comm); + using RequestType = + ComputeIndexOwner::ConsensusAlgorithmsPayload::RequestType; + using AnswerType = + ComputeIndexOwner::ConsensusAlgorithmsPayload::AnswerType; + ConsensusAlgorithms::selector( + process.compute_targets(), + [&process](const unsigned int other_rank) -> RequestType { + RequestType r; + process.create_request(other_rank, r); + return r; + }, + [&process](const unsigned int other_rank, + const RequestType &r) -> AnswerType { + AnswerType a; + process.answer_request(other_rank, r, a); + return a; + }, + [&process](const unsigned int other_rank, const AnswerType &a) -> void { + process.read_answer(other_rank, a); + }, + comm); return owning_ranks; } @@ -1876,12 +1891,27 @@ namespace Utilities // Communicate with the process who owns the index in the static // partition (i.e. in the dictionary). This process returns the actual // owner of the index. - ConsensusAlgorithms::Selector< - std::vector< - std::pair>, - std::vector> - consensus_algorithm; - consensus_algorithm.run(process, comm); + using RequestType = + ComputeIndexOwner::ConsensusAlgorithmsPayload::RequestType; + using AnswerType = + ComputeIndexOwner::ConsensusAlgorithmsPayload::AnswerType; + ConsensusAlgorithms::selector( + process.compute_targets(), + [&process](const unsigned int other_rank) -> RequestType { + RequestType r; + process.create_request(other_rank, r); + return r; + }, + [&process](const unsigned int other_rank, + const RequestType &r) -> AnswerType { + AnswerType a; + process.answer_request(other_rank, r, a); + return a; + }, + [&process](const unsigned int other_rank, const AnswerType &a) -> void { + process.read_answer(other_rank, a); + }, + comm); return {owning_ranks, process.get_requesters()}; } -- 2.39.5