40inline void forEach(RangeT range,
const FuncT &func)
42 if (range.empty())
return;
44 tbb::parallel_for(range, func);
46 if (
const size_t threadCount = std::thread::hardware_concurrency()>>1) {
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();