42inline T
reduce(RangeT range,
const T& identity,
const FuncT &func,
const JoinT &join)
44 if (range.empty())
return identity;
46 return tbb::parallel_reduce(range, identity, func, join);
48 if (
const size_t threadCount = std::thread::hardware_concurrency()>>1) {
49 std::vector<RangeT> rangePool{ range };
50 while(rangePool.size() < threadCount) {
51 const size_t oldSize = rangePool.size();
52 for (
size_t i = 0; i < oldSize && rangePool.size() < threadCount; ++i) {
53 auto &r = rangePool[i];
54 if (r.is_divisible()) rangePool.push_back(RangeT(r,
Split()));
56 if (rangePool.size() == oldSize)
break;
58 std::vector< std::future<T> > futurePool;
59 for (
auto &r : rangePool) {
60 auto task = std::async(std::launch::async, [&](){
return func(r, identity);});
61 futurePool.push_back( std::move(task) );
64 for (
auto &f : futurePool) {
65 result = join(result, f.get());
69 return static_cast<T
>(func(range, identity));
Convert a base-pointer to an openvdb grid, denoted srcGrid, to a nanovdb grid of the same type,...
Definition NanoVDB.h:247