From 43877203fd0986aa1e9b41bc96ade596de96c0fb Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 12 Jan 2022 20:50:15 -0700 Subject: [PATCH] Marginally accelerate compute_point_to_point_communication_pattern(). --- source/base/mpi.cc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 0aa1cbe233..53ac3bbb43 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -407,15 +407,25 @@ namespace Utilities # if DEAL_II_MPI_VERSION_GTE(3, 0) // Have a little function that checks if destinations provided - // to the current process are unique: + // to the current process are unique. The way it does this is + // to create a sorted list of destinations and then walk through + // the list and look at successive elements -- if we find the + // same number twice, we know that the destinations were not + // unique const bool my_destinations_are_unique = [destinations]() { - std::vector my_destinations = destinations; - const unsigned int n_destinations = my_destinations.size(); - std::sort(my_destinations.begin(), my_destinations.end()); - my_destinations.erase(std::unique(my_destinations.begin(), - my_destinations.end()), - my_destinations.end()); - return (my_destinations.size() == n_destinations); + if (destinations.size() == 0) + return true; + else + { + std::vector my_destinations = destinations; + std::sort(my_destinations.begin(), my_destinations.end()); + + for (unsigned int i = 0; i < my_destinations.size() - 1; ++i) + if (my_destinations[i] == my_destinations[i + 1]) + return false; + + return true; + } }(); // If all processes report that they have unique destinations, -- 2.39.5