]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
undo accidental removal of MPI::sum() in r24924
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 25 Jan 2012 20:56:29 +0000 (20:56 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 25 Jan 2012 20:56:29 +0000 (20:56 +0000)
git-svn-id: https://svn.dealii.org/trunk@24928 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/mpi.h

index fbb42e4d030ff465c4c77e4f0a6e88309a0fee93..a7190af12b035fc5f1d65e5b3721914a6745fe97 100644 (file)
@@ -168,6 +168,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
@@ -377,7 +392,25 @@ namespace Utilities
 #endif
     }
 
+    
+    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.