| 71 | class OfRuntime final : public RuntimeBase { |
| 72 | private: |
| 73 | void ParallelForImpl(int64_t begin, int64_t end, const CallableT& func, size_t num_threads, |
| 74 | size_t grain_size) override { |
| 75 | if (unlikely(pthread_fork::IsForkedSubProcess()) || Singleton<ThreadPool>::Get() == nullptr) { |
| 76 | return SeqFor(begin, end, func); |
| 77 | } |
| 78 | const size_t num_elements = end - begin; |
| 79 | num_threads = std::min(num_elements, num_threads); |
| 80 | BalancedSplitter bs(num_elements, num_threads); |
| 81 | BlockingCounter bc(num_threads); |
| 82 | |
| 83 | FOR_RANGE(size_t, range_id, 0, num_threads) { |
| 84 | Singleton<ThreadPool>::Get()->AddWork([&bc, &bs, range_id, func] { |
| 85 | const size_t begin_ = bs.At(range_id).begin(); |
| 86 | const size_t end_ = bs.At(range_id).end(); |
| 87 | SeqFor(begin_, end_, func); |
| 88 | bc.Decrease(); |
| 89 | }); |
| 90 | } |
| 91 | // buzy loop wait. |
| 92 | bc.WaitForeverUntilCntEqualZero(); |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | #if WITH_TBB |
nothing calls this directly
no test coverage detected