18 #ifndef NANOVDB_UTIL_PREFIX_SUM_H_HAS_BEEN_INCLUDED 19 #define NANOVDB_UTIL_PREFIX_SUM_H_HAS_BEEN_INCLUDED 25 #ifdef NANOVDB_USE_TBB 26 #include <tbb/parallel_scan.h> 40 template<
typename T,
typename OpT = std::plus<T>>
45 template<
typename T,
typename Op>
48 #ifndef NANOVDB_USE_TBB 54 #ifdef NANOVDB_USE_TBB 55 using RangeT = tbb::blocked_range<size_t>;
56 tbb::parallel_scan(RangeT(0, size), identity,
57 [&](
const RangeT &r, T sum,
bool is_final_scan)->T {
59 for (
size_t i = r.begin(); i < r.end(); ++i) {
60 tmp =
op(tmp, array[i]);
61 if (is_final_scan) array[i] = tmp;
64 },[&](
const T &a,
const T &b) {
return op(a, b);}
68 for (
size_t i=1; i<size; ++i) array[i] =
op(array[i], array[i-1]);
72 template<
typename T,
typename OpT>
81 template<
typename T,
typename OpT = std::plus<T>>
82 [[deprecated(
"Use nanovdb::util::prefixSum instead")]]
85 return util::prefixSum<T, OpT>(vec,
threaded,
op);
90 #endif // NANOVDB_UTIL_PREFIX_SUM_H_HAS_BEEN_INCLUDED
Definition: GridHandle.h:27
Custom Range class that is compatible with the tbb::blocked_range classes.
void inclusiveScan(T *array, size_t size, const T &identity, bool threaded, Op op)
An inclusive scan includes in[i] when computing out[i].
Definition: PrefixSum.h:46
T prefixSum(std::vector< T > &vec, bool threaded=true, OpT op=OpT())
Computes inclusive prefix sum of a vector.
Definition: PrefixSum.h:73