Medial Code Documentation
Loading...
Searching...
No Matches
threading.h
1#ifndef LIGHTGBM_UTILS_THREADING_H_
2#define LIGHTGBM_UTILS_THREADING_H_
3
4#include <LightGBM/utils/openmp_wrapper.h>
5
6#include <vector>
7#include <functional>
8
9namespace LightGBM {
10
11class Threading {
12public:
13 template<typename INDEX_T>
14 static inline void For(INDEX_T start, INDEX_T end, const std::function<void(int, INDEX_T, INDEX_T)>& inner_fun) {
15 int num_threads = 1;
16 #pragma omp parallel
17 #pragma omp master
18 {
19 num_threads = omp_get_num_threads();
20 }
21 INDEX_T num_inner = (end - start + num_threads - 1) / num_threads;
22 if (num_inner <= 0) { num_inner = 1; }
23 OMP_INIT_EX();
24 #pragma omp parallel for schedule(static, 1)
25 for (int i = 0; i < num_threads; ++i) {
26 OMP_LOOP_EX_BEGIN();
27 INDEX_T inner_start = start + num_inner * i;
28 INDEX_T inner_end = inner_start + num_inner;
29 if (inner_end > end) { inner_end = end; }
30 if (inner_start < end) {
31 inner_fun(i, inner_start, inner_end);
32 }
33 OMP_LOOP_EX_END();
34 }
35 OMP_THROW_EX();
36 }
37};
38
39} // namespace LightGBM
40
41#endif // LightGBM_UTILS_THREADING_H_
Definition threading.h:11
desc and descl2 fields must be written in reStructuredText format
Definition application.h:10