]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Marginally accelerate compute_point_to_point_communication_pattern().
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 13 Jan 2022 03:50:15 +0000 (20:50 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 13 Jan 2022 03:50:15 +0000 (20:50 -0700)
source/base/mpi.cc

index 0aa1cbe233b122f2e656cff099a2227f6950f6b7..53ac3bbb431223ba2410bda8ea3d616b25a78be8 100644 (file)
@@ -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<unsigned int> 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<unsigned int> 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,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.