From 5c2d7a18c92b445ba897d4b0b4859508ae720883 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Tue, 15 Jun 2021 14:08:26 +0800 Subject: [PATCH] Parallel model dump for trees. (#7040) --- src/gbm/gbtree_model.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gbm/gbtree_model.h b/src/gbm/gbtree_model.h index 2d07ec198a79..c5e05c0157af 100644 --- a/src/gbm/gbtree_model.h +++ b/src/gbm/gbtree_model.h @@ -17,6 +17,8 @@ #include #include +#include "../common/threading_utils.h" + namespace xgboost { class Json; @@ -107,12 +109,12 @@ struct GBTreeModel : public Model { void SaveModel(Json* p_out) const override; void LoadModel(Json const& p_out) override; - std::vector DumpModel(const FeatureMap& fmap, bool with_stats, + std::vector DumpModel(const FeatureMap &fmap, bool with_stats, std::string format) const { - std::vector dump; - for (const auto & tree : trees) { - dump.push_back(tree->DumpModel(fmap, with_stats, format)); - } + std::vector dump(trees.size()); + common::ParallelFor(static_cast(trees.size()), [&](size_t i) { + dump[i] = trees[i]->DumpModel(fmap, with_stats, format); + }); return dump; } void CommitModel(std::vector >&& new_trees,