Derecho  0.9
Distributed systems toolkit for RDMA
schedule.hpp
Go to the documentation of this file.
1 #ifndef SCHEDULE_HPP
2 #define SCHEDULE_HPP
3 
4 #include <cmath>
5 #include <optional>
6 #include <vector>
7 
8 using std::vector;
9 using std::optional;
10 
11 class schedule {
12 protected:
13  const uint32_t num_members = 0;
14  const uint32_t member_index = 0;
15 
16 public:
17  schedule(uint32_t members, uint32_t index)
18  : num_members(members),
19  member_index(index) {}
20  virtual ~schedule() = default;
21 
22  struct block_transfer {
23  uint32_t target;
24  size_t block_number;
25  };
26 
27  virtual vector<uint32_t> get_connections() const = 0;
28  virtual optional<block_transfer> get_outgoing_transfer(size_t num_blocks, size_t send_step) const = 0;
29  virtual optional<block_transfer> get_incoming_transfer(size_t num_blocks, size_t receive_step) const = 0;
30  virtual optional<block_transfer> get_first_block(size_t num_blocks) const = 0;
31  virtual size_t get_total_steps(size_t num_blocks) const = 0;
32 };
33 
34 class chain_schedule : public schedule {
35 public:
36  using schedule::schedule;
37  vector<uint32_t> get_connections() const;
38  optional<block_transfer> get_outgoing_transfer(size_t num_blocks, size_t send_step) const;
39  optional<block_transfer> get_incoming_transfer(size_t num_blocks, size_t receive_step) const;
40  optional<block_transfer> get_first_block(size_t num_blocks) const;
41  size_t get_total_steps(size_t num_blocks) const;
42 };
43 
44 class sequential_schedule : public schedule {
45 public:
46  using schedule::schedule;
47  vector<uint32_t> get_connections() const;
48  optional<block_transfer> get_outgoing_transfer(size_t num_blocks, size_t send_step) const;
49  optional<block_transfer> get_incoming_transfer(size_t num_blocks, size_t receive_step) const;
50  optional<block_transfer> get_first_block(size_t num_blocks) const;
51  size_t get_total_steps(size_t num_blocks) const;
52 };
53 
54 class tree_schedule : public schedule {
55 public:
56  using schedule::schedule;
57  vector<uint32_t> get_connections() const;
58  optional<block_transfer> get_outgoing_transfer(size_t num_blocks, size_t send_step) const;
59  optional<block_transfer> get_incoming_transfer(size_t num_blocks, size_t receive_step) const;
60  optional<block_transfer> get_first_block(size_t num_blocks) const;
61  size_t get_total_steps(size_t num_blocks) const;
62 };
63 
64 class binomial_schedule : public schedule {
65 private:
66  // Base to logarithm of the group size, rounded down.
67  const unsigned int log2_num_members;
68 
69  optional<block_transfer> get_vertex_outgoing_transfer(size_t send_step);
70  optional<block_transfer> get_vertex_incoming_transfer(size_t receive_step);
71 
72 public:
73  binomial_schedule(uint32_t members, uint32_t index)
74  : schedule(members, index),
75  log2_num_members(floor(log2(num_members))) {}
76 
77  static optional<block_transfer> get_vertex_outgoing_transfer(
78  uint32_t vertex, size_t step, uint32_t num_members,
79  unsigned int log2_num_members, size_t num_blocks, size_t total_steps);
80  static optional<block_transfer> get_vertex_incoming_transfer(
81  uint32_t vertex, size_t step, uint32_t num_members,
82  unsigned int log2_num_members, size_t num_blocks, size_t total_steps);
83  static optional<block_transfer> get_outgoing_transfer(
84  uint32_t node, size_t step, uint32_t num_members,
85  unsigned int log2_num_members, size_t num_blocks, size_t total_steps);
86  static optional<block_transfer> get_incoming_transfer(
87  uint32_t node, size_t step, uint32_t num_members,
88  unsigned int log2_num_members, size_t num_blocks, size_t total_steps);
89  static optional<size_t> get_intravertex_block(uint32_t vertex, size_t step,
90  uint32_t num_members,
91  unsigned int log2_num_members,
92  size_t num_blocks,
93  size_t total_steps);
94  static uint32_t get_intervertex_receiver(uint32_t vertex, size_t step,
95  uint32_t num_members,
96  unsigned int log2_num_members,
97  size_t num_blocks,
98  size_t total_steps);
99 
100  vector<uint32_t> get_connections() const;
101  optional<block_transfer> get_outgoing_transfer(size_t num_blocks, size_t send_step) const;
102  optional<block_transfer> get_incoming_transfer(size_t num_blocks, size_t receive_step) const;
103  optional<block_transfer> get_first_block(size_t num_blocks) const;
104  size_t get_total_steps(size_t num_blocks) const;
105 };
106 
107 #endif /* SCHEDULE_HPP */
virtual vector< uint32_t > get_connections() const =0
virtual optional< block_transfer > get_outgoing_transfer(size_t num_blocks, size_t send_step) const =0
const unsigned int log2_num_members
Definition: schedule.hpp:67
virtual ~schedule()=default
const uint32_t num_members
Definition: schedule.hpp:13
virtual size_t get_total_steps(size_t num_blocks) const =0
const uint32_t member_index
Definition: schedule.hpp:14
schedule(uint32_t members, uint32_t index)
Definition: schedule.hpp:17
virtual optional< block_transfer > get_first_block(size_t num_blocks) const =0
binomial_schedule(uint32_t members, uint32_t index)
Definition: schedule.hpp:73
virtual optional< block_transfer > get_incoming_transfer(size_t num_blocks, size_t receive_step) const =0