1 #ifndef DIY_PARTNERS_SWAP_HPP
2 #define DIY_PARTNERS_SWAP_HPP
3 
4 #include "common.hpp"
5 
6 namespace diy
7 {
8 
9 class Master;
10 
11 /**
12  * \ingroup Communication
13  * \brief Partners for swap-reduce
14  *
15  */
16 struct RegularSwapPartners: public RegularPartners
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>
RegularSwapPartnersdiy::RegularSwapPartners24                 RegularSwapPartners(const Decomposer& decomposer,   //!< domain decomposition
25                                     int k,                          //!< target k value
26                                     bool contiguous = true          //!< distance halving (true) or doubling (false)
27                     ):
28                     Parent(decomposer, k, contiguous)         {}
RegularSwapPartnersdiy::RegularSwapPartners29                 RegularSwapPartners(const DivisionVector&   divs, //!< explicit division vector
30                                     const KVSVector&        kvs,  //!< explicit k vector
31                                     bool  contiguous = true       //!< distance halving (true) or doubling (false)
32                     ):
33                     Parent(divs, kvs, contiguous)               {}
34 
activediy::RegularSwapPartners35   bool          active(int, int, const Master&) const                                           { return true; }    // in swap-reduce every block is always active
36 
incomingdiy::RegularSwapPartners37   void          incoming(int round, int gid, std::vector<int>& partners, const Master&) const   { Parent::fill(round - 1, gid, partners); }
outgoingdiy::RegularSwapPartners38   void          outgoing(int round, int gid, std::vector<int>& partners, const Master&) const   { Parent::fill(round, gid, partners); }
39 };
40 
41 } // diy
42 
43 #endif
44