Honor CPU counts from CFS. (#7654)

This commit is contained in:
Jiaming Yuan
2022-02-21 03:13:26 +08:00
committed by GitHub
parent 671b3c8d8e
commit 549f3bd781
5 changed files with 71 additions and 6 deletions

View File

@@ -1,7 +1,5 @@
/*!
* Copyright 2015-2019 by Contributors
* \file common.h
* \brief Threading utilities
* Copyright 2019-2022 by XGBoost Contributors
*/
#ifndef XGBOOST_COMMON_THREADING_UTILS_H_
#define XGBOOST_COMMON_THREADING_UTILS_H_
@@ -238,6 +236,8 @@ inline int32_t OmpGetThreadLimit() {
return limit;
}
int32_t GetCfsCPUCount() noexcept;
inline int32_t OmpGetNumThreads(int32_t n_threads) {
if (n_threads <= 0) {
n_threads = std::min(omp_get_num_procs(), omp_get_max_threads());