]> https://gitweb.dealii.org/ - dealii.git/commitdiff
MPI allreduce: Do not invoke MPI function for MPI_COMM_SELF 17545/head
authorMartin Kronbichler <martin.kronbichler@rub.de>
Fri, 16 Aug 2024 09:18:50 +0000 (11:18 +0200)
committerMartin Kronbichler <martin.kronbichler@rub.de>
Fri, 16 Aug 2024 09:18:50 +0000 (11:18 +0200)
include/deal.II/base/mpi.templates.h

index 68ba42078bf91e7c009446052fa94620e989be26..8cc731768bdd3090ca8d3567b4e0d894967d8238 100644 (file)
@@ -142,12 +142,17 @@ namespace Utilities
     T
     sum(const T &t, const MPI_Comm mpi_communicator)
     {
-      T return_value{};
-      internal::all_reduce(MPI_SUM,
-                           ArrayView<const T>(&t, 1),
-                           mpi_communicator,
-                           ArrayView<T>(&return_value, 1));
-      return return_value;
+      if (mpi_communicator == MPI_COMM_SELF)
+        return t;
+      else
+        {
+          T return_value{};
+          internal::all_reduce(MPI_SUM,
+                               ArrayView<const T>(&t, 1),
+                               mpi_communicator,
+                               ArrayView<T>(&return_value, 1));
+          return return_value;
+        }
     }
 
 
@@ -174,7 +179,11 @@ namespace Utilities
         const MPI_Comm            mpi_communicator,
         const ArrayView<T>       &sums)
     {
-      internal::all_reduce(MPI_SUM, values, mpi_communicator, sums);
+      if (mpi_communicator == MPI_COMM_SELF)
+        for (unsigned int i = 0; i < values.size(); ++i)
+          sums[i] = values[i];
+      else
+        internal::all_reduce(MPI_SUM, values, mpi_communicator, sums);
     }
 
 

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.