18#ifndef NANOVDB_UTIL_PREFIX_SUM_H_HAS_BEEN_INCLUDED
19#define NANOVDB_UTIL_PREFIX_SUM_H_HAS_BEEN_INCLUDED
26#include <tbb/parallel_scan.h>
41template<
typename T,
typename OpT = std::plus<T>>
42T
prefixSum(std::vector<T> &vec,
bool threaded =
true, OpT op = OpT());
46template<
typename T,
typename Op>
47void inclusiveScan(T *array,
size_t size,
const T &identity,
bool threaded, Op op)
49#ifndef NANOVDB_USE_TBB
56 using RangeT = tbb::blocked_range<size_t>;
57 tbb::parallel_scan(RangeT(0, size), identity,
58 [&](
const RangeT &r, T sum,
bool is_final_scan)->T {
60 for (
size_t i = r.begin(); i < r.end(); ++i) {
61 tmp = op(tmp, array[i]);
62 if (is_final_scan) array[i] = tmp;
65 },[&](
const T &a,
const T &b) {
return op(a, b);}
69 for (
size_t i=1; i<size; ++i) array[i] = op(array[i], array[i-1]);
73template<
typename T,
typename OpT>
74T
prefixSum(std::vector<T> &vec,
bool threaded, OpT op)
82template<
typename T,
typename OpT = std::plus<T>>
83[[deprecated(
"Use nanovdb::util::prefixSum instead")]]
84T
prefixSum(std::vector<T> &vec,
bool threaded =
true, OpT op = OpT())
Custom Range class that is compatible with the tbb::blocked_range classes.
T prefixSum(std::vector< T > &vec, bool threaded=true, OpT op=OpT())
Computes inclusive prefix sum of a vector.
Definition PrefixSum.h:74
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:47
Definition GridHandle.h:27
T prefixSum(std::vector< T > &vec, bool threaded=true, OpT op=OpT())
Definition PrefixSum.h:84