DIY  3.0
data-parallel out-of-core C++ library
 All Classes Namespaces Functions Typedefs Groups Pages
all-reduce.hpp
1 #ifndef DIY_PARTNERS_ALL_REDUCE_HPP
2 #define DIY_PARTNERS_ALL_REDUCE_HPP
3 
4 #include "merge.hpp"
5 
6 namespace diy
7 {
8 
9 class Master;
10 
14 
21 {
23 
27  template<class Decomposer>
29  int k,
30  bool contiguous = true
31  ):
32  Parent(decomposer, k, contiguous) {}
33  RegularAllReducePartners(const DivisionVector& divs,
34  const KVSVector& kvs,
35  bool contiguous = true
36  ):
37  Parent(divs, kvs, contiguous) {}
38 
40  size_t rounds() const { return 2*Parent::rounds(); }
42  int size(int round) const { return Parent::size(parent_round(round)); }
44  int dim(int round) const { return Parent::dim(parent_round(round)); }
46  inline bool active(int round, int gid, const Master& m) const { return Parent::active(parent_round(round), gid, m); }
48  int parent_round(int round) const { return round < (int) Parent::rounds() ? round : static_cast<int>(rounds()) - round; }
49 
50  // incoming is only valid for an active gid; it will only be called with an active gid
51  inline void incoming(int round, int gid, std::vector<int>& partners, const Master& m) const
52  {
53  if (round <= (int) Parent::rounds())
54  Parent::incoming(round, gid, partners, m);
55  else
56  Parent::outgoing(parent_round(round), gid, partners, m);
57  }
58 
59  inline void outgoing(int round, int gid, std::vector<int>& partners, const Master& m) const
60  {
61  if (round < (int) Parent::rounds())
62  Parent::outgoing(round, gid, partners, m);
63  else
64  Parent::incoming(parent_round(round), gid, partners, m);
65  }
66 };
67 
68 } // diy
69 
70 #endif
71 
72 
int size(int round) const
returns size of a group of partners in a given round
Definition: all-reduce.hpp:42
Partners for merge-reduce.
Definition: merge.hpp:16
bool active(int round, int gid, const Master &m) const
returns whether a given block in a given round has dropped out of the merge yet or not ...
Definition: all-reduce.hpp:46
int dim(int round) const
returns dimension (direction of partners in a regular grid) in a given round
Definition: all-reduce.hpp:44
Decomposes a regular (discrete or continuous) domain into even blocks; creates Links with Bounds alon...
Definition: decomposition.hpp:75
RegularMergePartners Parent
base class merge reduction
Definition: all-reduce.hpp:22
Allreduce (reduction with results broadcasted to all blocks) is implemented as two merge reductions...
Definition: all-reduce.hpp:20
Definition: master.hpp:35
RegularAllReducePartners(const Decomposer &decomposer, int k, bool contiguous=true)
contiguous parameter indicates whether to match partners contiguously or in a round-robin fashion; co...
Definition: all-reduce.hpp:28
size_t rounds() const
returns total number of rounds
Definition: all-reduce.hpp:40
int parent_round(int round) const
returns what the current round would be in the first or second parent merge reduction ...
Definition: all-reduce.hpp:48
RegularAllReducePartners(const DivisionVector &divs, const KVSVector &kvs, bool contiguous=true)
Definition: all-reduce.hpp:33