Remove omp_get_max_threads (#7608)
This is the one last PR for removing omp global variable. * Add context object to the `DMatrix`. This bridges `DMatrix` with https://github.com/dmlc/xgboost/issues/7308 . * Require context to be available at the construction time of booster. * Add `n_threads` support for R csc DMatrix constructor. * Remove `omp_get_max_threads` in R glue code. * Remove threading utilities that rely on omp global variable.
This commit is contained in:
@@ -14,15 +14,7 @@
|
||||
namespace xgboost {
|
||||
namespace common {
|
||||
|
||||
size_t GetNThreads() {
|
||||
size_t nthreads;
|
||||
#pragma omp parallel
|
||||
{
|
||||
#pragma omp master
|
||||
nthreads = omp_get_num_threads();
|
||||
}
|
||||
return nthreads;
|
||||
}
|
||||
size_t GetNThreads() { return common::OmpGetNumThreads(0); }
|
||||
|
||||
template <typename GradientSumT>
|
||||
void ParallelGHistBuilderReset() {
|
||||
|
||||
@@ -590,10 +590,8 @@ TEST(Json, DISABLED_RoundTripExhaustive) {
|
||||
}
|
||||
};
|
||||
int64_t int32_max = static_cast<int64_t>(std::numeric_limits<uint32_t>::max());
|
||||
#pragma omp parallel for schedule(static)
|
||||
for (int64_t i = 0; i <= int32_max; ++i) {
|
||||
test(static_cast<uint32_t>(i));
|
||||
}
|
||||
GenericParameter ctx;
|
||||
common::ParallelFor(int32_max, ctx.Threads(), [&](auto i) { test(static_cast<uint32_t>(i)); });
|
||||
}
|
||||
|
||||
TEST(Json, TypedArray) {
|
||||
|
||||
@@ -88,22 +88,5 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user