MCPcopy Create free account
hub / github.com/dmlc/xgboost / OmpGetNumThreads

Function OmpGetNumThreads

src/common/threading_utils.cc:108–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108std::int32_t OmpGetNumThreads(std::int32_t n_threads) noexcept(true) {
109 // Don't use parallel if we are in a parallel region.
110 if (omp_in_parallel()) {
111 return 1;
112 }
113 // Honor the openmp thread limit, which can be set via environment variable.
114 auto max_n_threads = std::min({omp_get_num_procs(), omp_get_max_threads(), OmpGetThreadLimit()});
115 // If -1 or 0 is specified by the user, we default to maximum number of threads.
116 if (n_threads <= 0) {
117 n_threads = max_n_threads;
118 }
119 n_threads = std::min(n_threads, max_n_threads);
120 n_threads = std::max(n_threads, 1);
121 return n_threads;
122}
123
124void NameThread(std::thread* t, StringView name) {
125#if defined(__linux__) && (!defined(__ANDROID__) || __ANDROID_API__ >= 26)

Callers 3

ThreadsMethod · 0.85
XGDMatrixCreateFromCSCFunction · 0.85
TESTFunction · 0.85

Calls 1

OmpGetThreadLimitFunction · 0.85

Tested by 1

TESTFunction · 0.68