From b8043dd3ee75fe99465b09be6d4b977936cc3a11 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 22 Mar 2021 21:45:21 +0100 Subject: [PATCH] Make a variable 'const'. --- include/deal.II/base/mpi.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 6a281b3798..22fd0aea8b 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -1500,14 +1500,26 @@ namespace Utilities AssertIndexRange(root_process, n_procs); (void)n_procs; - std::vector buffer = Utilities::pack(object_to_send, false); - unsigned int buffer_size = buffer.size(); + std::vector buffer; + unsigned int buffer_size = numbers::invalid_unsigned_int; - // Exchanging the size of buffer + // On the root process, pack the data and determine what the + // buffer size needs to be. + if (this_mpi_process(comm) == root_process) + { + buffer = Utilities::pack(object_to_send, false); + buffer_size = buffer.size(); + } + + // Exchange the size of buffer int ierr = MPI_Bcast(&buffer_size, 1, MPI_UNSIGNED, root_process, comm); AssertThrowMPI(ierr); - buffer.resize(buffer_size); + // If not on the root process, correctly size the buffer to + // receive the data, then do exactly that. + if (this_mpi_process(comm) != root_process) + buffer.resize(buffer_size); + ierr = MPI_Bcast(buffer.data(), buffer_size, MPI_CHAR, root_process, comm); AssertThrowMPI(ierr); -- 2.39.5