From: Martin Kronbichler Date: Fri, 16 Aug 2024 09:18:50 +0000 (+0200) Subject: MPI allreduce: Do not invoke MPI function for MPI_COMM_SELF X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d3cf88f6dbce0910a850c02de4df85fa4c1f04a;p=dealii.git MPI allreduce: Do not invoke MPI function for MPI_COMM_SELF --- diff --git a/include/deal.II/base/mpi.templates.h b/include/deal.II/base/mpi.templates.h index 68ba42078b..8cc731768b 100644 --- a/include/deal.II/base/mpi.templates.h +++ b/include/deal.II/base/mpi.templates.h @@ -142,12 +142,17 @@ namespace Utilities T sum(const T &t, const MPI_Comm mpi_communicator) { - T return_value{}; - internal::all_reduce(MPI_SUM, - ArrayView(&t, 1), - mpi_communicator, - ArrayView(&return_value, 1)); - return return_value; + if (mpi_communicator == MPI_COMM_SELF) + return t; + else + { + T return_value{}; + internal::all_reduce(MPI_SUM, + ArrayView(&t, 1), + mpi_communicator, + ArrayView(&return_value, 1)); + return return_value; + } } @@ -174,7 +179,11 @@ namespace Utilities const MPI_Comm mpi_communicator, const ArrayView &sums) { - internal::all_reduce(MPI_SUM, values, mpi_communicator, sums); + if (mpi_communicator == MPI_COMM_SELF) + for (unsigned int i = 0; i < values.size(); ++i) + sums[i] = values[i]; + else + internal::all_reduce(MPI_SUM, values, mpi_communicator, sums); }