7#ifndef PXR_BASE_WORK_REDUCE_H
8#define PXR_BASE_WORK_REDUCE_H
13#include "pxr/base/work/api.h"
15#include <tbb/blocked_range.h>
16#include <tbb/parallel_reduce.h>
17#include <tbb/task_group.h>
19PXR_NAMESPACE_OPEN_SCOPE
81template <
typename Fn,
typename Rn,
typename V>
87 Rn &&reductionCallback,
99 Work_Body_TBB(Fn &fn) : _fn(fn) { }
102 const tbb::blocked_range<size_t> &r,
103 const V &value)
const {
109 return std::forward<Fn>(_fn)(r.begin(), r.end(), value);
117 tbb::task_group_context ctx(tbb::task_group_context::isolated);
118 return tbb::parallel_reduce(tbb::blocked_range<size_t>(0,n,grainSize),
120 Work_Body_TBB(loopCallback),
121 std::forward<Rn>(reductionCallback),
122 tbb::auto_partitioner(),
127 return std::forward<Fn>(loopCallback)(0, n, identity);
138template <
typename Fn,
typename Rn,
typename V>
144 Rn &&reductionCallback)
149PXR_NAMESPACE_CLOSE_SCOPE
V WorkParallelReduceN(const V &identity, size_t n, Fn &&loopCallback, Rn &&reductionCallback, size_t grainSize)
Recursively splits the range [0, n) into subranges, which are then reduced by invoking loopCallback i...
WORK_API bool WorkHasConcurrency()
Return true if WorkGetPhysicalConcurrencyLimit() returns a number greater than 1 and PXR_WORK_THREAD_...