From: Wolfgang Bangerth Date: Thu, 13 Jan 2022 03:50:15 +0000 (-0700) Subject: Marginally accelerate compute_point_to_point_communication_pattern(). X-Git-Tag: v9.4.0-rc1~618^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43877203fd0986aa1e9b41bc96ade596de96c0fb;p=dealii.git Marginally accelerate compute_point_to_point_communication_pattern(). --- 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,