67 template <
typename A1,
typename A2>
69 void mpi_reduce_into(A1
const &a_in, A2 &&a_out, mpi::communicator comm = {},
int root = 0,
bool all =
false, MPI_Op op = MPI_SUM) {
71 EXPECTS_WITH_MESSAGE(detail::have_mpi_equal_shapes(a_in, comm),
"Error in nda::mpi_reduce_into: Shapes of arrays/views must be equal");
74 bool const receives = (
all || (comm.rank() == root));
79 if (a_in.is_contiguous() and a_in.has_positive_strides()) {
80 auto a_in_span = std::span{a_in.data(),
static_cast<std::size_t
>(a_in.size())};
81 if ((a_out.is_contiguous() and a_out.has_positive_strides()) || !receives) {
82 auto a_out_span = std::span{a_out.data(),
static_cast<std::size_t
>(a_out.size())};
83 mpi::reduce_range(a_in_span, a_out_span, comm, root,
all, op);
85 mpi::reduce_range(a_in_span, a_out, comm, root,
all, op);
88 if ((a_out.is_contiguous() and a_out.has_positive_strides()) || !receives) {
89 auto a_out_span = std::span{a_out.data(),
static_cast<std::size_t
>(a_out.size())};
90 mpi::reduce_range(a_in, a_out_span, comm, root,
all, op);
92 mpi::reduce_range(a_in, a_out, comm, root,
all, op);
127 template <
typename A>
129 auto mpi_reduce(A
const &a, mpi::communicator comm = {},
int root = 0,
bool all =
false, MPI_Op op = MPI_SUM) {
130 using value_t = std::remove_cvref_t<
decltype(mpi::reduce(std::declval<
get_value_t<A>>()))>;
131 using return_t = basic_array<value_t, get_rank<A>,
typename A::layout_policy_t::contiguous_t, get_algebra<A>,
heap<>>;
Provides basic functions to create and manipulate arrays and views.
Provides concepts for the nda library.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
bool all(A const &a)
Do all elements of the array evaluate to true?
void resize_or_check_if_view(A &a, std::array< long, A::rank > const &sha)
Resize a given regular array to the given shape or check if a given view as the correct shape.
auto mpi_reduce(A const &a, mpi::communicator comm={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for nda::basic_array or nda::basic_array_view types.
void mpi_reduce_into(A1 const &a_in, A2 &&a_out, mpi::communicator comm={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for nda::basic_array or nda::basic_array_view types that reduces dire...
std::decay_t< decltype(get_first_element(std::declval< A const >()))> get_value_t
Get the value type of an array/view or a scalar type.
constexpr bool is_regular_or_view_v
Constexpr variable that is true if type A is either a regular array or a view.
heap_basic< mem::mallocator< AdrSp > > heap
Alias template of the nda::heap_basic policy using an nda::mem::mallocator.
Macros used in the nda library.
Provides lazy function calls on arrays/views.
Provides various utility functions used by the MPI interface of nda.
Provides type traits for the nda library.