Skip to content

Commit

Permalink
Parallel model dump for trees. (#7040)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jun 15, 2021
1 parent 2567404 commit 5c2d7a1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/gbm/gbtree_model.h
Expand Up @@ -17,6 +17,8 @@
#include <string>
#include <vector>

#include "../common/threading_utils.h"

namespace xgboost {

class Json;
Expand Down Expand Up @@ -107,12 +109,12 @@ struct GBTreeModel : public Model {
void SaveModel(Json* p_out) const override;
void LoadModel(Json const& p_out) override;

std::vector<std::string> DumpModel(const FeatureMap& fmap, bool with_stats,
std::vector<std::string> DumpModel(const FeatureMap &fmap, bool with_stats,
std::string format) const {
std::vector<std::string> dump;
for (const auto & tree : trees) {
dump.push_back(tree->DumpModel(fmap, with_stats, format));
}
std::vector<std::string> dump(trees.size());
common::ParallelFor(static_cast<omp_ulong>(trees.size()), [&](size_t i) {
dump[i] = trees[i]->DumpModel(fmap, with_stats, format);
});
return dump;
}
void CommitModel(std::vector<std::unique_ptr<RegTree> >&& new_trees,
Expand Down

0 comments on commit 5c2d7a1

Please sign in to comment.