13# include <tbb/blocked_range.h>
14# include <tbb/parallel_for.h>
15# include <tbb/parallel_for_each.h>
16# include <tbb/parallel_invoke.h>
17# include <tbb/parallel_reduce.h>
18# include <tbb/task_arena.h>
30template<
typename Range,
typename Function>
34 tbb::parallel_for_each(range, function);
36 for (
auto &&value : range) {
68template<
typename Function>
71 const Function &function,
95 const int64_t alignment_mask = ~(alignment - 1);
99 const int64_t aligned_begin = std::max(global_begin, unaligned_begin & alignment_mask);
100 const int64_t aligned_end = unaligned_end == global_end ?
102 std::max(global_begin, unaligned_end & alignment_mask);
104 return aligned_range;
114template<
typename Function>
118 const Function &function)
122 function(aligned_range);
126template<
typename Value,
typename Function,
typename Reduction>
129 const Value &identity,
130 const Function &function,
131 const Reduction &reduction)
134 if (range.
size() >= grain_size) {
136 return tbb::parallel_reduce(
139 [&](
const tbb::blocked_range<int64_t> &subrange,
const Value &ident) {
140 return function(IndexRange(subrange.begin(), subrange.size()), ident);
147 return function(range, identity);
150template<
typename Value,
typename Function,
typename Reduction>
154 const Value &identity,
155 const Function &function,
156 const Reduction &reduction)
162 [&](
const IndexRange unaligned_range,
const Value &ident) {
164 function(aligned_range, ident);
169template<
typename Value,
typename Function,
typename Reduction>
172 const Value &identity,
173 const Function &function,
174 const Reduction &reduction)
177 if (range.
size() >= grain_size) {
179 return tbb::parallel_deterministic_reduce(
182 [&](
const tbb::blocked_range<int64_t> &subrange,
const Value &ident) {
183 return function(IndexRange(subrange.begin(), subrange.size()), ident);
190 return function(range, identity);
200 tbb::parallel_invoke(std::forward<Functions>(functions)...);
211template<
typename... Functions>
224template<
typename Function>
inline auto isolate_task(
const Function &function)
228 return tbb::this_task_arena::isolate(function);
238template<
typename Function>
250template<
typename Function>
252 const Function &function)
259 if (approximate_bytes_touched <= 8 * 1024 * 1024) {
constexpr int64_t first() const
constexpr int64_t one_after_last() const
constexpr int64_t size() const
constexpr bool is_empty() const
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr int64_t start() const
void parallel_for_impl(IndexRange range, int64_t grain_size, FunctionRef< void(IndexRange)> function, const TaskSizeHints &size_hints)
void max_threads_task_impl(int max_threads, FunctionRef< void()> function)
void memory_bandwidth_bound_task_impl(FunctionRef< void()> function)
void parallel_invoke(Functions &&...functions)
void parallel_for_each(Range &&range, const Function &function)
void max_threads_task(const int max_threads, const Function &function)
Value parallel_deterministic_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
bool use_single_thread(const TaskSizeHints &size_hints, const IndexRange range, const int64_t threshold)
void memory_bandwidth_bound_task(const int64_t approximate_bytes_touched, const Function &function)
void parallel_for_aligned(const IndexRange range, const int64_t grain_size, const int64_t alignment, const Function &function)
auto isolate_task(const Function &function)
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Value parallel_reduce_aligned(const IndexRange range, const int64_t grain_size, const int64_t alignment, const Value &identity, const Function &function, const Reduction &reduction)
IndexRange align_sub_range(const IndexRange unaligned_range, const int64_t alignment, const IndexRange global_range)