[blocking] fix parallel eval_split of hist updater (#4851)

* Don't call rabit functions inside parallel loop.
This commit is contained in:
Xu Xiao 2019-09-13 21:35:03 +08:00 committed by Jiaming Yuan
parent 6a5e805886
commit c89bcc4de5

View File

@ -1076,6 +1076,8 @@ void QuantileHistMaker::Builder::EvaluateSplitsBatch(
}
}
// rabit::IsDistributed is not thread-safe
auto isDistributed = rabit::IsDistributed();
// partial results
std::vector<std::pair<SplitEntry, SplitEntry>> splits(tasks.size());
// parallel enumeration
@ -1088,16 +1090,16 @@ void QuantileHistMaker::Builder::EvaluateSplitsBatch(
const int32_t sibling_nid = nodes[node_idx].sibling_nid;
const int32_t parent_nid = nodes[node_idx].parent_nid;
common::GradStatHist::GradType* hist_data =
reinterpret_cast<common::GradStatHist::GradType*>(hist_[nid].data());
common::GradStatHist::GradType* sibling_hist_data = sibling_nid > -1 ?
// reduce needed part of a hist here to have it in cache before enumeration
if (!isDistributed) {
auto hist_data = reinterpret_cast<common::GradStatHist::GradType *>(hist_[nid].data());
auto sibling_hist_data = sibling_nid > -1 ?
reinterpret_cast<common::GradStatHist::GradType *>(
hist_[sibling_nid].data()) : nullptr;
common::GradStatHist::GradType* parent_hist_data = sibling_nid > -1 ?
reinterpret_cast<common::GradStatHist::GradType*>(hist_[parent_nid].data()) : nullptr;
auto parent_hist_data = sibling_nid > -1 ?
reinterpret_cast<common::GradStatHist::GradType *>(
hist_[parent_nid].data()) : nullptr;
// reduce needed part of a hist here to have it in cache before enumeration
if (!rabit::IsDistributed()) {
const std::vector<uint32_t>& cut_ptr = gmat.cut.Ptrs();
const size_t ibegin = 2 * cut_ptr[fid];
const size_t iend = 2 * cut_ptr[fid + 1];