26#include <itertools/itertools.hpp>
50 [[nodiscard]]
inline long chunk_length(
long end,
int nranges,
int i,
long min_size = 1) {
51 if (min_size < 1 || end % min_size != 0)
throw std::runtime_error(
"Error in mpi::chunk_length: min_size must be a divisor of end");
52 auto [node_begin, node_end] = itertools::chunk_range(0, end / min_size, nranges, i);
53 return (node_end - node_begin) * min_size;
67 auto total_size = itertools::distance(std::cbegin(rg), std::cend(rg));
68 auto [start_idx, end_idx] = itertools::chunk_range(0, total_size, c.size(), c.rank());
69 return itertools::slice(std::forward<R>(rg), start_idx, end_idx);
C++ wrapper around MPI_Comm providing various convenience functions.
Provides a C++ wrapper class for an MPI_Comm object.
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...
auto chunk(R &&rg, communicator c={})
Divide a given range as evenly as possible across the MPI processes in a communicator and get the sub...