46 static_assert(std::is_trivial_v<T>);
47 if (comm.rank() == root) {
48 static std::vector<int> sizes;
49 static std::vector<int> displ;
51 detail::size_and_offset<T>(sizes, displ, n_elem, comm, root);
53 for (
auto i = 0u; i < static_cast<unsigned>(comm.size()); i++) {
54 sizes[i] *=
sizeof(T);
55 displ[i] *=
sizeof(T);
59 MPI_Scatterv(buffer, sizes.data(), displ.data(), MPI_BYTE, MPI_IN_PLACE, 0,
60 MPI_BYTE, root, comm);
62 detail::size_and_offset(n_elem, comm, root);
64 MPI_Scatterv(
nullptr,
nullptr,
nullptr, MPI_BYTE, buffer,
65 n_elem *
sizeof(T), MPI_BYTE, root, comm);
void scatter_buffer(T *buffer, int n_elem, boost::mpi::communicator comm, int root=0)
Scatter buffer with different size on each node.