From 98a42a76cf58fe114c183152b988b5db8a33f898 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 1 Jun 2022 18:04:24 -0600 Subject: [PATCH] Use free consensus algorithms functions instead of the class version. --- .../base/mpi_compute_index_owner_internal.h | 69 -------- .../base/mpi_compute_index_owner_internal.cc | 147 +++++++----------- 2 files changed, 54 insertions(+), 162 deletions(-) diff --git a/include/deal.II/base/mpi_compute_index_owner_internal.h b/include/deal.II/base/mpi_compute_index_owner_internal.h index 195b19e155..9d449c2ef8 100644 --- a/include/deal.II/base/mpi_compute_index_owner_internal.h +++ b/include/deal.II/base/mpi_compute_index_owner_internal.h @@ -70,75 +70,6 @@ namespace Utilities std::map data_map; }; - /** - * Specialization of ConsensusAlgorithms::Process for setting up the - * Dictionary even if there are ranges in the IndexSet space not owned - * by any processes. - * - * @note Only for internal usage. - */ - class DictionaryPayLoad - : public ConsensusAlgorithms::Process< - std::vector< - std::pair>, - std::vector> - { - public: - /** - * Constructor. - */ - DictionaryPayLoad( - const std::map>> - & buffers, - FlexibleIndexStorage &actually_owning_ranks, - const std::pair - & local_range, - std::vector &actually_owning_rank_list); - - /** - * Implementation of - * Utilities::MPI::ConsensusAlgorithms::Process::compute_targets(). - */ - virtual std::vector - compute_targets() override; - - /** - * Implementation of - * Utilities::MPI::ConsensusAlgorithms::Process::create_request(). - */ - virtual void - create_request(const unsigned int other_rank, - std::vector> - &send_buffer) override; - - /** - * Implementation of - * Utilities::MPI::ConsensusAlgorithms::Process::answer_request(). - */ - virtual void - answer_request( - const unsigned int other_rank, - const std::vector> &buffer_recv, - std::vector &request_buffer) override; - - private: - const std::map>> - &buffers; - - FlexibleIndexStorage &actually_owning_ranks; - - const std::pair - &local_range; - - std::vector &actually_owning_rank_list; - }; - /** diff --git a/source/base/mpi_compute_index_owner_internal.cc b/source/base/mpi_compute_index_owner_internal.cc index c70898afa8..8f1dd43b96 100644 --- a/source/base/mpi_compute_index_owner_internal.cc +++ b/source/base/mpi_compute_index_owner_internal.cc @@ -164,88 +164,6 @@ namespace Utilities - DictionaryPayLoad::DictionaryPayLoad( - const std::map>> - & buffers, - FlexibleIndexStorage &actually_owning_ranks, - const std::pair - & local_range, - std::vector &actually_owning_rank_list) - : buffers(buffers) - , actually_owning_ranks(actually_owning_ranks) - , local_range(local_range) - , actually_owning_rank_list(actually_owning_rank_list) - { - Assert(local_range.first <= local_range.second, ExcInternalError()); - } - - - - std::vector - DictionaryPayLoad::compute_targets() - { - std::vector targets; - for (const auto &rank_pair : buffers) - targets.push_back(rank_pair.first); - - return targets; - } - - - - void - DictionaryPayLoad::create_request( - const unsigned int other_rank, - std::vector> &send_buffer) - { - send_buffer = this->buffers.at(other_rank); - } - - - - void - DictionaryPayLoad::answer_request( - const unsigned int other_rank, - const std::vector> &buffer_recv, - std::vector & request_buffer) - { - (void)request_buffer; // not needed - - - // process message: loop over all intervals - for (auto interval : buffer_recv) - { -#ifdef DEBUG - for (types::global_dof_index i = interval.first; - i < interval.second; - i++) - Assert( - actually_owning_ranks.entry_has_been_set( - i - local_range.first) == false, - ExcMessage( - "Multiple processes seem to own the same global index. " - "A possible reason is that the sets of locally owned " - "indices are not distinct.")); - Assert(interval.first < interval.second, ExcInternalError()); - Assert( - local_range.first <= interval.first && - interval.second <= local_range.second, - ExcMessage( - "The specified interval is not handled by the current process.")); -#endif - actually_owning_ranks.fill(interval.first - local_range.first, - interval.second - local_range.first, - other_rank); - } - actually_owning_rank_list.push_back(other_rank); - } - - - void Dictionary::reinit(const IndexSet &owned_indices, const MPI_Comm &comm) { @@ -428,17 +346,60 @@ namespace Utilities // 3/4) use a ConsensusAlgorithm to send messages with local // dofs to the right dict process - DictionaryPayLoad temp(buffers, - actually_owning_ranks, - local_range, - actually_owning_rank_list); - - ConsensusAlgorithms::Selector< - std::vector< - std::pair>, - std::vector> - consensus_algo(temp, comm); - consensus_algo.run(); + + using RequestType = std::vector< + std::pair>; + + ConsensusAlgorithms::selector( + /* targets = */ + [&buffers]() { + std::vector targets; + for (const auto &rank_pair : buffers) + targets.push_back(rank_pair.first); + + return targets; + }(), + + /* create_request = */ + [&buffers](const unsigned int target_rank) -> RequestType { + return buffers.at(target_rank); + }, + + /* process_request = */ + [&](const unsigned int source_rank, + const RequestType &request) -> void { + // process message: loop over all intervals + for (auto interval : request) + { +# ifdef DEBUG + for (types::global_dof_index i = interval.first; + i < interval.second; + i++) + Assert( + actually_owning_ranks.entry_has_been_set( + i - local_range.first) == false, + ExcMessage( + "Multiple processes seem to own the same global index. " + "A possible reason is that the sets of locally owned " + "indices are not distinct.")); + Assert(interval.first < interval.second, + ExcInternalError()); + Assert( + local_range.first <= interval.first && + interval.second <= local_range.second, + ExcMessage( + "The specified interval is not handled by the current process.")); +# endif + actually_owning_ranks.fill(interval.first - + local_range.first, + interval.second - + local_range.first, + source_rank); + } + actually_owning_rank_list.push_back(source_rank); + }, + + comm); } std::sort(actually_owning_rank_list.begin(), -- 2.39.5