Skip to content

Commit

Permalink
Minor MPI improvements (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
garth-wells committed Oct 19, 2021
1 parent fafd816 commit 3a937ba
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cpp/dolfinx/common/MPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,21 @@ graph::AdjacencyList<T> all_to_all(MPI_Comm comm,

// Data size per destination rank
std::vector<int> send_size(comm_size);
std::adjacent_difference(std::next(send_offsets.begin(), +1),
send_offsets.end(), send_size.begin());
std::adjacent_difference(std::next(send_offsets.begin()), send_offsets.end(),
send_size.begin());

// Get received data sizes from each rank
std::vector<int> recv_size(comm_size);
MPI_Alltoall(send_size.data(), 1, mpi_type<int>(), recv_size.data(), 1,
mpi_type<int>(), comm);

// Compute receive offset
std::vector<std::int32_t> recv_offset(comm_size + 1);
recv_offset[0] = 0;
std::vector<std::int32_t> recv_offset(comm_size + 1, 0);
std::partial_sum(recv_size.begin(), recv_size.end(),
std::next(recv_offset.begin()));

// Send/receive data
std::vector<T> recv_values(recv_offset[comm_size]);
std::vector<T> recv_values(recv_offset.back());
MPI_Alltoallv(values_in.data(), send_size.data(), send_offsets.data(),
mpi_type<T>(), recv_values.data(), recv_size.data(),
recv_offset.data(), mpi_type<T>(), comm);
Expand Down

0 comments on commit 3a937ba

Please sign in to comment.