diff options
Diffstat (limited to 'boost/mpi/collectives/broadcast.hpp')
-rw-r--r-- | boost/mpi/collectives/broadcast.hpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/boost/mpi/collectives/broadcast.hpp b/boost/mpi/collectives/broadcast.hpp index d5160cff7f..f8b27f0b4f 100644 --- a/boost/mpi/collectives/broadcast.hpp +++ b/boost/mpi/collectives/broadcast.hpp @@ -100,22 +100,35 @@ namespace detail { } // We're sending a type that does not have an associated MPI - // datatype, so we'll need to serialize it. Unfortunately, this - // means that we cannot use MPI_Bcast, so we'll just send from the - // root to everyone else. + // datatype, so we'll need to serialize it. template<typename T> void broadcast_impl(const communicator& comm, T* values, int n, int root, - mpl::false_) + mpl::false_ non_mpi_datatype) { + // Implementation proposed by Lorenz Hübschle-Schneider if (comm.rank() == root) { packed_oarchive oa(comm); - for (int i = 0; i < n; ++i) + for (int i = 0; i < n; ++i) { oa << values[i]; - broadcast(comm, oa, root); + } + std::size_t asize = oa.size(); + broadcast(comm, asize, root); + void const* aptr = oa.address(); + BOOST_MPI_CHECK_RESULT(MPI_Bcast, + (const_cast<void*>(aptr), asize, + MPI_BYTE, + root, MPI_Comm(comm))); } else { packed_iarchive ia(comm); - broadcast(comm, ia, root); + std::size_t asize; + broadcast(comm, asize, root); + ia.resize(asize); + void* aptr = ia.address(); + BOOST_MPI_CHECK_RESULT(MPI_Bcast, + (aptr, asize, + MPI_BYTE, + root, MPI_Comm(comm))); for (int i = 0; i < n; ++i) ia >> values[i]; } |