1 // Copyright (C) 2005, 2006 Douglas Gregor <doug.gregor -at- gmail.com>.
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Message Passing Interface 1.1 -- Section 4.4. Broadcast
8 #ifndef BOOST_MPI_BROADCAST_HPP
9 #define BOOST_MPI_BROADCAST_HPP
11 #include <boost/mpi/collectives_fwd.hpp>
12 #include <boost/mpi/exception.hpp>
13 #include <boost/mpi/datatype.hpp>
14 #include <boost/mpi/communicator.hpp>
16 namespace boost { namespace mpi {
18 /************************************************************************
20 ************************************************************************/
27 broadcast<const packed_oarchive>(const communicator& comm,
28 const packed_oarchive& oa,
36 broadcast<packed_oarchive>(const communicator& comm, packed_oarchive& oa,
44 broadcast<packed_iarchive>(const communicator& comm, packed_iarchive& ia,
52 broadcast<const packed_skeleton_oarchive>(const communicator& comm,
53 const packed_skeleton_oarchive& oa,
61 broadcast<packed_skeleton_oarchive>(const communicator& comm,
62 packed_skeleton_oarchive& oa, int root);
69 broadcast<packed_skeleton_iarchive>(const communicator& comm,
70 packed_skeleton_iarchive& ia, int root);
76 void broadcast<content>(const communicator& comm, content& c, int root);
82 void broadcast<const content>(const communicator& comm, const content& c,
85 /************************************************************************
86 * broadcast() implementation *
87 ************************************************************************/
89 // We're sending a type that has an associated MPI datatype, so
90 // we'll use MPI_Bcast to do all of the work.
93 broadcast_impl(const communicator& comm, T* values, int n, int root,
96 BOOST_MPI_CHECK_RESULT(MPI_Bcast,
98 boost::mpi::get_mpi_datatype<T>(*values),
99 root, MPI_Comm(comm)));
102 // We're sending a type that does not have an associated MPI
103 // datatype, so we'll need to serialize it. Unfortunately, this
104 // means that we cannot use MPI_Bcast, so we'll just send from the
105 // root to everyone else.
108 broadcast_impl(const communicator& comm, T* values, int n, int root,
111 if (comm.rank() == root) {
112 packed_oarchive oa(comm);
113 for (int i = 0; i < n; ++i)
115 broadcast(comm, oa, root);
117 packed_iarchive ia(comm);
118 broadcast(comm, ia, root);
119 for (int i = 0; i < n; ++i)
123 } // end namespace detail
126 void broadcast(const communicator& comm, T& value, int root)
128 detail::broadcast_impl(comm, &value, 1, root, is_mpi_datatype<T>());
132 void broadcast(const communicator& comm, T* values, int n, int root)
134 detail::broadcast_impl(comm, values, n, root, is_mpi_datatype<T>());
137 } } // end namespace boost::mpi
139 // If the user has already included skeleton_and_content.hpp, include
140 // the code to broadcast skeletons and content.
141 #ifdef BOOST_MPI_SKELETON_AND_CONTENT_HPP
142 # include <boost/mpi/detail/broadcast_sc.hpp>
145 #endif // BOOST_MPI_BROADCAST_HPP