]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Implement Utilities::sum for vectors of objects.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 4 Dec 2011 18:27:08 +0000 (18:27 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 4 Dec 2011 18:27:08 +0000 (18:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@24786 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/utilities.h

index 3a3677197bba06a5784e454018a69c906a4ed64f..b20da3a0c9efeb0c59605be666f739f604943110 100644 (file)
@@ -399,6 +399,21 @@ namespace Utilities
              const MPI_Comm &mpi_communicator,
              T (&sums)[N]);
 
+                                     /**
+                                      * Like the previous function,
+                                      * but take the sums over the
+                                      * elements of a std::vector. In other words,
+                                      * the i-th element of the
+                                      * results array is the sum over
+                                      * the i-th entries of the input
+                                      * arrays from each processor.
+                                      */
+    template <typename T>
+    inline
+    void sum (const std::vector<T> &values,
+              const MPI_Comm &mpi_communicator,
+              std::vector<T> &sums);
+    
     /**
      * Return the maximum over all processors of the value @p t. This function
      * is collective over all processors given in the communicator. If
@@ -1080,6 +1095,24 @@ namespace Utilities
     }
 
 
+    template <typename T>
+    inline
+    void sum (const std::vector<T> &values,
+              const MPI_Comm       &mpi_communicator,
+              std::vector<T>       &sums)
+    {
+#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
+      sums.resize (values.size());
+      MPI_Allreduce (const_cast<void*>(static_cast<const void*>(&values[0])),
+                     &sums[0], values.size(), internal::mpi_type_id((T*)0), MPI_SUM,
+                     mpi_communicator);
+#else
+      (void)mpi_communicator;
+      sums = values;
+#endif
+    }
+
+
     template <typename T>
     inline
     T max (const T &t,

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.