Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Manually track num_max_thread (#12380)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
azai91 authored and cjolivier01 committed Nov 15, 2018
1 parent 100a4aa commit 7541021
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/engine/openmp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,14 @@ void OpenMP::set_reserve_cores(int cores) {
CHECK_GE(cores, 0);
reserve_cores_ = cores;
#ifdef _OPENMP
if (reserve_cores_ >= omp_thread_max_) {
omp_set_num_threads(1);
} else {
omp_set_num_threads(omp_thread_max_ - reserve_cores_);
}
omp_thread_max_ = std::max(omp_thread_max_ - reserve_cores_, 1);
#endif
}

int OpenMP::GetRecommendedOMPThreadCount(bool exclude_reserved) const {
#ifdef _OPENMP
if (omp_num_threads_set_in_environment_) {
return omp_get_max_threads();
return omp_thread_max_;
}
if (enabled_) {
int thread_count = omp_get_max_threads();
Expand All @@ -101,10 +97,8 @@ int OpenMP::GetRecommendedOMPThreadCount(bool exclude_reserved) const {
}
return omp_thread_max_;
}
return 1;
#else
return 1;
#endif
return 1;
}

OpenMP *__init_omp__ = OpenMP::Get();
Expand Down

0 comments on commit 7541021

Please sign in to comment.