28 static unsigned int NumThreads(
void) {
return tbb::this_task_arena::max_concurrency(); }
31 template <
typename... Functions>
32 static void ParallelSections(Functions&&... funcs)
34 tbb::parallel_invoke(std::forward<Functions>(funcs)...);
38 template <
typename Function>
39 static void ParallelFor(
size_t begin,
size_t end, Function&& func)
44 for (
size_t i = begin; i < end; ++i) {
45 func(thread_index, i);
48 static const bool NeedsThreadIndex =
49 std::is_convertible_v<Function, std::function<void(
unsigned int,
size_t)>>;
52 tbb::blocked_range<size_t>(begin, end),
53 [&](
const tbb::blocked_range<size_t>& r) {
54 int thread_index = tbb::this_task_arena::current_thread_index();
56 for (
size_t i = r.begin(); i < r.end(); ++i) {
57 if constexpr (NeedsThreadIndex)
58 func(thread_index, i);