11 #ifndef ALPS_GF_MPI_BCAST_HPP_c030bec39d4b43b9a24a16b5805f542d 12 #define ALPS_GF_MPI_BCAST_HPP_c030bec39d4b43b9a24a16b5805f542d 23 typedef std::vector<T> data_type;
24 typedef typename data_type::size_type size_type;
25 size_type root_sz=data.size();
39 template <
typename T,
size_t N>
42 typedef boost::multi_array<T,N> data_type;
44 typedef typename data_type::size_type size_type;
47 const bool is_root=(rank==root);
51 if (! (data.storage_order()==boost::c_storage_order()) )
52 throw std::logic_error(
"Unsupported storage order in multi_array broadcast at rank #"+
53 std::to_string(rank));
57 #ifndef BOOST_DISABLE_ASSERTS 62 throw std::logic_error(
"Different multi_array dimensions in broadcast:\n" 69 " has N="+std::to_string(N));
73 }
catch (
const std::exception& exc) {
75 std::cerr <<
"Exception in broadcast of boost::multi_array data on rank " << rank << std::endl
77 <<
"\nAborting." << std::endl;
78 MPI_Abort(MPI_COMM_WORLD,1);
85 boost::array<index_type,N> bases;
86 const index_type* root_bases=data.index_bases();
88 std::copy(root_bases, root_bases+N, bases.begin());
93 boost::array<size_type,N> shape;
95 const size_type* root_shape=data.shape();
96 std::copy(root_shape, root_shape+N, shape.begin());
105 size_t nelements=data.num_elements();
109 unsigned long nelements_root=nelements;
111 if (nelements_root!=nelements) {
114 std::cerr <<
"Broadcast of incompatible boost::multi_array data detected on rank " << rank
115 <<
".\nRoot sends " << nelements_root <<
" elements," 116 <<
" this process expects " << nelements <<
" elements." 119 MPI_Abort(MPI_COMM_WORLD, 1);
index_mesh::index_type index
void broadcast(C const &c, P &p, int r=0)
Header for object-oriented interface to MPI (similar to boost::mpi)
Encapsulation of an MPI communicator and some communicator-related operations.
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 ...