Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid omp reduction in rank metric. #7349

Merged
merged 2 commits into from
Oct 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/metric/rank_metric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
const auto &labels = info.labels_.ConstHostVector();
const auto &h_preds = preds.ConstHostVector();

dmlc::OMPException exc;
#pragma omp parallel reduction(+:sum_metric)
#pragma omp parallel num_threads(tparam_->Threads())
{
exc.Run([&]() {
// each thread takes a local rec
PredIndPairContainer rec;
#pragma omp for schedule(static)
#pragma omp for schedule(static)
for (bst_omp_uint k = 0; k < ngroups; ++k) {
exc.Run([&]() {
rec.clear();
for (unsigned j = gptr[k]; j < gptr[k + 1]; ++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();
}

Expand Down