MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / ParallelForImpl

Method ParallelForImpl

oneflow/core/thread/thread_runtime.h:116–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114class OmpRuntime final : public RuntimeBase {
115 private:
116 void ParallelForImpl(int64_t begin, int64_t end, const CallableT& func, size_t num_threads,
117 size_t grain_size) override {
118 num_threads = std::min(DivUp((end - begin), grain_size), num_threads);
119#pragma omp parallel num_threads(num_threads)
120 {
121 int64_t omp_num_thread = omp_get_num_threads();
122 int64_t chunk_size = DivUp((end - begin), omp_num_thread);
123 int64_t omp_tid = omp_get_thread_num();
124 int64_t thread_begin_index = begin + omp_tid * chunk_size;
125 int64_t thread_end_index = std::min(end, chunk_size + thread_begin_index);
126
127 if (thread_begin_index < end) { SeqFor(thread_begin_index, thread_end_index, func); }
128 }
129 }
130};
131#endif
132

Callers

nothing calls this directly

Calls 2

DivUpFunction · 0.85
SeqForFunction · 0.85

Tested by

no test coverage detected