7#ifndef PXR_BASE_WORK_LOOPS_H
8#define PXR_BASE_WORK_LOOPS_H
13#include "pxr/base/work/api.h"
15#include <tbb/blocked_range.h>
16#include <tbb/parallel_for.h>
17#include <tbb/parallel_for_each.h>
18#include <tbb/task_group.h>
20PXR_NAMESPACE_OPEN_SCOPE
38 std::forward<Fn>(fn)(0, n);
66 class Work_ParallelForN_TBB
69 Work_ParallelForN_TBB(Fn &fn) : _fn(fn) { }
71 void operator()(
const tbb::blocked_range<size_t> &r)
const {
77 std::forward<Fn>(_fn)(r.begin(), r.end());
86 tbb::task_group_context ctx(tbb::task_group_context::isolated);
87 tbb::parallel_for(tbb::blocked_range<size_t>(0,n,grainSize),
88 Work_ParallelForN_TBB(callback),
110template <
typename Fn>
130template <
typename InputIterator,
typename Fn>
133 InputIterator first, InputIterator last, Fn &&fn)
135 tbb::task_group_context ctx(tbb::task_group_context::isolated);
136 tbb::parallel_for_each(first, last, std::forward<Fn>(fn), ctx);
139PXR_NAMESPACE_CLOSE_SCOPE
void WorkParallelForEach(InputIterator first, InputIterator last, Fn &&fn)
WorkParallelForEach(Iterator first, Iterator last, CallbackType callback)
void WorkParallelForN(size_t n, Fn &&callback, size_t grainSize)
WorkParallelForN(size_t n, CallbackType callback, size_t grainSize = 1)
void WorkSerialForN(size_t n, Fn &&fn)
WorkSerialForN(size_t n, CallbackType callback)
WORK_API bool WorkHasConcurrency()
Return true if WorkGetPhysicalConcurrencyLimit() returns a number greater than 1 and PXR_WORK_THREAD_...