DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
local_range.h
1
2// Copyright (C) 2007-2023 Magnus Vikstrøm, Garth N. Wells and Paul T. Kühner
3//
4// This file is part of DOLFINx (https://www.fenicsproject.org)
5//
6// SPDX-License-Identifier: LGPL-3.0-or-later
7
8#pragma once
9
10#include <array>
11#include <cassert>
12#include <cstdint>
13
14namespace dolfinx::common
15{
26constexpr std::array<std::int64_t, 2> local_range(int index, std::int64_t N,
27 int size)
28{
29 assert(index >= 0);
30 assert(N >= 0);
31 assert(size > 0);
32
33 // Compute number of items per rank and remainder
34 const std::int64_t n = N / size;
35 const std::int64_t r = N % size;
36
37 // Compute local range
38 if (index < r)
39 return {index * (n + 1), index * (n + 1) + n + 1};
40 else
41 return {index * n + r, index * n + r + n};
42}
43} // namespace dolfinx::common
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
constexpr std::array< std::int64_t, 2 > local_range(int index, std::int64_t N, int size)
Partition a global range [0, N - 1] across callers into non-overlapping sub-partitions of almost equa...
Definition local_range.h:26