Skip to content

Commit 7541021

Browse files
azai91cjolivier01
authored andcommitted
Manually track num_max_thread (apache#12380)
* use cached version of get thread max * reserve core affects omp singleton * omp_thread_max_ updated in one line * remove enabled block * add brackets * re-add excluded reserved * add missing var * refactor macro
1 parent 100a4aa commit 7541021

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/engine/openmp.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,14 @@ void OpenMP::set_reserve_cores(int cores) {
7373
CHECK_GE(cores, 0);
7474
reserve_cores_ = cores;
7575
#ifdef _OPENMP
76-
if (reserve_cores_ >= omp_thread_max_) {
77-
omp_set_num_threads(1);
78-
} else {
79-
omp_set_num_threads(omp_thread_max_ - reserve_cores_);
80-
}
76+
omp_thread_max_ = std::max(omp_thread_max_ - reserve_cores_, 1);
8177
#endif
8278
}
8379

8480
int OpenMP::GetRecommendedOMPThreadCount(bool exclude_reserved) const {
8581
#ifdef _OPENMP
8682
if (omp_num_threads_set_in_environment_) {
87-
return omp_get_max_threads();
83+
return omp_thread_max_;
8884
}
8985
if (enabled_) {
9086
int thread_count = omp_get_max_threads();
@@ -101,10 +97,8 @@ int OpenMP::GetRecommendedOMPThreadCount(bool exclude_reserved) const {
10197
}
10298
return omp_thread_max_;
10399
}
104-
return 1;
105-
#else
106-
return 1;
107100
#endif
101+
return 1;
108102
}
109103

110104
OpenMP *__init_omp__ = OpenMP::Get();

0 commit comments

Comments
 (0)