From cb538cb832dad2be7574efd53b303948432233ed Mon Sep 17 00:00:00 2001 From: fis Date: Mon, 10 Aug 2020 18:44:57 +0800 Subject: [PATCH] Slow it down. --- src/common/quantile.cc | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/src/common/quantile.cc b/src/common/quantile.cc index 889be6e9104f..fe55b7128eb8 100644 --- a/src/common/quantile.cc +++ b/src/common/quantile.cc @@ -62,13 +62,8 @@ void HostSketchContainer::PushRowPage(SparsePage const &page, // Data groups, used in ranking. std::vector const &group_ptr = info.group_ptr_; - size_t const num_groups = group_ptr.size() == 0 ? 0 : group_ptr.size() - 1; // Use group index for weights? - size_t group_ind = 0; auto batch = page.GetView(); - if (use_group_ind_) { - group_ind = this->SearchGroupIndFromRow(group_ptr, page.base_rowid); - } dmlc::OMPException exec; // Parallel over columns. Asumming the data is dense, each thread owns a set of // consecutive columns. @@ -76,23 +71,21 @@ void HostSketchContainer::PushRowPage(SparsePage const &page, auto const is_dense = info.num_nonzero_ == info.num_col_ * info.num_row_; auto thread_columns_ptr = LoadBalance(page, columns_size_, nthread); -#pragma omp parallel num_threads(nthread) firstprivate(group_ind) +#pragma omp parallel num_threads(nthread) { exec.Run([&]() { auto tid = static_cast(omp_get_thread_num()); auto const begin = thread_columns_ptr[tid]; auto const end = thread_columns_ptr[tid + 1]; + size_t group_ind = 0; // do not iterate if no columns are assigned to the thread if (begin < end && end <= ncol) { for (size_t i = 0; i < batch.Size(); ++i) { // NOLINT(*) size_t const ridx = page.base_rowid + i; SparsePage::Inst const inst = batch[i]; - if (use_group_ind_ && group_ptr[group_ind] == ridx && - // maximum equals to weights.size() - 1 - group_ind < num_groups - 1) { - // move to next group - group_ind++; + if (use_group_ind_) { + group_ind = this->SearchGroupIndFromRow(group_ptr, i + page.base_rowid); } size_t w_idx = use_group_ind_ ? group_ind : ridx; auto w = info.GetWeight(w_idx); @@ -102,22 +95,11 @@ void HostSketchContainer::PushRowPage(SparsePage const &page, sketches_[ii].Push(p_data[ii].fvalue, w); } } else { - auto p_end = inst.data() + inst.size(); - auto mid = static_cast( - (static_cast(begin) / static_cast(ncol)) * - static_cast(inst.size())); - if (mid < inst.size() / 2) { - for (auto it = p_data; it != p_end && it->index < end; ++it) { - if (it->index >= begin) { - sketches_[it->index].Push(it->fvalue, w); - } - } - } else { - for (auto it = p_end - 1; it >= p_data && it->index >= begin; - --it) { - if (it->index < end) { - sketches_[it->index].Push(it->fvalue, w); - } + auto p_inst = inst.data(); + for (size_t i = 0; i < inst.size(); ++i) { + auto const& entry = p_inst[i]; + if (entry.index >= begin && entry.index < end) { + sketches_[entry.index].Push(entry.fvalue, w); } } }