From 1b5830f44013d8e8bc26e533723a3c5f3d9ed921 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Sun, 10 Nov 2019 18:24:29 +0100 Subject: [PATCH] Rewrite compute_point_to_point_communication_pattern so that it uses ConsensusAlgorithm_NBX for MPI 3.0 --- source/base/mpi.cc | 148 ++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 76 deletions(-) diff --git a/source/base/mpi.cc b/source/base/mpi.cc index c5c84b3310..6c1388ed16 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -219,6 +219,66 @@ namespace Utilities + /** + * A re-implementation of compute_point_to_point_communication_pattern + * using the ConsensusAlgorithm. + */ + class ConsensusAlgorithmProcessTargets + : public ConsensusAlgorithmProcess + { + public: + ConsensusAlgorithmProcessTargets(const std::vector &target) + : target(target) + {} + + using T1 = int; + using T2 = int; + + virtual void + process_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, @@ -236,7 +296,16 @@ namespace Utilities "There is no point in communicating with ourselves.")); } -# if DEAL_II_MPI_VERSION_GTE(2, 2) +# if DEAL_II_MPI_VERSION_GTE(3, 0) + + ConsensusAlgorithmProcessTargets process(destinations); + ConsensusAlgorithm_NBX + consensus_algorithm(process, mpi_comm); + consensus_algorithm.run(); + return process.get_result(); + +# elif DEAL_II_MPI_VERSION_GTE(2, 2) static CollectiveMutex mutex; CollectiveMutex::ScopedLock lock(mutex, mpi_comm); @@ -1207,66 +1276,6 @@ namespace Utilities - /** - * A re-implementation of compute_point_to_point_communication_pattern - * using the ConsensusAlgorithm. - */ - class ConsensusAlgorithmProcessTargets - : public ConsensusAlgorithmProcess - { - public: - ConsensusAlgorithmProcessTargets(std::vector &target) - : target(target) - {} - - using T1 = int; - using T2 = int; - - virtual void - process_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; - }; - - - template ConsensusAlgorithm_PEX::ConsensusAlgorithm_PEX( ConsensusAlgorithmProcess &process, @@ -1356,21 +1365,8 @@ namespace Utilities targets = this->process.compute_targets(); // 2) determine who wants to communicate with this process - const bool use_nbx = false; - if (!use_nbx) - { - sources = - compute_point_to_point_communication_pattern(this->comm, targets); - } - else - { - ConsensusAlgorithmProcessTargets process(targets); - ConsensusAlgorithm_NBX - consensus_algorithm(process, this->comm); - consensus_algorithm.run(); - sources = process.get_result(); - } + sources = + compute_point_to_point_communication_pattern(this->comm, targets); const auto n_targets = targets.size(); const auto n_sources = sources.size(); -- 2.39.5