@brief Return local range for the calling process, partitioning the global [0, N - 1] range across all ranks into partitions of almost equal size. @param[in] rank MPI rank of the caller @param[in] N The value to partition. @param[in] size Number of MPI ranks across which to partition `N`.
| 87 | /// @param[in] N The value to partition. |
| 88 | /// @param[in] size Number of MPI ranks across which to partition `N`. |
| 89 | constexpr std::array<std::int64_t, 2> local_range(int rank, std::int64_t N, |
| 90 | int size) |
| 91 | { |
| 92 | assert(rank >= 0); |
| 93 | assert(N >= 0); |
| 94 | assert(size > 0); |
| 95 | |
| 96 | // Compute number of items per rank and remainder |
| 97 | const std::int64_t n = N / size; |
| 98 | const std::int64_t r = N % size; |
| 99 | |
| 100 | // Compute local range |
| 101 | if (rank < r) |
| 102 | return {rank * (n + 1), rank * (n + 1) + n + 1}; |
| 103 | else |
| 104 | return {rank * n + r, rank * n + r + n}; |
| 105 | } |
| 106 | |
| 107 | /// @brief Return which rank owns index in global range [0, N - 1] |
| 108 | /// (inverse of MPI::local_range). |
no outgoing calls
no test coverage detected