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>
40template<
typename T,
typename OpT = std::plus<T>>
41T
prefixSum(std::vector<T> &vec,
bool threaded =
true, OpT op = OpT());
45template<
typename T,
typename Op>
46void inclusiveScan(T *array,
size_t size,
const T &identity,
bool threaded, Op op)
48#ifndef 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]);
72template<
typename T,
typename OpT>
73T
prefixSum(std::vector<T> &vec,
bool threaded, OpT op)
81template<
typename T,
typename OpT = std::plus<T>>
82[[deprecated(
"Use nanovdb::util::prefixSum instead")]]
83T
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:73
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
Definition GridHandle.h:27
T prefixSum(std::vector< T > &vec, bool threaded=true, OpT op=OpT())
Definition PrefixSum.h:83