GBTree::Predict performance fix: removed excess thread_temp initialization

This commit is contained in:
yoori 2015-10-20 00:06:00 +04:00
parent fd8439ffbc
commit c0853967d5

View File

@ -138,10 +138,13 @@ class GBTree : public IGradBooster {
{ {
nthread = omp_get_num_threads(); nthread = omp_get_num_threads();
} }
int prev_thread_temp_size = thread_temp.size();
if(prev_thread_temp_size < nthread) {
thread_temp.resize(nthread, tree::RegTree::FVec()); thread_temp.resize(nthread, tree::RegTree::FVec());
for (int i = 0; i < nthread; ++i) { for (int i = prev_thread_temp_size; i < nthread; ++i) {
thread_temp[i].Init(mparam.num_feature); thread_temp[i].Init(mparam.num_feature);
} }
}
std::vector<float> &preds = *out_preds; std::vector<float> &preds = *out_preds;
const size_t stride = info.num_row * mparam.num_output_group; const size_t stride = info.num_row * mparam.num_output_group;
preds.resize(stride * (mparam.size_leaf_vector+1)); preds.resize(stride * (mparam.size_leaf_vector+1));
@ -194,10 +197,13 @@ class GBTree : public IGradBooster {
{ {
nthread = omp_get_num_threads(); nthread = omp_get_num_threads();
} }
int prev_thread_temp_size = thread_temp.size();
if(prev_thread_temp_size < nthread) {
thread_temp.resize(nthread, tree::RegTree::FVec()); thread_temp.resize(nthread, tree::RegTree::FVec());
for (int i = 0; i < nthread; ++i) { for (int i = prev_thread_temp_size; i < nthread; ++i) {
thread_temp[i].Init(mparam.num_feature); thread_temp[i].Init(mparam.num_feature);
} }
}
this->PredPath(p_fmat, info, out_preds, ntree_limit); this->PredPath(p_fmat, info, out_preds, ntree_limit);
} }
virtual std::vector<std::string> DumpModel(const utils::FeatMap& fmap, int option) { virtual std::vector<std::string> DumpModel(const utils::FeatMap& fmap, int option) {