14 #ifndef NANOVDB_FOREACH_H_HAS_BEEN_INCLUDED
15 #define NANOVDB_FOREACH_H_HAS_BEEN_INCLUDED
19 #ifdef NANOVDB_USE_TBB
20 #include <tbb/parallel_for.h>
39 template <
typename RangeT,
typename FuncT>
42 if (range.empty())
return;
43 #ifdef NANOVDB_USE_TBB
45 #else// naive and likely slow alternative based on std::thread
47 std::vector<RangeT> rangePool{ range };
48 while(rangePool.size() < threadCount) {
49 const size_t oldSize = rangePool.size();
50 for (
size_t i = 0; i < oldSize && rangePool.size() < threadCount; ++i) {
51 auto &
r = rangePool[i];
52 if (
r.is_divisible()) rangePool.push_back(RangeT(
r,
Split()));
54 if (rangePool.size() == oldSize)
break;
56 std::vector<std::thread> threadPool;
57 for (
auto &
r : rangePool) threadPool.emplace_back(func,
r);
58 for (
auto &
t : threadPool)
t.join();
66 template <
typename FuncT>
73 template <
template<
typename...>
class ContainerT,
typename...
T,
typename FuncT>
80 template <
template<
typename...>
class ContainerT,
typename...
T,
typename FuncT>
81 inline void forEach(
const ContainerT<T...> &
c,
size_t grainSize,
const FuncT&
func)
88 #endif // NANOVDB_FOREACH_H_HAS_BEEN_INCLUDED
OIIO_API unsigned int hardware_concurrency()
void parallel_for(int64_t start, int64_t end, std::function< void(int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
void forEach(RangeT range, const FuncT &func)
simple wrapper for tbb::parallel_for with a naive std fallback
Range< 1, size_t > Range1D
Custom Range class that is compatible with the tbb::blocked_range classes.
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.