-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTwistedHyperCube.h
48 lines (39 loc) · 1.03 KB
/
TwistedHyperCube.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
class HyperCube
{
public:
// Bits of node id can be shifted by the optional parameter.
HyperCube(int num_nodes, int shift = 0);
int NumNodes() const;
int Dimension() const;
virtual int Peer(int id, int dim) const;
// send and recv location in recursive halving
// for recursive doubling, pass Dimension() - 1 - dim
virtual int RecvLocation(int id, int dim) const;
virtual int SendLocation(int id, int dim) const;
protected:
int ShiftedId(int id, int shift) const;
int ShiftedId(int id) const;
int UnshiftedId(int id) const;
int num_nodes_;
int shift_;
};
// 0 - 1
// | |
// 3 - 2
// X
// 4 - 5
// | |
// 7 - 6
class TwistedHyperCube : public HyperCube
{
public:
TwistedHyperCube(int num_nodes, int shift = 0);
int Peer(int id, int dim) const override;
// send and recv location in recursive halving
// for recursive doubling, pass Dimension() - 1 - dim
int RecvLocation(int id, int dim) const override;
int SendLocation(int id, int dim) const override;
private:
int shift_;
};