From: Wolfgang Bangerth Date: Mon, 22 Mar 2021 20:45:21 +0000 (+0100) Subject: Make a variable 'const'. X-Git-Tag: v9.3.0-rc1~260^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11954%2Fhead;p=dealii.git Make a variable 'const'. --- 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);