From a90d9a06bc94a1d36118ab6c9d285ca943e02263 Mon Sep 17 00:00:00 2001 From: heister Date: Wed, 25 Jan 2012 20:56:29 +0000 Subject: [PATCH] undo accidental removal of MPI::sum() in r24924 git-svn-id: https://svn.dealii.org/trunk@24928 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/mpi.h | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/deal.II/include/deal.II/base/mpi.h b/deal.II/include/deal.II/base/mpi.h index fbb42e4d03..a7190af12b 100644 --- a/deal.II/include/deal.II/base/mpi.h +++ b/deal.II/include/deal.II/base/mpi.h @@ -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 + inline + void sum (const std::vector &values, + const MPI_Comm &mpi_communicator, + std::vector &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 + inline + void sum (const std::vector &values, + const MPI_Comm &mpi_communicator, + std::vector &sums) + { +#ifdef DEAL_II_COMPILER_SUPPORTS_MPI + sums.resize (values.size()); + MPI_Allreduce (const_cast(static_cast(&values[0])), + &sums[0], values.size(), internal::mpi_type_id((T*)0), MPI_SUM, + mpi_communicator); +#else + (void)mpi_communicator; + sums = values; +#endif + } + template inline T max (const T &t, -- 2.39.5