]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make a variable 'const'. 11954/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 22 Mar 2021 20:45:21 +0000 (21:45 +0100)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 31 Mar 2021 01:57:13 +0000 (19:57 -0600)
include/deal.II/base/mpi.h

index 6a281b3798fd63eddc4e82445d24613171be2e60..22fd0aea8b2d7d34a8bb1cc59423b28a0de86d36 100644 (file)
@@ -1500,14 +1500,26 @@ namespace Utilities
       AssertIndexRange(root_process, n_procs);
       (void)n_procs;
 
-      std::vector<char> buffer      = Utilities::pack(object_to_send, false);
-      unsigned int      buffer_size = buffer.size();
+      std::vector<char> 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);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.