100 if (not target.is_contiguous()) NDA_RUNTIME_ERROR <<
"Error in MPI gather for nda::Array: Target array needs to be contiguous";
101 static_assert(std::decay_t<A>::layout_t::stride_order_encoded == std::decay_t<T>::layout_t::stride_order_encoded,
102 "Error in MPI gather for nda::Array: Incompatible stride orders");
105 if (not mpi::has_env) {
115 auto recvcounts = std::vector<int>(comm.size());
116 auto displs = std::vector<int>(comm.size() + 1, 0);
117 int sendcount = rhs.size();
118 auto mpi_int_type = mpi::mpi_type<int>::get();
120 MPI_Gather(&sendcount, 1, mpi_int_type, &recvcounts[0], 1, mpi_int_type, root, comm.get());
122 MPI_Allgather(&sendcount, 1, mpi_int_type, &recvcounts[0], 1, mpi_int_type, comm.get());
124 for (
int r = 0; r < comm.size(); ++r) displs[r + 1] = recvcounts[r] + displs[r];
127 auto mpi_value_type = mpi::mpi_type<value_type>::get();
129 MPI_Gatherv((
void *)rhs.data(), sendcount, mpi_value_type, target.data(), &recvcounts[0], &displs[0], mpi_value_type, root, comm.get());
131 MPI_Allgatherv((
void *)rhs.data(), sendcount, mpi_value_type, target.data(), &recvcounts[0], &displs[0], mpi_value_type, comm.get());