inlinevoidPredLoopSpecalize(){ constint nthread = omp_get_max_threads(); InitThreadTemp(nthread, model.param.num_feature); for (bst_omp_uint i = 0; i < nsize - rest; i += K) { constint tid = omp_get_thread_num(); RegTree::FVec& feats = thread_temp[tid]; // thread_temp 为成员变量 // 省略其他逻辑 } }
inlinevoidInitThreadTemp(int nthread, int num_feature){ int prev_thread_temp_size = thread_temp.size(); if (prev_thread_temp_size < nthread) { thread_temp.resize(nthread, RegTree::FVec()); for (int i = prev_thread_temp_size; i < nthread; ++i) { thread_temp[i].Init(num_feature); } } }
修改后
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
inlinevoidPredLoopSpecalize(){ constint nthread = omp_get_max_threads(); std::vector<RegTree::FVec> local_thread_temp; // 改动点 int prev_thread_temp_size = local_thread_temp.size(); if (prev_thread_temp_size < nthread) { local_thread_temp.resize(nthread, RegTree::FVec()); for (int i = prev_thread_temp_size; i < nthread; ++i) { local_thread_temp[i].Init(model.param.num_feature); } } for (bst_omp_uint i = 0; i < nsize - rest; i += K) { constint tid = omp_get_thread_num(); RegTree::FVec& feats = local_thread_temp[tid]; // 改动点 // thread_temp 为成员变量 // 省略其他逻辑 } }