Skip to content

Commit

Permalink
fix invalid read detected by valgrind (#3526)
Browse files Browse the repository at this point in the history
Co-authored-by: StrikerRUS <[email protected]>
  • Loading branch information
guolinke and StrikerRUS authored Nov 7, 2020
1 parent bee732a commit da6c6ea
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/treelearner/leaf_splits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ namespace LightGBM {
class LeafSplits {
public:
LeafSplits(data_size_t num_data, const Config* config)
:config_(config), num_data_in_leaf_(num_data), num_data_(num_data),
: deterministic_(false),
num_data_in_leaf_(num_data),
num_data_(num_data),
data_indices_(nullptr), weight_(0) {
if (config != nullptr) {
deterministic_ = config->deterministic;
}
}
void ResetNumData(data_size_t num_data) {
num_data_ = num_data;
Expand Down Expand Up @@ -71,7 +76,7 @@ class LeafSplits {
data_indices_ = nullptr;
double tmp_sum_gradients = 0.0f;
double tmp_sum_hessians = 0.0f;
#pragma omp parallel for schedule(static, 512) reduction(+:tmp_sum_gradients, tmp_sum_hessians) if (num_data_in_leaf_ >= 1024 && !config_->deterministic)
#pragma omp parallel for schedule(static, 512) reduction(+:tmp_sum_gradients, tmp_sum_hessians) if (num_data_in_leaf_ >= 1024 && !deterministic_)
for (data_size_t i = 0; i < num_data_in_leaf_; ++i) {
tmp_sum_gradients += gradients[i];
tmp_sum_hessians += hessians[i];
Expand All @@ -93,7 +98,7 @@ class LeafSplits {
data_indices_ = data_partition->GetIndexOnLeaf(leaf, &num_data_in_leaf_);
double tmp_sum_gradients = 0.0f;
double tmp_sum_hessians = 0.0f;
#pragma omp parallel for schedule(static, 512) reduction(+:tmp_sum_gradients, tmp_sum_hessians) if (num_data_in_leaf_ >= 1024 && !config_->deterministic)
#pragma omp parallel for schedule(static, 512) reduction(+:tmp_sum_gradients, tmp_sum_hessians) if (num_data_in_leaf_ >= 1024 && !deterministic_)
for (data_size_t i = 0; i < num_data_in_leaf_; ++i) {
const data_size_t idx = data_indices_[i];
tmp_sum_gradients += gradients[idx];
Expand Down Expand Up @@ -146,7 +151,7 @@ class LeafSplits {


private:
const Config* config_;
bool deterministic_;
/*! \brief current leaf index */
int leaf_index_;
/*! \brief number of data on current leaf */
Expand Down

0 comments on commit da6c6ea

Please sign in to comment.