14 #ifndef ALPS_PARAMS_MPI_VARIANT_HPP_69d56023ac6048ca987f4be0f67122af 15 #define ALPS_PARAMS_MPI_VARIANT_HPP_69d56023ac6048ca987f4be0f67122af 33 struct broadcast_sender {
40 void operator()(
const T& val) {
42 assert(comm_.
rank()==root_ &&
"Should be only called by broadcast root");
43 broadcast(comm_, const_cast<T&>(val), root_);
48 struct broadcast_receiver {
55 : target_which(which), which_count(0), comm_(comm), root_(root)
59 boost::optional<T> operator()(
const T*)
62 assert(comm_.
rank()!=root_ &&
"Should NOT be called by broadcast root");
63 boost::optional<T> ret;
64 if (target_which==which_count) {
74 typedef alps::detail::variant_serializer<alps::params_ns::detail::dict_all_types,
75 broadcast_sender, broadcast_receiver> var_serializer;
76 typedef var_serializer::variant_type variant_type;
81 template <
typename MPLSEQ>
86 int which=var.which();
89 if (comm.
rank()==root) {
90 detail::broadcast_sender consumer(comm, root);
91 detail::var_serializer::consume(consumer, var);
93 detail::broadcast_receiver producer(which, comm, root);
94 var=detail::var_serializer::produce(producer);
Encapsulation of an MPI communicator and some communicator-related operations.
Header for boost::variant serialization.
Header for object-oriented interface to MPI for std::pair.
int rank() const
Returns process rank in this communicator.
void broadcast(const communicator &comm, T *vals, std::size_t count, int root)
Broadcasts array vals of a primitive type T, length count on communicator comm with root root ...