diff --git a/include/boost/mpi/collectives/gather.hpp b/include/boost/mpi/collectives/gather.hpp index 4f39392..70dfd65 100644 --- a/include/boost/mpi/collectives/gather.hpp +++ b/include/boost/mpi/collectives/gather.hpp @@ -131,7 +131,12 @@ void gather(const communicator& comm, const T* in_values, int n, std::vector& out_values, int root) { - ::boost::mpi::gather(comm, in_values, n, &out_values[0], root); + if (comm.rank() == root) { + out_values.resize(comm.size() * n); + ::boost::mpi::gather(comm, in_values, n, &out_values[0], root); + } + else + ::boost::mpi::gather(comm, in_values, n, root); } template