Skip to content

Commit

Permalink
Slow it down.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Aug 10, 2020
1 parent cdd78b3 commit d7a75d7
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions src/common/quantile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,30 @@ void HostSketchContainer::PushRowPage(SparsePage const &page,

// Data groups, used in ranking.
std::vector<bst_uint> 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.
auto const ncol = static_cast<uint32_t>(info.num_col_);
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<uint32_t>(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);
Expand All @@ -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<size_t>(
(static_cast<double>(begin) / static_cast<double>(ncol)) *
static_cast<double>(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);
}
}
}
Expand Down

0 comments on commit d7a75d7

Please sign in to comment.