Skip to content

Commit a7db2a1

Browse files
staleness moved to separate function (#29)
1 parent 2b1aa72 commit a7db2a1

File tree

4 files changed

+37
-62
lines changed

4 files changed

+37
-62
lines changed

include/osp/bsp/model/BspSchedule.hpp

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,38 +67,6 @@ class BspSchedule : public IBspSchedule<Graph_t>, public IBspScheduleEval<Graph_
6767
std::vector<unsigned> node_to_processor_assignment;
6868
std::vector<unsigned> node_to_superstep_assignment;
6969

70-
template<unsigned staleness>
71-
inline bool satisfies_precedence_constraints_staleness() const {
72-
73-
if (node_to_processor_assignment.size() != instance->numberOfVertices() ||
74-
node_to_superstep_assignment.size() != instance->numberOfVertices()) {
75-
return false;
76-
}
77-
78-
for (const auto &v : instance->vertices()) {
79-
80-
if (node_to_superstep_assignment[v] >= number_of_supersteps) {
81-
return false;
82-
}
83-
84-
if (node_to_processor_assignment[v] >= instance->numberOfProcessors()) {
85-
return false;
86-
}
87-
88-
for (const auto &target : instance->getComputationalDag().children(v)) {
89-
90-
const unsigned different_processors =
91-
(node_to_processor_assignment[v] == node_to_processor_assignment[target]) ? 0u : staleness;
92-
93-
if (node_to_superstep_assignment[v] + different_processors > node_to_superstep_assignment[target]) {
94-
return false;
95-
}
96-
}
97-
}
98-
99-
return true;
100-
}
101-
10270
void compute_lazy_communication_costs_helper(std::vector<std::vector<v_commw_t<Graph_t>>> & rec, std::vector<std::vector<v_commw_t<Graph_t>>> & send) const {
10371
for (const auto &node : instance->vertices()) {
10472

@@ -580,9 +548,36 @@ class BspSchedule : public IBspSchedule<Graph_t>, public IBspScheduleEval<Graph_
580548
*
581549
* @return True if the schedule satisfies the precedence constraints of the computational DAG, false otherwise.
582550
*/
583-
virtual bool satisfiesPrecedenceConstraints() const {
584-
return satisfies_precedence_constraints_staleness<1>();
585-
};
551+
inline bool satisfiesPrecedenceConstraints() const {
552+
553+
if (node_to_processor_assignment.size() != instance->numberOfVertices() ||
554+
node_to_superstep_assignment.size() != instance->numberOfVertices()) {
555+
return false;
556+
}
557+
558+
for (const auto &v : instance->vertices()) {
559+
560+
if (node_to_superstep_assignment[v] >= number_of_supersteps) {
561+
return false;
562+
}
563+
564+
if (node_to_processor_assignment[v] >= instance->numberOfProcessors()) {
565+
return false;
566+
}
567+
568+
for (const auto &target : instance->getComputationalDag().children(v)) {
569+
570+
const unsigned different_processors =
571+
(node_to_processor_assignment[v] == node_to_processor_assignment[target]) ? 0u : getStaleness();
572+
573+
if (node_to_superstep_assignment[v] + different_processors > node_to_superstep_assignment[target]) {
574+
return false;
575+
}
576+
}
577+
}
578+
579+
return true;
580+
}
586581

587582
bool satisfiesNodeTypeConstraints() const {
588583

@@ -834,6 +829,8 @@ class BspSchedule : public IBspSchedule<Graph_t>, public IBspScheduleEval<Graph_
834829

835830
return num;
836831
}
832+
833+
unsigned virtual getStaleness() const { return 1; }
837834
};
838835

839836
} // namespace osp

include/osp/bsp/model/BspScheduleCS.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class BspScheduleCS : public BspSchedule<Graph_t> {
216216
return false;
217217

218218
first_at[std::get<0>(key)][std::get<2>(key)] =
219-
std::min(first_at[std::get<0>(key)][std::get<2>(key)], val + 1);
219+
std::min(first_at[std::get<0>(key)][std::get<2>(key)], val + this->getStaleness());
220220
}
221221

222222
for (auto const &[key, val] : cs) {

include/osp/bsp/model/MaxBspSchedule.hpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,6 @@ class MaxBspSchedule : public BspSchedule<Graph_t> {
8686
* @brief Destructor for the BspSchedule class.
8787
*/
8888
virtual ~MaxBspSchedule() = default;
89-
90-
/**
91-
* @brief Returns true if the schedule satisfies the precedence constraints of the computational DAG.
92-
*
93-
* The precedence constraints of the computational DAG are satisfied if, for each directed edge (u, v) such that u
94-
* and v are assigned to different processors, the superstep assigned to node u is less than the superstep assigned
95-
* to node v.
96-
*
97-
* @return True if the schedule satisfies the precedence constraints of the computational DAG, false otherwise.
98-
*/
99-
virtual bool satisfiesPrecedenceConstraints() const override {
100-
return this->template satisfies_precedence_constraints_staleness<2>();
101-
};
10289

10390
virtual v_workw_t<Graph_t> computeCosts() const override {
10491

@@ -123,6 +110,8 @@ class MaxBspSchedule : public BspSchedule<Graph_t> {
123110
}
124111
return costs;
125112
}
113+
114+
unsigned virtual getStaleness() const override { return 2; }
126115
};
127116

128117
} // namespace osp

include/osp/bsp/model/MaxBspScheduleCS.hpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,6 @@ class MaxBspScheduleCS : public BspScheduleCS<Graph_t> {
8080
* @brief Destructor for the BspSchedule class.
8181
*/
8282
virtual ~MaxBspScheduleCS() = default;
83-
84-
/**
85-
* @brief Returns true if the schedule satisfies the precedence constraints of the computational DAG.
86-
*
87-
* The precedence constraints of the computational DAG are satisfied if, for each directed edge (u, v) such that u
88-
* and v are assigned to different processors, the superstep assigned to node u is less than the superstep assigned
89-
* to node v.
90-
*
91-
* @return True if the schedule satisfies the precedence constraints of the computational DAG, false otherwise.
92-
*/
93-
virtual bool satisfiesPrecedenceConstraints() const override {
94-
return this->template satisfies_precedence_constraints_staleness<2>();
95-
};
9683

9784
virtual v_workw_t<Graph_t> computeCosts() const override {
9885

@@ -117,6 +104,8 @@ class MaxBspScheduleCS : public BspScheduleCS<Graph_t> {
117104
}
118105
return costs;
119106
}
107+
108+
unsigned virtual getStaleness() const override { return 2; }
120109
};
121110

122111
} // namespace osp

0 commit comments

Comments
 (0)