24 #ifndef PXR_BASE_WORK_REDUCE_H
25 #define PXR_BASE_WORK_REDUCE_H
30 #include "pxr/base/work/api.h"
32 #include <tbb/blocked_range.h>
33 #include <tbb/parallel_reduce.h>
36 PXR_NAMESPACE_OPEN_SCOPE
98 template <
typename Fn,
typename Rn,
typename V>
104 Rn &&reductionCallback,
116 Work_Body_TBB(Fn &fn) : _fn(fn) { }
119 const tbb::blocked_range<size_t> &r,
120 const V &value)
const {
126 return std::forward<Fn>(_fn)(r.begin(), r.end(), value);
134 tbb::task_group_context ctx(tbb::task_group_context::isolated);
135 return tbb::parallel_reduce(tbb::blocked_range<size_t>(0,n,grainSize),
137 Work_Body_TBB(loopCallback),
138 std::forward<Rn>(reductionCallback),
139 tbb::auto_partitioner(),
144 return std::forward<Fn>(loopCallback)(0, n, identity);
155 template <
typename Fn,
typename Rn,
typename V>
161 Rn &&reductionCallback)
166 PXR_NAMESPACE_CLOSE_SCOPE
168 #endif // PXR_BASE_WORK_REDUCE_H
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_...