Return single thread from context when called inside omp region. (#8693)

This commit is contained in:
Jiaming Yuan
2023-01-18 09:23:37 +08:00
committed by GitHub
parent 31b9cbab3d
commit 4416452f94
2 changed files with 37 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2014-2022 by XGBoost Contributors
* Copyright 2014-2023 by XGBoost Contributors
*
* \brief Context object used for controlling runtime parameters.
*/
@@ -53,6 +53,9 @@ void Context::ConfigureGpuId(bool require_gpu) {
}
std::int32_t Context::Threads() const {
if (omp_in_parallel()) {
return 1;
}
auto n_threads = common::OmpGetNumThreads(nthread);
if (cfs_cpu_count_ > 0) {
n_threads = std::min(n_threads, cfs_cpu_count_);