static void dequeue_values(std::vector<T>& v, const ReduceProxy& rp, bool skip_self = true) { auto log = get_logger(); int k_in = rp.in_link().size(); log->trace("dequeue_values(): gid={}, round={}; v.size()={}", rp.gid(), rp.round(), v.size()); if (detail::is_default< Serialization<T> >::value) { // add up sizes size_t sz = 0; size_t end = v.size(); for (int i = 0; i < k_in; ++i) { log->trace(" incoming size from {}: {}", rp.in_link().target(i).gid, sz); if (skip_self && rp.in_link().target(i).gid == rp.gid()) continue; MemoryBuffer& in = rp.incoming(rp.in_link().target(i).gid); sz += in.size() / sizeof(T); } log->trace(" incoming size: {}", sz); v.resize(end + sz); for (int i = 0; i < k_in; ++i) { if (skip_self && rp.in_link().target(i).gid == rp.gid()) continue; MemoryBuffer& in = rp.incoming(rp.in_link().target(i).gid); size_t sz = in.size() / sizeof(T); T* bg = (T*) &in.buffer[0]; std::copy(bg, bg + sz, &v[end]); end += sz; } } else { for (int i = 0; i < k_in; ++i) { if (skip_self && rp.in_link().target(i).gid == rp.gid()) continue; MemoryBuffer& in = rp.incoming(rp.in_link().target(i).gid); while(in) { T x; diy::load(in, x); v.emplace_back(std::move(x)); } } } log->trace(" v.size()={}", v.size()); }
void operator()(Block* b, const ReduceProxy& rp) const { if (rp.round() == 0) { // enqueue values to the correct locations for (size_t i = 0; i < (b->*values).size(); ++i) { int to = std::lower_bound((b->*samples).begin(), (b->*samples).end(), (b->*values)[i], cmp) - (b->*samples).begin(); rp.enqueue(rp.out_link().target(to), (b->*values)[i]); } (b->*values).clear(); } else { dequeue_values((b->*values), rp, false); std::sort((b->*values).begin(), (b->*values).end(), cmp); } }