From 32fd05ec18a05cefa3a7090c740e87401febcfcc Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 20 Apr 2021 18:02:06 -0600 Subject: [PATCH] Minor optimization in Utilities::MPI::broadcast(). --- include/deal.II/base/mpi.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 2a0e52342b..670f439b16 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -1114,7 +1114,9 @@ namespace Utilities * @param[in] root_process The process that sends the object to all * processes. By default the process with rank 0 is the root process. * - * @return Every process receives the object sent by the @p root_process. + * @return On the root process, return a copy of @p object_to_send. + * On every other process, return a copy of the object sent by + * the @p root_process. */ template T @@ -1514,6 +1516,8 @@ namespace Utilities # endif } + + template T broadcast(const MPI_Comm & comm, @@ -1553,7 +1557,10 @@ namespace Utilities MPI_Bcast(buffer.data(), buffer_size, MPI_CHAR, root_process, comm); AssertThrowMPI(ierr); - return Utilities::unpack(buffer, false); + if (Utilities::MPI::this_mpi_process(comm) == root_process) + return object_to_send; + else + return Utilities::unpack(buffer, false); # endif } -- 2.39.5