TRIQS/mpi
2.0.0
C++ interface to MPI
Toggle main menu visibility
Loading...
Searching...
No Matches
chunk.hpp
Go to the documentation of this file.
1
// Copyright (c) 2024 Simons Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0.txt
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
// Authors: Thomas Hahn, Alexander Hampel, Olivier Parcollet, Nils Wentzell
16
21
22
#pragma once
23
24
#include "
./communicator.hpp
"
25
#include "
./macros.hpp
"
26
27
#include <itertools/itertools.hpp>
28
29
#include <iterator>
30
#include <utility>
31
32
namespace
mpi {
33
38
54
[[nodiscard]]
inline
long
chunk_length
(
long
end,
int
n,
int
i,
long
min_size = 1) {
55
EXPECTS_WITH_MESSAGE(min_size > 0 && end % min_size == 0,
"Error in mpi::chunk_length: min_size must be a divisor of end"
);
56
auto
[node_begin, node_end] = itertools::chunk_range(0, end / min_size, n, i);
57
return
(node_end - node_begin) * min_size;
58
}
59
71
template
<
typename
R> [[nodiscard]]
auto
chunk
(R &&rg,
communicator
c = {}) {
72
auto
total_size = itertools::distance(std::cbegin(rg), std::cend(rg));
73
auto
[start_idx, end_idx] = itertools::chunk_range(0, total_size, c.size(), c.rank());
74
return
itertools::slice(std::forward<R>(rg), start_idx, end_idx);
75
}
76
78
79
}
// namespace mpi
mpi::communicator
C++ wrapper around MPI_Comm providing various convenience functions.
Definition
communicator.hpp:51
communicator.hpp
Provides a C++ wrapper class for an MPI_Comm object.
mpi::chunk
auto chunk(R &&rg, communicator c={})
Divide a given range as evenly as possible across the MPI processes in a communicator.
Definition
chunk.hpp:71
mpi::chunk_length
long chunk_length(long end, int n, 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...
Definition
chunk.hpp:54
macros.hpp
Macros used in the mpi library.
mpi
chunk.hpp
Generated by
1.17.0