15 using namespace dolfinx;
57 const std::span<T>& recv_buffer,
58 MPI_Request& request)
const
61 if (_sizes_local.empty() and _sizes_remote.empty())
64 MPI_Ineighbor_alltoallv(
65 send_buffer.data(), _sizes_local.data(), _displs_local.data(),
66 MPI::mpi_type<T>(), recv_buffer.data(), _sizes_remote.data(),
67 _displs_remote.data(), MPI::mpi_type<T>(), _comm0.comm(), &request);
98 template <
typename T,
typename Functor>
100 std::span<T> local_buffer, std::span<T> remote_buffer,
101 Functor pack_fn, MPI_Request& request)
const
103 assert(local_buffer.size() == _local_inds.size());
104 assert(remote_buffer.size() == _remote_inds.size());
105 pack_fn(local_data, _local_inds, local_buffer);
128 template <
typename T,
typename Functor>
130 std::span<T> remote_data, Functor unpack_fn,
131 MPI_Request& request)
const
133 assert(remote_buffer.size() == _remote_inds.size());
134 assert(remote_data.size() == _remote_inds.size());
136 unpack_fn(remote_buffer, _remote_inds, remote_data,
137 [](T , T b) {
return b; });
151 template <
typename T>
153 std::span<T> remote_data)
const
158 auto pack_fn = [](
const auto& in,
const auto& idx,
auto& out)
160 for (std::size_t i = 0; i < idx.size(); ++i)
164 std::span<T>(remote_buffer), pack_fn, request);
166 auto unpack_fn = [](
const auto& in,
const auto& idx,
auto& out,
auto op)
168 for (std::size_t i = 0; i < idx.size(); ++i)
169 out[idx[i]] = op(out[idx[i]], in[i]);
172 scatter_fwd_end(std::span<const T>(remote_buffer), remote_data, unpack_fn,
200 template <
typename T>
202 const std::span<T>& recv_buffer,
203 MPI_Request& request)
const
206 if (_sizes_local.empty() and _sizes_remote.empty())
210 MPI_Ineighbor_alltoallv(
211 send_buffer.data(), _sizes_remote.data(), _displs_remote.data(),
212 MPI::mpi_type<T>(), recv_buffer.data(), _sizes_local.data(),
213 _displs_local.data(), MPI::mpi_type<T>(), _comm1.comm(), &request);
252 template <
typename T,
typename Functor>
254 std::span<T> remote_buffer, std::span<T> local_buffer,
255 Functor pack_fn, MPI_Request& request)
const
257 assert(local_buffer.size() == _local_inds.size());
258 assert(remote_buffer.size() == _remote_inds.size());
259 pack_fn(remote_data, _remote_inds, remote_buffer);
282 template <
typename T,
typename Functor,
typename BinaryOp>
284 std::span<T> local_data, Functor unpack_fn, BinaryOp op,
285 MPI_Request& request)
287 assert(local_buffer.size() == _local_inds.size());
288 if (_local_inds.size() > 0)
289 assert(*std::max_element(_local_inds.begin(), _local_inds.end())
290 < std::int32_t(local_data.size()));
292 unpack_fn(local_buffer, _local_inds, local_data, op);
297 template <
typename T,
typename BinaryOp>
299 const std::span<const T>& remote_data, BinaryOp op)
303 auto pack_fn = [](
const auto& in,
const auto& idx,
auto& out)
305 for (std::size_t i = 0; i < idx.size(); ++i)
308 auto unpack_fn = [](
const auto& in,
const auto& idx,
auto& out,
auto op)
310 for (std::size_t i = 0; i < idx.size(); ++i)
311 out[idx[i]] = op(out[idx[i]], in[i]);
315 std::span<T>(local_buffer), pack_fn, request);
316 scatter_rev_end(std::span<const T>(local_buffer), local_data, unpack_fn, op,
333 const std::vector<std::int32_t>&
local_indices() const noexcept;
342 int bs() const noexcept;
353 dolfinx::MPI::Comm _comm0;
360 dolfinx::MPI::Comm _comm1;
363 std::vector<std::int32_t> _remote_inds;
366 std::vector<
int> _sizes_remote;
369 std::vector<
int> _displs_remote;
374 std::vector<std::int32_t> _local_inds;
377 std::vector<
int> _sizes_local;
380 std::vector<
int> _displs_local;
This class represents the distribution index arrays across processes. An index array is a contiguous ...
Definition: IndexMap.h:64
A Scatterer supports the MPI scattering and gathering of data that is associated with a common::Index...
Definition: Scatterer.h:28
void scatter_fwd_end(const std::span< const T > &remote_buffer, std::span< T > remote_data, Functor unpack_fn, MPI_Request &request) const
Complete a non-blocking send from the local owner to process ranks that have the index as a ghost,...
Definition: Scatterer.h:129
void scatter_fwd(const std::span< const T > &local_data, std::span< T > remote_data) const
Scatter data associated with owned indices to ghosting ranks.
Definition: Scatterer.h:152
std::int32_t remote_buffer_size() const noexcept
Buffer size for remote data (ghosts) used in forward and reverse communication.
Definition: Scatterer.cpp:172
std::int32_t local_buffer_size() const noexcept
Size of buffer for local data (owned and shared) used in forward and reverse communication.
Definition: Scatterer.cpp:167
void scatter_rev_end(MPI_Request &request) const
End the reverse scatter communication.
Definition: Scatterer.cpp:157
void scatter_fwd_begin(const std::span< const T > &local_data, std::span< T > local_buffer, std::span< T > remote_buffer, Functor pack_fn, MPI_Request &request) const
Scatter data associated with owned indices to ghosting ranks.
Definition: Scatterer.h:99
void scatter_rev(std::span< T > local_data, const std::span< const T > &remote_data, BinaryOp op)
Scatter data associated with ghost indices to ranks that own the indices.
Definition: Scatterer.h:298
void scatter_fwd_end(MPI_Request &request) const
Complete a non-blocking send from the local owner to process ranks that have the index as a ghost.
Definition: Scatterer.cpp:147
void scatter_rev_end(const std::span< const T > &local_buffer, std::span< T > local_data, Functor unpack_fn, BinaryOp op, MPI_Request &request)
End the reverse scatter communication, and unpack the received local buffer into local data.
Definition: Scatterer.h:283
const std::vector< std::int32_t > & local_indices() const noexcept
Return a vector of local indices (owned) used to pack/unpack local data. These indices are grouped by...
Definition: Scatterer.cpp:177
void scatter_rev_begin(const std::span< const T > &send_buffer, const std::span< T > &recv_buffer, MPI_Request &request) const
Start a non-blocking send of ghost data to ranks that own the data.
Definition: Scatterer.h:201
void scatter_fwd_begin(const std::span< const T > &send_buffer, const std::span< T > &recv_buffer, MPI_Request &request) const
Start a non-blocking send of owned data to ranks that ghost the data.
Definition: Scatterer.h:56
const std::vector< std::int32_t > & remote_indices() const noexcept
Return a vector of remote indices (ghosts) used to pack/unpack ghost data. These indices are grouped ...
Definition: Scatterer.cpp:182
int bs() const noexcept
The number values (block size) to send per index in the common::IndexMap use to create the scatterer.
Definition: Scatterer.cpp:187
void scatter_rev_begin(const std::span< const T > &remote_data, std::span< T > remote_buffer, std::span< T > local_buffer, Functor pack_fn, MPI_Request &request) const
Scatter data associated with ghost indices to owning ranks.
Definition: Scatterer.h:253
Scatterer(const IndexMap &map, int bs)
Create a scatterer.
Definition: Scatterer.cpp:18
Miscellaneous classes, functions and types.