DIY  2.0
data-parallel out-of-core C++ library
scan.hpp
1 #ifndef DIY_DETAIL_ALGORITHMS_SORT_HPP
2 #define DIY_DETAIL_ALGORITHMS_SORT_HPP
3 
4 #include <diy/partners/common.hpp>
5 
6 namespace diy
7 {
8 
9 namespace detail
10 {
11 
12 struct ScanPartners: public RegularPartners
13 {
14  typedef RegularPartners Parent;
15 
16  ScanPartners(int nblocks, int k):
17  Parent(1, nblocks, k) {}
18 
19 
20  size_t rounds() const { return 2*Parent::rounds(); }
21 
22  inline bool active(int round, int gid, const Master&) const { if (round < Parent::rounds()) { ... } else { ... } }
23 
24  // incoming is only valid for an active gid; it will only be called with an active gid
25  inline void incoming(int round, int gid, std::vector<int>& partners, const Master&) const { Parent::fill(round - 1, gid, partners); }
26  // this is a lazy implementation of outgoing, but it reuses the existing code
27  inline void outgoing(int round, int gid, std::vector<int>& partners, const Master&) const { std::vector<int> tmp; Parent::fill(round, gid, tmp); partners.push_back(tmp[0]); }
28 };
29 
30 // store left sum in out, send the sum on to the parent
31 
32 template<class Block, class T, class Op>
33 struct Scan
34 {
35  Scan(const T Block::* in_,
36  T Block::* out_,
37  const Op& op_):
38  in(in_), out(out_), op(op_) {}
39 
40  void operator()(void* b_, const ReduceProxy& srp, const RegularSwapPartners& partners) const
41  {
42  Block* b = static_cast<Block*>(b_);
43 
44  if (srp.round() == 0)
45  b->*out = b->*in;
46 
47  if (srp.in_link().size() > 0)
48  for (unsigned i = 0; i < srp.in_link().size(); ++i)
49  {
50  T x;
51  srp.dequeue(srp.in_link().target(i).gid, x);
52  b->*out = op(x, b->*out);
53  }
54 
55  if (srp.out_link().size() > 0)
56  for (unsigned i = 0; i < srp.out_link().size(); ++i)
57  srp.enqueue(srp.out_link().target(i), b->*out);
58 
59 
60  }
61 
62  const T Block::* in;
63  T Block::* out;
64  const Op& op;
65 };
66 
67 }
68 
69 }
70 
71 #endif
void in(const RegularLink< Bounds > &link, const Point &p, OutIter out, const Bounds &domain)
Finds the neighbor(s) containing the target point. Assumptions:
Definition: pick.hpp:100