From 58f62e830fd345f627c3404dd31c7727b99bc685 Mon Sep 17 00:00:00 2001 From: fis Date: Mon, 8 Nov 2021 18:00:25 +0800 Subject: [PATCH] Remove weird set thread. --- src/common/threading_utils.h | 3 +-- tests/cpp/tree/test_approx.cc | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/threading_utils.h b/src/common/threading_utils.h index fe0008444f5f..da8ddf3c2c6d 100644 --- a/src/common/threading_utils.h +++ b/src/common/threading_utils.h @@ -130,8 +130,7 @@ class BlockedSpace2d { template void ParallelFor2d(const BlockedSpace2d& space, int nthreads, Func func) { const size_t num_blocks_in_space = space.Size(); - nthreads = std::min(nthreads, omp_get_max_threads()); - nthreads = std::max(nthreads, 1); + CHECK_GE(nthreads, 1); dmlc::OMPException exc; #pragma omp parallel num_threads(nthreads) diff --git a/tests/cpp/tree/test_approx.cc b/tests/cpp/tree/test_approx.cc index b19e13af43eb..e598069234be 100644 --- a/tests/cpp/tree/test_approx.cc +++ b/tests/cpp/tree/test_approx.cc @@ -78,8 +78,9 @@ TEST(Approx, PredictionCache) { auto Xy = RandomDataGenerator{n_samples, n_features, 0}.GenerateDMatrix(true); { + omp_set_num_threads(1); GenericParameter ctx; - ctx.InitAllowUnknown(Args{}); + ctx.InitAllowUnknown(Args{{"nthread", "8"}}); std::unique_ptr approx{ TreeUpdater::Create("grow_global_approx_histmaker", &ctx, ObjInfo{ObjInfo::kRegression})}; RegTree tree;