13# if defined(WIN32) && !defined(NOMINMAX)
17# define TBB_MIN_MAX_CLEANUP
19# include <tbb/blocked_range.h>
20# include <tbb/parallel_for.h>
21# include <tbb/parallel_for_each.h>
22# include <tbb/parallel_invoke.h>
23# include <tbb/parallel_reduce.h>
24# include <tbb/task_arena.h>
29# ifdef TBB_MIN_MAX_CLEANUP
55template<
typename Range,
typename Function>
59 tbb::parallel_for_each(range, function);
61 for (
auto &&value : range) {
92template<
typename Function>
95 const Function &function,
119 const int64_t alignment_mask = ~(alignment - 1);
121 const int64_t unaligned_begin = unaligned_range.
start();
123 const int64_t aligned_begin = std::max(global_begin, unaligned_begin & alignment_mask);
124 const int64_t aligned_end = unaligned_end == global_end ?
126 std::max(global_begin, unaligned_end & alignment_mask);
128 return aligned_range;
138template<
typename Function>
142 const Function &function)
146 function(aligned_range);
150template<
typename Value,
typename Function,
typename Reduction>
153 const Value &identity,
154 const Function &function,
155 const Reduction &reduction)
158 if (range.
size() >= grain_size) {
160 return tbb::parallel_reduce(
163 [&](
const tbb::blocked_range<int64_t> &subrange,
const Value &ident) {
164 return function(IndexRange(subrange.begin(), subrange.size()), ident);
171 return function(range, identity);
174template<
typename Value,
typename Function,
typename Reduction>
178 const Value &identity,
179 const Function &function,
180 const Reduction &reduction)
186 [&](
const IndexRange unaligned_range,
const Value &ident) {
188 function(aligned_range, ident);
193template<
typename Value,
typename Function,
typename Reduction>
196 const Value &identity,
197 const Function &function,
198 const Reduction &reduction)
201 if (range.
size() >= grain_size) {
203 return tbb::parallel_deterministic_reduce(
206 [&](
const tbb::blocked_range<int64_t> &subrange,
const Value &ident) {
207 return function(IndexRange(subrange.begin(), subrange.size()), ident);
214 return function(range, identity);
224 tbb::parallel_invoke(std::forward<Functions>(functions)...);
235template<
typename... Functions>
248template<
typename Function>
inline void isolate_task(
const Function &function)
252 tbb::this_task_arena::isolate(function);
264template<
typename Function>
266 const Function &function)
273 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 memory_bandwidth_bound_task_impl(FunctionRef< void()> function)
void isolate_task(const Function &function)
void parallel_invoke(Functions &&...functions)
void parallel_for_each(Range &&range, 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)
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)
constexpr GrainSize(const int64_t grain_size)