DIY  3.0
data-parallel out-of-core C++ library
 All Classes Namespaces Functions Typedefs Groups Pages
merge.hpp
1 #ifndef DIY_PARTNERS_MERGE_HPP
2 #define DIY_PARTNERS_MERGE_HPP
3 
4 #include "common.hpp"
5 
6 namespace diy
7 {
8 
9 class Master;
10 
17 {
18  typedef RegularPartners Parent;
19 
20  // contiguous parameter indicates whether to match partners contiguously or in a round-robin fashion;
21  // contiguous is useful when data needs to be united;
22  // round-robin is useful for vector-"halving"
23  template<class Decomposer>
24  RegularMergePartners(const Decomposer& decomposer,
25  int k,
26  bool contiguous = true
27  ):
28  Parent(decomposer, k, contiguous) {}
29  RegularMergePartners(const DivisionVector& divs,
30  const KVSVector& kvs,
31  bool contiguous = true
32  ):
33  Parent(divs, kvs, contiguous) {}
34 
35  inline bool active(int round, int gid, const Master&) const;
36 
37  // incoming is only valid for an active gid; it will only be called with an active gid
38  inline void incoming(int round, int gid, std::vector<int>& partners, const Master&) const { Parent::fill(round - 1, gid, partners); }
39  // this is a lazy implementation of outgoing, but it reuses the existing code
40  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]); }
41 };
42 
43 } // diy
44 
45 bool
46 diy::RegularMergePartners::
47 active(int round, int gid, const Master&) const
48 {
49  CoordVector coords;
50  Decomposer::gid_to_coords(gid, coords, divisions());
51 
52  for (int r = 0; r < round; ++r)
53  if (Parent::group_position(r, coords[kvs()[r].dim], step(r)) != 0)
54  return false;
55 
56  return true;
57 }
58 
59 #endif
60 
Partners for merge-reduce.
Definition: merge.hpp:16
Definition: common.hpp:10
RegularMergePartners(const DivisionVector &divs, const KVSVector &kvs, bool contiguous=true)
Definition: merge.hpp:29
Decomposes a regular (discrete or continuous) domain into even blocks; creates Links with Bounds alon...
Definition: decomposition.hpp:75
Definition: master.hpp:35
RegularMergePartners(const Decomposer &decomposer, int k, bool contiguous=true)
Definition: merge.hpp:24