Unify thread configuration. (#6186)

This commit is contained in:
Jiaming Yuan
2020-10-19 16:05:42 +08:00
committed by GitHub
parent 7f6ed5780c
commit ddf37cca30
5 changed files with 39 additions and 12 deletions

View File

@@ -88,6 +88,22 @@ TEST(ParallelFor2dNonUniform, Test) {
omp_set_num_threads(old);
}
#if defined(_OPENMP)
TEST(OmpSetNumThreads, Basic) {
auto nthreads = 2;
auto orgi = OmpSetNumThreads(&nthreads);
ASSERT_EQ(omp_get_max_threads(), 2);
nthreads = 0;
OmpSetNumThreads(&nthreads);
ASSERT_EQ(omp_get_max_threads(), omp_get_num_procs());
nthreads = 1;
OmpSetNumThreads(&nthreads);
nthreads = 0;
OmpSetNumThreads(&nthreads);
ASSERT_EQ(omp_get_max_threads(), omp_get_num_procs());
omp_set_num_threads(orgi);
}
#endif // defined(_OPENMP)
} // namespace common
} // namespace xgboost