Skip to content

Commit e8abff5

Browse files
Merge pull request #40 from Algebraic-Programming/hill_climbing_for_maxBSP
MaxBSP schedulers (grredy converter, HC, HCcs)
2 parents d4771f5 + fad2ba8 commit e8abff5

File tree

11 files changed

+793
-112
lines changed

11 files changed

+793
-112
lines changed

include/osp/bsp/model/BspSchedule.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ class BspSchedule : public IBspSchedule<Graph_t>, public IBspScheduleEval<Graph_
8383

8484
if (step_needed[proc] < number_of_supersteps) {
8585

86-
send[node_to_processor_assignment[node]][step_needed[proc] - 1] +=
86+
send[node_to_processor_assignment[node]][step_needed[proc] - getStaleness()] +=
8787
instance->sendCosts(node_to_processor_assignment[node], proc) *
8888
instance->getComputationalDag().vertex_comm_weight(node);
8989

90-
rec[proc][step_needed[proc] - 1] += instance->sendCosts(node_to_processor_assignment[node], proc) *
90+
rec[proc][step_needed[proc] - getStaleness()] += instance->sendCosts(node_to_processor_assignment[node], proc) *
9191
instance->getComputationalDag().vertex_comm_weight(node);
9292
}
9393
}

include/osp/bsp/model/BspScheduleCS.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,11 @@ class BspScheduleCS : public BspSchedule<Graph_t> {
359359
for (const auto &source : BspSchedule<Graph_t>::instance->getComputationalDag().parents(node)) {
360360

361361
if (!node_to_proc_been_sent[source][proc]) {
362-
assert(BspSchedule<Graph_t>::node_to_superstep_assignment[source] < step);
362+
assert(BspSchedule<Graph_t>::node_to_superstep_assignment[source] < step + 1 - this->getStaleness());
363363
commSchedule.emplace(
364364
std::make_tuple(source, BspSchedule<Graph_t>::node_to_processor_assignment[source],
365365
proc),
366-
step - 1);
366+
step - this->getStaleness());
367367
node_to_proc_been_sent[source][proc] = true;
368368
v_commw_t<Graph_t> comm_cost =
369369
BspSchedule<Graph_t>::instance->getComputationalDag().vertex_comm_weight(source) *
@@ -399,7 +399,7 @@ class BspScheduleCS : public BspSchedule<Graph_t> {
399399
comm_cost + receive_cost[dest_proc] > max_comm_cost) {
400400
iter++;
401401
} else {
402-
commSchedule.emplace(std::make_tuple(node_to_send, proc, dest_proc), step - 1);
402+
commSchedule.emplace(std::make_tuple(node_to_send, proc, dest_proc), step - this->getStaleness());
403403
node_to_proc_been_sent[node_to_send][dest_proc] = true;
404404
send_cost[proc] += comm_cost;
405405
receive_cost[dest_proc] += comm_cost;
@@ -441,11 +441,11 @@ class BspScheduleCS : public BspSchedule<Graph_t> {
441441
const auto tmp = std::make_tuple(source, BspSchedule<Graph_t>::node_to_processor_assignment[source],
442442
BspSchedule<Graph_t>::node_to_processor_assignment[target]);
443443
if (commSchedule.find(tmp) == commSchedule.end()) {
444-
commSchedule[tmp] = BspSchedule<Graph_t>::node_to_superstep_assignment[target] - 1;
444+
commSchedule[tmp] = BspSchedule<Graph_t>::node_to_superstep_assignment[target] - this->getStaleness();
445445

446446
} else {
447447
commSchedule[tmp] =
448-
std::min(BspSchedule<Graph_t>::node_to_superstep_assignment[target] - 1, commSchedule[tmp]);
448+
std::min(BspSchedule<Graph_t>::node_to_superstep_assignment[target] - this->getStaleness(), commSchedule[tmp]);
449449
}
450450
}
451451
}

include/osp/bsp/model/BspScheduleCostEvaluator.hpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,6 @@ class BspScheduleCostEvaluator {
8686
return max_comm_per_step;
8787
}
8888

89-
std::vector<v_workw_t<Graph_t>> compute_max_work_per_step_helper() const {
90-
const unsigned number_of_supersteps = schedule.numberOfSupersteps();
91-
std::vector<std::vector<v_workw_t<Graph_t>>> work = std::vector<std::vector<v_workw_t<Graph_t>>>(
92-
number_of_supersteps, std::vector<v_workw_t<Graph_t>>(instance.numberOfProcessors(), 0));
93-
for (const auto &node : instance.vertices()) {
94-
work[schedule.assignedSuperstep(node)][schedule.assignedProcessor(node)] +=
95-
instance.getComputationalDag().vertex_work_weight(node);
96-
}
97-
98-
std::vector<v_workw_t<Graph_t>> max_work_per_step(number_of_supersteps, 0);
99-
for (unsigned step = 0; step < number_of_supersteps; step++) {
100-
v_workw_t<Graph_t> max_work = 0;
101-
for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) {
102-
if (max_work < work[step][proc]) {
103-
max_work = work[step][proc];
104-
}
105-
}
106-
107-
max_work_per_step[step] = max_work;
108-
}
109-
110-
return max_work_per_step;
111-
}
112-
11389
public:
11490
/**
11591
* @brief Construct a new Bsp Schedule Cost Evaluator object.
@@ -150,6 +126,35 @@ class BspScheduleCostEvaluator {
150126
return costs;
151127
}
152128

129+
/**
130+
* @brief Computes the work costs for each superstep.
131+
*
132+
* @return The work cost per superstep.
133+
*/
134+
std::vector<v_workw_t<Graph_t>> compute_max_work_per_step_helper() const {
135+
const unsigned number_of_supersteps = schedule.numberOfSupersteps();
136+
std::vector<std::vector<v_workw_t<Graph_t>>> work = std::vector<std::vector<v_workw_t<Graph_t>>>(
137+
number_of_supersteps, std::vector<v_workw_t<Graph_t>>(instance.numberOfProcessors(), 0));
138+
for (const auto &node : instance.vertices()) {
139+
work[schedule.assignedSuperstep(node)][schedule.assignedProcessor(node)] +=
140+
instance.getComputationalDag().vertex_work_weight(node);
141+
}
142+
143+
std::vector<v_workw_t<Graph_t>> max_work_per_step(number_of_supersteps, 0);
144+
for (unsigned step = 0; step < number_of_supersteps; step++) {
145+
v_workw_t<Graph_t> max_work = 0;
146+
for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) {
147+
if (max_work < work[step][proc]) {
148+
max_work = work[step][proc];
149+
}
150+
}
151+
152+
max_work_per_step[step] = max_work;
153+
}
154+
155+
return max_work_per_step;
156+
}
157+
153158
/**
154159
* @brief Computes the total work costs of the schedule.
155160
*

include/osp/bsp/model/MaxBspSchedule.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class MaxBspSchedule : public BspSchedule<Graph_t> {
7171

7272
MaxBspSchedule(const IBspSchedule<Graph_t> &schedule) : BspSchedule<Graph_t>(schedule) {}
7373

74+
MaxBspSchedule(IBspSchedule<Graph_t> &&schedule) : BspSchedule<Graph_t>(std::move(schedule)) {}
75+
7476
MaxBspSchedule(const MaxBspSchedule<Graph_t> &schedule) = default;
7577

7678
MaxBspSchedule<Graph_t> &operator=(const MaxBspSchedule<Graph_t> &schedule) = default;

include/osp/bsp/model/MaxBspScheduleCS.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ class MaxBspScheduleCS : public BspScheduleCS<Graph_t> {
6666
MaxBspScheduleCS(const BspScheduleCS<Graph_t> &schedule) : BspScheduleCS<Graph_t>(schedule) {}
6767
MaxBspScheduleCS(BspScheduleCS<Graph_t> &&schedule) : BspScheduleCS<Graph_t>(std::move(schedule)) {}
6868

69+
MaxBspScheduleCS(const MaxBspSchedule<Graph_t> &schedule) : BspScheduleCS<Graph_t>(schedule) {
70+
this->setAutoCommunicationSchedule();
71+
}
72+
73+
MaxBspScheduleCS(MaxBspSchedule<Graph_t> &&schedule) : BspScheduleCS<Graph_t>(std::move(schedule)) {
74+
this->setAutoCommunicationSchedule();
75+
}
76+
6977
MaxBspScheduleCS(const MaxBspScheduleCS<Graph_t> &schedule) = default;
7078
MaxBspScheduleCS(MaxBspScheduleCS<Graph_t> &&schedule) = default;
7179

0 commit comments

Comments
 (0)