From 825099ab056ac15a0585462266f5d060ed62ddef Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Sun, 6 Jun 2021 17:11:20 +0200 Subject: [PATCH] Simplify compute_point_to_point_communication_pattern() and compute_n_point_to_point_communications() --- source/base/mpi.cc | 128 +++------------------------------------------ 1 file changed, 8 insertions(+), 120 deletions(-) diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 83567af5f9..7e928322c2 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -295,66 +295,6 @@ namespace Utilities - /** - * A re-implementation of compute_point_to_point_communication_pattern - * using a ConsensusAlgorithm. - */ - class ConsensusAlgorithmsProcessTargets - : public ConsensusAlgorithms::Process - { - public: - ConsensusAlgorithmsProcessTargets(const std::vector &target) - : target(target) - {} - - using T1 = unsigned int; - using T2 = unsigned int; - - virtual void - answer_request(const unsigned int other_rank, - const std::vector &, - std::vector &) override - { - this->sources.push_back(other_rank); - } - - /** - * Simply return the user-provided list. - * - * @return List of processes this process wants to send requests to. - */ - virtual std::vector - compute_targets() override - { - return target; - } - - /** - * The result of the consensus algorithm. - * @return Sorted list of ranks of processes wanting to send a request to - * this process. - */ - std::vector - get_result() - { - std::sort(sources.begin(), sources.end()); - return sources; - } - - private: - /** - * List of processes this process wants to send requests to. - */ - const std::vector ⌖ - - /** - * List of ranks of processes wanting to send a request to this process. - */ - std::vector sources; - }; - - - std::vector compute_point_to_point_communication_pattern( const MPI_Comm & mpi_comm, @@ -373,12 +313,11 @@ namespace Utilities # if DEAL_II_MPI_VERSION_GTE(3, 0) - ConsensusAlgorithmsProcessTargets process(destinations); - ConsensusAlgorithms::NBX - consensus_algorithm(process, mpi_comm); - consensus_algorithm.run(); - return process.get_result(); + ConsensusAlgorithms::AnonymousProcess process( + [&]() { return destinations; }); + ConsensusAlgorithms::NBX consensus_algorithm(process, + mpi_comm); + return consensus_algorithm.run(); # elif DEAL_II_MPI_VERSION_GTE(2, 2) @@ -498,60 +437,9 @@ namespace Utilities const MPI_Comm & mpi_comm, const std::vector &destinations) { - const unsigned int n_procs = Utilities::MPI::n_mpi_processes(mpi_comm); - - for (const unsigned int destination : destinations) - { - (void)destination; - AssertIndexRange(destination, n_procs); - Assert(destination != Utilities::MPI::this_mpi_process(mpi_comm), - ExcMessage( - "There is no point in communicating with ourselves.")); - } - - // Calculate the number of messages to send to each process - std::vector dest_vector(n_procs); - for (const auto &el : destinations) - ++dest_vector[el]; - -# if DEAL_II_MPI_VERSION_GTE(2, 2) - // Find out how many processes will send to this one - // MPI_Reduce_scatter(_block) does exactly this - unsigned int n_recv_from = 0; - - const int ierr = MPI_Reduce_scatter_block( - dest_vector.data(), &n_recv_from, 1, MPI_UNSIGNED, MPI_SUM, mpi_comm); - - AssertThrowMPI(ierr); - - return n_recv_from; -# else - // Find out how many processes will send to this one - // by reducing with sum and then scattering the - // results over all processes - std::vector buffer(dest_vector.size()); - unsigned int n_recv_from = 0; - - int ierr = MPI_Reduce(dest_vector.data(), - buffer.data(), - dest_vector.size(), - MPI_UNSIGNED, - MPI_SUM, - 0, - mpi_comm); - AssertThrowMPI(ierr); - ierr = MPI_Scatter(buffer.data(), - 1, - MPI_UNSIGNED, - &n_recv_from, - 1, - MPI_UNSIGNED, - 0, - mpi_comm); - AssertThrowMPI(ierr); - - return n_recv_from; -# endif + return compute_point_to_point_communication_pattern(mpi_comm, + destinations) + .size(); } -- 2.39.5