DIY 3.0 data-parallel out-of-core C++ library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List

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
20 struct RegularAllReducePartners: public RegularMergePartners
21 {
22 typedef RegularMergePartners Parent;
23
27 template<class Decomposer>
28 RegularAllReducePartners(const Decomposer& 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
diy::RegularAllReducePartners::size
int size(int round) const
returns size of a group of partners in a given round
Definition: all-reduce.hpp:42
diy::RegularMergePartners
Partners for merge-reduce.
Definition: merge.hpp:16
diy::RegularAllReducePartners::active
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
diy::RegularAllReducePartners::dim
int dim(int round) const
returns dimension (direction of partners in a regular grid) in a given round
Definition: all-reduce.hpp:44
diy::RegularDecomposer
Decomposes a regular (discrete or continuous) domain into even blocks; creates Links with Bounds alon...
Definition: decomposition.hpp:75
diy::RegularAllReducePartners::Parent
RegularMergePartners Parent
base class merge reduction
Definition: all-reduce.hpp:22
diy::RegularAllReducePartners
Allreduce (reduction with results broadcasted to all blocks) is implemented as two merge reductions...
Definition: all-reduce.hpp:20
diy::Master
Definition: master.hpp:35
diy::RegularAllReducePartners::RegularAllReducePartners
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
diy::RegularAllReducePartners::rounds
size_t rounds() const
returns total number of rounds
Definition: all-reduce.hpp:40
diy::RegularAllReducePartners::parent_round
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
diy::RegularAllReducePartners::RegularAllReducePartners
RegularAllReducePartners(const DivisionVector &divs, const KVSVector &kvs, bool contiguous=true)
Definition: all-reduce.hpp:33