Function utils::mpiPartitionRange
Defined in File MPIUtils.hpp
Function Documentation
-
inline auto utils::mpiPartitionRange(const unsigned long rangeStart, const unsigned long rangeEnd) -> std::pair<unsigned long, unsigned long>
Divide a contiguous trial-number range evenly across every MPI rank.
Splits [rangeStart, rangeEnd) into mpiSize() contiguous sub-ranges, as evenly as possible: with total = rangeEnd - rangeStart, base = total / mpiSize() trials go to every rank, and the first (total % mpiSize()) ranks each get one additional trial, so the sub-ranges’ own sizes add up to exactly total regardless of whether it divides evenly. When mpiSize() == 1 (including every build not compiled with SLUG_MPI), this always returns {rangeStart, rangeEnd} unchanged.
- Parameters:
rangeStart – Start of the range to divide (inclusive)
rangeEnd – End of the range to divide (exclusive)
- Returns:
The [start, end) sub-range of [rangeStart, rangeEnd) that this process’s own rank should run – every rank’s own returned sub-range is disjoint from every other rank’s, and their union is exactly [rangeStart, rangeEnd), so trial numbers themselves never collide across ranks (only unique IDs need mpiUidStride for that – see its own comment)