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:
Jiaming Yuan
2022-01-28 16:09:22 +08:00
committed by GitHub
parent 028bdc1740
commit 81210420c6
31 changed files with 195 additions and 211 deletions

View File

@@ -69,7 +69,8 @@ void GBTreeModel::SaveModel(Json* p_out) const {
out["gbtree_model_param"] = ToJson(param);
std::vector<Json> trees_json(trees.size());
common::ParallelFor(trees.size(), omp_get_max_threads(), [&](auto t) {
CHECK(ctx_);
common::ParallelFor(trees.size(), ctx_->Threads(), [&](auto t) {
auto const& tree = trees[t];
Json tree_json{Object()};
tree->SaveModel(&tree_json);
@@ -95,7 +96,8 @@ void GBTreeModel::LoadModel(Json const& in) {
auto const& trees_json = get<Array const>(in["trees"]);
trees.resize(trees_json.size());
common::ParallelFor(trees_json.size(), omp_get_max_threads(), [&](auto t) {
CHECK(ctx_);
common::ParallelFor(trees_json.size(), ctx_->Threads(), [&](auto t) {
auto tree_id = get<Integer>(trees_json[t]["id"]);
trees.at(tree_id).reset(new RegTree());
trees.at(tree_id)->LoadModel(trees_json[t]);