94 if (not target.is_contiguous()) NDA_RUNTIME_ERROR <<
"Error in MPI scatter for nda::Array: Target array needs to be contiguous";
95 static_assert(std::decay_t<A>::layout_t::stride_order_encoded == std::decay_t<T>::layout_t::stride_order_encoded,
96 "Error in MPI scatter for nda::Array: Incompatible stride orders");
99 if (not mpi::has_env) {
106 resize_or_check_if_view(target, dims);
109 auto dim0 = rhs.extent(0);
110 auto stride0 = rhs.indexmap().strides()[0];
111 auto sendcounts = std::vector<int>(comm.size());
112 auto displs = std::vector<int>(comm.size() + 1, 0);
113 int recvcount = mpi::chunk_length(dim0, comm.size(), comm.rank()) * stride0;
114 for (
int r = 0; r < comm.size(); ++r) {
115 sendcounts[r] = mpi::chunk_length(dim0, comm.size(), r) * stride0;
116 displs[r + 1] = sendcounts[r] + displs[r];
120 auto mpi_value_type = mpi::mpi_type<value_type>::get();
121 MPI_Scatterv((
void *)rhs.data(), &sendcounts[0], &displs[0], mpi_value_type, (
void *)target.data(), recvcount, mpi_value_type, root, comm.get());