123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #ifndef BOOST_MPI_BROADCAST_HPP
- #define BOOST_MPI_BROADCAST_HPP
- #include <boost/mpi/collectives_fwd.hpp>
- #include <boost/mpi/exception.hpp>
- #include <boost/mpi/datatype.hpp>
- #include <boost/mpi/communicator.hpp>
- namespace boost { namespace mpi {
- template<>
- BOOST_MPI_DECL void
- broadcast<const packed_oarchive>(const communicator& comm,
- const packed_oarchive& oa,
- int root);
- template<>
- BOOST_MPI_DECL void
- broadcast<packed_oarchive>(const communicator& comm, packed_oarchive& oa,
- int root);
- template<>
- BOOST_MPI_DECL void
- broadcast<packed_iarchive>(const communicator& comm, packed_iarchive& ia,
- int root);
- template<>
- BOOST_MPI_DECL void
- broadcast<const packed_skeleton_oarchive>(const communicator& comm,
- const packed_skeleton_oarchive& oa,
- int root);
- template<>
- void
- broadcast<packed_skeleton_oarchive>(const communicator& comm,
- packed_skeleton_oarchive& oa, int root);
- template<>
- void
- broadcast<packed_skeleton_iarchive>(const communicator& comm,
- packed_skeleton_iarchive& ia, int root);
- template<>
- void broadcast<content>(const communicator& comm, content& c, int root);
- template<>
- void broadcast<const content>(const communicator& comm, const content& c,
- int root);
- namespace detail {
-
-
- template<typename T>
- void
- broadcast_impl(const communicator& comm, T* values, int n, int root,
- mpl::true_)
- {
- BOOST_MPI_CHECK_RESULT(MPI_Bcast,
- (values, n,
- boost::mpi::get_mpi_datatype<T>(*values),
- root, MPI_Comm(comm)));
- }
-
-
- template<typename T>
- void
- broadcast_impl(const communicator& comm, T* values, int n, int root,
- mpl::false_ non_mpi_datatype)
- {
-
- if (comm.rank() == root) {
- packed_oarchive oa(comm);
- for (int i = 0; i < n; ++i) {
- oa << values[i];
- }
- 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);
- 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];
- }
- }
- }
- template<typename T>
- void broadcast(const communicator& comm, T& value, int root)
- {
- detail::broadcast_impl(comm, &value, 1, root, is_mpi_datatype<T>());
- }
- template<typename T>
- void broadcast(const communicator& comm, T* values, int n, int root)
- {
- detail::broadcast_impl(comm, values, n, root, is_mpi_datatype<T>());
- }
- } }
- #ifdef BOOST_MPI_SKELETON_AND_CONTENT_HPP
- # include <boost/mpi/detail/broadcast_sc.hpp>
- #endif
- #endif
|