| 97 | class TbbRuntime final : public RuntimeBase { |
| 98 | private: |
| 99 | void ParallelForImpl(int64_t begin, int64_t end, const CallableT& func, size_t num_threads, |
| 100 | size_t grain_size) override { |
| 101 | tbb::global_control global_thread_limit(tbb::global_control::max_allowed_parallelism, |
| 102 | num_threads); |
| 103 | const size_t chunk_size = std::max(DivUp((end - begin), num_threads), grain_size); |
| 104 | |
| 105 | tbb::parallel_for( |
| 106 | tbb::blocked_range<int64_t>(begin, end, chunk_size), |
| 107 | [&func](const tbb::blocked_range<int64_t>& r) { SeqFor(r.begin(), r.end(), func); }, |
| 108 | tbb::static_partitioner{}); |
| 109 | } |
| 110 | }; |
| 111 | #endif |
| 112 | |