Avoid omp reduction in rank metric. (#7349)
This commit is contained in:
parent
e36b066344
commit
fd61c61071
@ -192,28 +192,32 @@ struct EvalRank : public Metric, public EvalRankConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK(tparam_);
|
||||||
|
std::vector<double> sum_tloc(tparam_->Threads(), 0.0);
|
||||||
|
|
||||||
if (!rank_gpu_ || tparam_->gpu_id < 0) {
|
if (!rank_gpu_ || tparam_->gpu_id < 0) {
|
||||||
const auto &labels = info.labels_.ConstHostVector();
|
const auto &labels = info.labels_.ConstHostVector();
|
||||||
const auto &h_preds = preds.ConstHostVector();
|
const auto &h_preds = preds.ConstHostVector();
|
||||||
|
|
||||||
dmlc::OMPException exc;
|
dmlc::OMPException exc;
|
||||||
#pragma omp parallel reduction(+:sum_metric)
|
#pragma omp parallel num_threads(tparam_->Threads())
|
||||||
{
|
{
|
||||||
exc.Run([&]() {
|
exc.Run([&]() {
|
||||||
// each thread takes a local rec
|
// each thread takes a local rec
|
||||||
PredIndPairContainer rec;
|
PredIndPairContainer rec;
|
||||||
#pragma omp for schedule(static)
|
#pragma omp for schedule(static)
|
||||||
for (bst_omp_uint k = 0; k < ngroups; ++k) {
|
for (bst_omp_uint k = 0; k < ngroups; ++k) {
|
||||||
exc.Run([&]() {
|
exc.Run([&]() {
|
||||||
rec.clear();
|
rec.clear();
|
||||||
for (unsigned j = gptr[k]; j < gptr[k + 1]; ++j) {
|
for (unsigned j = gptr[k]; j < gptr[k + 1]; ++j) {
|
||||||
rec.emplace_back(h_preds[j], static_cast<int>(labels[j]));
|
rec.emplace_back(h_preds[j], static_cast<int>(labels[j]));
|
||||||
}
|
}
|
||||||
sum_metric += this->EvalGroup(&rec);
|
sum_tloc[omp_get_thread_num()] += this->EvalGroup(&rec);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
sum_metric = std::accumulate(sum_tloc.cbegin(), sum_tloc.cend(), 0.0);
|
||||||
exc.Rethrow();
|
exc.Rethrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user