52 template <std::default_initializable T>
54 bool has_val = opt.has_value();
58 if (!opt.has_value()) opt.emplace();
82 template <
typename T1, std::default_initializable T2>
84 MPI_Op op = MPI_SUM) {
87 "mpi::reduce_into for std::optional requires all ranks to have consistent has_value state");
89 bool const receives = (c.rank() == root || all);
91 if (opt_in.has_value()) {
93 if (!opt_out.has_value()) opt_out.emplace();
99 }
else if (receives) {
C++ wrapper around MPI_Comm providing various convenience functions.
Provides a C++ wrapper class for an MPI_Comm object.
Provides generic implementations for a subset of collective MPI communications (broadcast,...
void mpi_reduce_into(std::array< T1, N1 > const &arr_in, std::array< T2, N2 > &arr_out, communicator c={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for a std::array that reduces directly into an existing output array.
void reduce_into(T1 &&x_in, T2 &&x_out, communicator c={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Generic MPI reduce that reduces directly into an existing output object.
void mpi_broadcast(std::array< T, N > &arr, communicator c={}, int root=0)
Implementation of an MPI broadcast for a std::array.
bool all_equal(T const &x, communicator c={})
Checks if a given object is equal across all ranks in the given communicator.
void broadcast(T &&x, communicator c={}, int root=0)
Generic MPI broadcast.
Macros used in the mpi library.