From 08c9101ee9b0977b930517f4fb15c7e34262e975 Mon Sep 17 00:00:00 2001 From: bangerth Date: Mon, 26 Sep 2011 12:02:41 +0000 Subject: [PATCH] Implement the new function in namespace Utilities::MPI instead. Give it a simpler name. git-svn-id: https://svn.dealii.org/trunk@24416 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 2 +- deal.II/include/deal.II/base/utilities.h | 51 ++++++++++++++---------- tests/mpi/collective_02.cc | 16 ++++---- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 4d059b040f..9abc392900 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -297,7 +297,7 @@ and DoF handlers embedded in higher dimensional space have been added.

Specific improvements

    -
  1. New: The function Utilities::System::calculate_collective_mpi_sum +
  2. New: The function Utilities::MPI::sum function can be used to compute the sum of values over a number of MPI processes without having to deal with the underlying MPI functions.
    diff --git a/deal.II/include/deal.II/base/utilities.h b/deal.II/include/deal.II/base/utilities.h index e3f08d2ffc..d268d61942 100644 --- a/deal.II/include/deal.II/base/utilities.h +++ b/deal.II/include/deal.II/base/utilities.h @@ -274,6 +274,34 @@ namespace Utilities std::vector invert_permutation (const std::vector &permutation); + /** + * A namespace for utility functions that + * abstract certain operations using the + * Message Passing Interface (MPI) or + * provide fallback operations in + * case deal.II is configured not to use + * MPI at all. + * + * @ingroup utilities + */ + namespace MPI + { + /** + * Return the sum over all processors of the value @p t. This function + * is collective over all processors given in the communicator. If + * deal.II is not configured for use of MPI, this function simply + * returns the value of @p t. This function corresponds to the + * MPI_Allreduce function, i.e. all processors receive + * the result of this operation. + * + * @note This function is only implemented for certain template + * arguments T, namely float, double, int, + * unsigned int. + */ + template + T sum (const T &t, + const MPI_Comm &mpi_communicator); + } /** * A namespace for utility functions that * probe system properties. @@ -440,23 +468,6 @@ namespace Utilities */ MPI_Comm duplicate_communicator (const MPI_Comm &mpi_communicator); - - /** - * Return the sum over all processors of the value @p t. This function - * is collective over all processors given in the communicator. If - * deal.II is not configured for use of MPI, this function simply - * returns the value of @p t. This function corresponds to the - * MPI_Allreduce function, i.e. all processors receive - * the result of this operation. - * - * @note This function is only implemented for certain template - * arguments T, namely float, double, int, - * unsigned int. - */ - template - T calculate_collective_mpi_sum (const T &t, - const MPI_Comm &mpi_communicator); - /** * Data structure to store the result of * calculate_collective_mpi_min_max_avg. @@ -881,7 +892,7 @@ namespace Utilities } - namespace System + namespace MPI { namespace internal { @@ -916,8 +927,8 @@ namespace Utilities template inline - T calculate_collective_mpi_sum (const T &t, - const MPI_Comm &mpi_communicator) + T sum (const T &t, + const MPI_Comm &mpi_communicator) { #ifdef DEAL_II_COMPILER_SUPPORTS_MPI T sum; diff --git a/tests/mpi/collective_02.cc b/tests/mpi/collective_02.cc index 386b1be0ae..a0e97f1983 100644 --- a/tests/mpi/collective_02.cc +++ b/tests/mpi/collective_02.cc @@ -27,20 +27,20 @@ void test() int int_sum, uint_sum, double_sum, float_sum; int_sum = - Utilities::System::calculate_collective_mpi_sum(myid+1, - MPI_COMM_WORLD); + Utilities::MPI::sum(myid+1, + MPI_COMM_WORLD); uint_sum = - Utilities::System::calculate_collective_mpi_sum(myid+1, - MPI_COMM_WORLD); + Utilities::MPI::sum(myid+1, + MPI_COMM_WORLD); float_sum = - Utilities::System::calculate_collective_mpi_sum(myid+1, - MPI_COMM_WORLD); + Utilities::MPI::sum(myid+1, + MPI_COMM_WORLD); double_sum = - Utilities::System::calculate_collective_mpi_sum(myid+1, - MPI_COMM_WORLD); + Utilities::MPI::sum(myid+1, + MPI_COMM_WORLD); if (myid==0) deallog << int_sum << ' ' << uint_sum << ' ' << double_sum << ' ' << float_sum << std::endl; -- 2.39.5