From c7052067abd88db8ba55d8fa03032009341f449e Mon Sep 17 00:00:00 2001 From: bangerth Date: Sun, 4 Dec 2011 18:27:08 +0000 Subject: [PATCH] Implement Utilities::sum for vectors of objects. git-svn-id: https://svn.dealii.org/trunk@24786 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/utilities.h | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/deal.II/include/deal.II/base/utilities.h b/deal.II/include/deal.II/base/utilities.h index 3a3677197b..b20da3a0c9 100644 --- a/deal.II/include/deal.II/base/utilities.h +++ b/deal.II/include/deal.II/base/utilities.h @@ -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 + 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 @@ -1080,6 +1095,24 @@ namespace Utilities } + 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