7#ifndef PXR_BASE_WORK_TBB_LOOPS_IMPL_H
8#define PXR_BASE_WORK_TBB_LOOPS_IMPL_H
12#include <tbb/blocked_range.h>
13#include <tbb/parallel_for.h>
14#include <tbb/parallel_for_each.h>
15#include <tbb/task_group.h>
21#define WORK_IMPL_HAS_PARALLEL_FOR_TBB_RANGE
23PXR_NAMESPACE_OPEN_SCOPE
31WorkImpl_ParallelForN(
size_t n, Fn &&callback,
size_t grainSize)
33 class Work_ParallelForN_TBB
36 Work_ParallelForN_TBB(Fn &fn) : _fn(fn) { }
38 void operator()(
const tbb::blocked_range<size_t> &r)
const {
44 std::forward<Fn>(_fn)(r.begin(), r.end());
53 tbb::task_group_context ctx(tbb::task_group_context::isolated);
54 tbb::parallel_for(tbb::blocked_range<size_t>(0,n,grainSize),
55 Work_ParallelForN_TBB(callback),
61template <
typename RangeType,
typename Fn>
63WorkImpl_ParallelForTBBRange(
const RangeType &range, Fn &&callback)
65 tbb::task_group_context ctx(tbb::task_group_context::isolated);
66 tbb::parallel_for(range, std::forward<Fn>(callback), ctx);
71template <
typename InputIterator,
typename Fn>
73WorkImpl_ParallelForEach(
74 InputIterator first, InputIterator last, Fn &&fn)
76 tbb::task_group_context ctx(tbb::task_group_context::isolated);
77 tbb::parallel_for_each(first, last, std::forward<Fn>(fn), ctx);
80PXR_NAMESPACE_CLOSE_SCOPE