TRIQS/itertools
2.0.0
C++ range library
Toggle main menu visibility
Loading...
Searching...
No Matches
omp_chunk.hpp
Go to the documentation of this file.
1
// Copyright (c) 2019-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, Olivier Parcollet, Nils Wentzell
16
21
22
#pragma once
23
24
#include "
./itertools.hpp
"
25
26
#include <omp.h>
27
28
namespace
itertools {
29
41
template
<
typename
R>
auto
omp_chunk
(R &&rg) {
42
auto
total_size =
itertools::distance
(std::cbegin(rg), std::cend(rg));
43
auto
[start_idx, end_idx] =
chunk_range
(0, total_size, omp_get_num_threads(), omp_get_thread_num());
44
return
itertools::slice
(std::forward<R>(rg), start_idx, end_idx);
45
}
46
47
}
// namespace itertools
itertools::slice
sliced< R > slice(R &&rg, std::ptrdiff_t start_idx, std::ptrdiff_t end_idx)
Lazy-slice a given range.
Definition
slice.hpp:123
itertools::chunk_range
std::pair< std::ptrdiff_t, std::ptrdiff_t > chunk_range(std::ptrdiff_t first, std::ptrdiff_t last, long n_chunks, long rank)
Given an integer range [first, last), divide it as equally as possible into N chunks.
Definition
utils.hpp:93
itertools::distance
std::iterator_traits< Iter1 >::difference_type distance(Iter1 first, Iter2 last)
Calculate the distance between two iterators.
Definition
utils.hpp:51
itertools::omp_chunk
auto omp_chunk(R &&rg)
Distribute a range as evenly as possible across all OMP threads.
Definition
omp_chunk.hpp:41
itertools.hpp
Provides a small subset of the ranges and views from std::ranges.
itertools
omp_chunk.hpp
Generated by
1.17.0