From c0853967d5cb04bbf8e6ceebe7db32d01725cb5f Mon Sep 17 00:00:00 2001 From: yoori Date: Tue, 20 Oct 2015 00:06:00 +0400 Subject: [PATCH] GBTree::Predict performance fix: removed excess thread_temp initialization --- src/gbm/gbtree-inl.hpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/gbm/gbtree-inl.hpp b/src/gbm/gbtree-inl.hpp index 9335ef8e7..d6bbcc6d1 100644 --- a/src/gbm/gbtree-inl.hpp +++ b/src/gbm/gbtree-inl.hpp @@ -138,9 +138,12 @@ class GBTree : public IGradBooster { { nthread = omp_get_num_threads(); } - thread_temp.resize(nthread, tree::RegTree::FVec()); - for (int i = 0; i < nthread; ++i) { - thread_temp[i].Init(mparam.num_feature); + int prev_thread_temp_size = thread_temp.size(); + if(prev_thread_temp_size < nthread) { + thread_temp.resize(nthread, tree::RegTree::FVec()); + for (int i = prev_thread_temp_size; i < nthread; ++i) { + thread_temp[i].Init(mparam.num_feature); + } } std::vector &preds = *out_preds; const size_t stride = info.num_row * mparam.num_output_group; @@ -194,9 +197,12 @@ class GBTree : public IGradBooster { { nthread = omp_get_num_threads(); } - thread_temp.resize(nthread, tree::RegTree::FVec()); - for (int i = 0; i < nthread; ++i) { - thread_temp[i].Init(mparam.num_feature); + int prev_thread_temp_size = thread_temp.size(); + if(prev_thread_temp_size < nthread) { + thread_temp.resize(nthread, tree::RegTree::FVec()); + for (int i = prev_thread_temp_size; i < nthread; ++i) { + thread_temp[i].Init(mparam.num_feature); + } } this->PredPath(p_fmat, info, out_preds, ntree_limit); }