54 auto count = v.size();
56 if (c.rank() != root) v.resize(count);
77 template <
typename T>
auto mpi_reduce(std::vector<T>
const &v,
communicator c = {},
int root = 0,
bool all =
false, MPI_Op op = MPI_SUM) {
78 using value_type = std::remove_cvref_t<decltype(reduce(std::declval<T>()))>;
79 std::vector<value_type> res(c.rank() == root || all ? v.size() : 0);
99 template <
typename T1,
typename T2>
101 MPI_Op op = MPI_SUM) {
102 if ((c.rank() == root || all) && v_out.size() != v_in.size()) v_out.resize(v_in.size());
120 auto scatter_size =
static_cast<int>(v_in.size());
122 auto const recvcount =
chunk_length(scatter_size, c.size(), c.rank());
123 if (v_out.size() != recvcount) v_out.resize(recvcount);
141 template <
typename T>
void mpi_gather_into(std::vector<T>
const &v_in, std::vector<T> &v_out,
communicator c = {},
int root = 0,
bool all =
false) {
143 if ((c.rank() == root || all) && v_out.size() != gather_size) v_out.resize(gather_size);
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,...
auto mpi_reduce(std::array< T, N > const &arr, communicator c={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for a std::array.
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 mpi_scatter_into(std::vector< T > const &v_in, std::vector< T > &v_out, communicator c={}, int root=0)
Implementation of an MPI scatter for a std::vector that scatters directly into an existing output vec...
void mpi_gather_into(T const &x, R &&rg, communicator c={}, int root=0, bool all=false)
Implementation of an MPI gather that gathers directly into an existing output range for types that ha...
void reduce_range(R1 &&in_rg, R2 &&out_rg, communicator c={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for std::ranges::sized_range objects.
void gather_range(R1 &&in_rg, R2 &&out_rg, communicator c={}, int root=0, bool all=false)
Implementation of an MPI gather for mpi::MPICompatibleRange objects.
void broadcast_range(R &&rg, communicator c={}, int root=0)
Implementation of an MPI broadcast for std::ranges::sized_range objects.
void scatter_range(R1 &&in_rg, R2 &&out_rg, long scatter_size, communicator c={}, int root=0, long chunk_size=1)
Implementation of an MPI scatter for mpi::MPICompatibleRange objects.
void mpi_broadcast(std::array< T, N > &arr, communicator c={}, int root=0)
Implementation of an MPI broadcast for a std::array.
decltype(auto) all_reduce(T &&x, communicator c={}, MPI_Op op=MPI_SUM)
Generic MPI all-reduce.
void broadcast(T &&x, communicator c={}, int root=0)
Generic MPI broadcast.
long chunk_length(long end, int nranges, int i, long min_size=1)
Get the length of the ith subrange after splitting the integer range [0, end) as evenly as possible a...
Provides an MPI broadcast, reduce, scatter and gather for generic ranges.
Provides general utilities related to MPI.