18 #ifndef NANOVDB_PREFIX_SUM_H_HAS_BEEN_INCLUDED
19 #define NANOVDB_PREFIX_SUM_H_HAS_BEEN_INCLUDED
25 #ifdef NANOVDB_USE_TBB
26 #include <tbb/parallel_scan.h>
38 template<
typename T,
typename OpT = std::plus<T>>
39 T prefixSum(std::vector<T> &vec,
bool threaded =
true, OpT op = OpT());
43 template<
typename T,
typename Op>
46 #ifndef NANOVDB_USE_TBB
52 #ifdef NANOVDB_USE_TBB
53 using RangeT = tbb::blocked_range<size_t>;
54 tbb::parallel_scan(RangeT(0, size), identity,
55 [&](
const RangeT &
r,
T sum,
bool is_final_scan)->
T {
57 for (
size_t i = r.begin(); i < r.end(); ++i) {
58 tmp = op(tmp, array[i]);
59 if (is_final_scan) array[i] = tmp;
62 },[&](
const T &
a,
const T &
b) {
return op(a,
b);}
66 for (
size_t i=1; i<
size; ++i) array[i] = op(array[i], array[i-1]);
70 template<
typename T,
typename OpT>
79 #endif // NANOVDB_PREFIX_SUM_H_HAS_BEEN_INCLUDED
GLboolean GLboolean GLboolean GLboolean a
T prefixSum(std::vector< T > &vec, bool threaded=true, OpT op=OpT())
Computes inclusive prefix sum of a vector.
Custom Range class that is compatible with the tbb::blocked_range classes.
GLboolean GLboolean GLboolean b
void inclusiveScan(T *array, size_t size, const T &identity, bool threaded, Op op)
An inclusive scan includes in[i] when computing out[i].