Skip to content

Commit 5a5fa6e

Browse files
committed
moved compute_lazy_communication_costs
1 parent 2305fd4 commit 5a5fa6e

3 files changed

Lines changed: 40 additions & 40 deletions

File tree

include/osp/bsp/model/MaxBspSchedule.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ limitations under the License.
2727
#include <vector>
2828

2929
#include "BspSchedule.hpp"
30-
#include "osp/bsp/model/cost/CostModelHelpers.hpp"
30+
#include "osp/bsp/model/cost/LazyCommunicationCost.hpp"
3131
#include "osp/concepts/computational_dag_concept.hpp"
3232

3333
namespace osp {
@@ -93,7 +93,7 @@ class MaxBspSchedule : public BspSchedule<Graph_t> {
9393
std::vector<std::vector<v_commw_t<Graph_t>>> rec(this->instance->numberOfProcessors(), std::vector<v_commw_t<Graph_t>>(this->number_of_supersteps, 0));
9494
std::vector<std::vector<v_commw_t<Graph_t>>> send(this->instance->numberOfProcessors(), std::vector<v_commw_t<Graph_t>>(this->number_of_supersteps, 0));
9595

96-
cost_helpers::compute_lazy_communication_costs(*this, rec, send);
96+
compute_lazy_communication_costs(*this, rec, send);
9797
const std::vector<v_commw_t<Graph_t>> max_comm_per_step = cost_helpers::compute_max_comm_per_step(*this, rec, send);
9898
const std::vector<v_workw_t<Graph_t>> max_work_per_step = cost_helpers::compute_max_work_per_step(*this);
9999

include/osp/bsp/model/cost/CostModelHelpers.hpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -113,42 +113,5 @@ v_workw_t<Graph_t> compute_work_costs(
113113
return compute_work_costs(schedule.getInstance(), schedule.numberOfSupersteps(), schedule.assignedProcessors(), schedule.assignedSupersteps());
114114
}
115115

116-
template<typename Graph_t>
117-
void compute_lazy_communication_costs(
118-
const BspInstance<Graph_t> &instance,
119-
unsigned number_of_supersteps,
120-
const std::vector<unsigned> &node_to_processor_assignment,
121-
const std::vector<unsigned> &node_to_superstep_assignment,
122-
const unsigned staleness,
123-
std::vector<std::vector<v_commw_t<Graph_t>>> &rec,
124-
std::vector<std::vector<v_commw_t<Graph_t>>> &send) {
125-
for (const auto &node : instance.vertices()) {
126-
127-
std::vector<unsigned> step_needed(instance.numberOfProcessors(), number_of_supersteps);
128-
for (const auto &target : instance.getComputationalDag().children(node)) {
129-
130-
if (node_to_processor_assignment[node] != node_to_processor_assignment[target]) {
131-
step_needed[node_to_processor_assignment[target]] = std::min(step_needed[node_to_processor_assignment[target]], node_to_superstep_assignment[target]);
132-
}
133-
}
134-
135-
for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) {
136-
137-
if (step_needed[proc] < number_of_supersteps) {
138-
send[node_to_processor_assignment[node]][step_needed[proc] - staleness] += instance.sendCosts(node_to_processor_assignment[node], proc) * instance.getComputationalDag().vertex_comm_weight(node);
139-
rec[proc][step_needed[proc] - staleness] += instance.sendCosts(node_to_processor_assignment[node], proc) * instance.getComputationalDag().vertex_comm_weight(node);
140-
}
141-
}
142-
}
143-
}
144-
145-
template<typename Graph_t>
146-
void compute_lazy_communication_costs(
147-
const BspSchedule<Graph_t> &schedule,
148-
std::vector<std::vector<v_commw_t<Graph_t>>> &rec,
149-
std::vector<std::vector<v_commw_t<Graph_t>>> &send) {
150-
compute_lazy_communication_costs(schedule.getInstance(), schedule.numberOfSupersteps(), schedule.assignedProcessors(), schedule.assignedSupersteps(), schedule.getStaleness(), rec, send);
151-
}
152-
153116
} // namespace cost_helpers
154117
} // namespace osp

include/osp/bsp/model/cost/LazyCommunicationCost.hpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,43 @@ limitations under the License.
2525

2626
namespace osp {
2727

28+
template<typename Graph_t>
29+
void compute_lazy_communication_costs(
30+
const BspInstance<Graph_t> &instance,
31+
unsigned number_of_supersteps,
32+
const std::vector<unsigned> &node_to_processor_assignment,
33+
const std::vector<unsigned> &node_to_superstep_assignment,
34+
const unsigned staleness,
35+
std::vector<std::vector<v_commw_t<Graph_t>>> &rec,
36+
std::vector<std::vector<v_commw_t<Graph_t>>> &send) {
37+
for (const auto &node : instance.vertices()) {
38+
39+
std::vector<unsigned> step_needed(instance.numberOfProcessors(), number_of_supersteps);
40+
for (const auto &target : instance.getComputationalDag().children(node)) {
41+
42+
if (node_to_processor_assignment[node] != node_to_processor_assignment[target]) {
43+
step_needed[node_to_processor_assignment[target]] = std::min(step_needed[node_to_processor_assignment[target]], node_to_superstep_assignment[target]);
44+
}
45+
}
46+
47+
for (unsigned proc = 0; proc < instance.numberOfProcessors(); proc++) {
48+
49+
if (step_needed[proc] < number_of_supersteps) {
50+
send[node_to_processor_assignment[node]][step_needed[proc] - staleness] += instance.sendCosts(node_to_processor_assignment[node], proc) * instance.getComputationalDag().vertex_comm_weight(node);
51+
rec[proc][step_needed[proc] - staleness] += instance.sendCosts(node_to_processor_assignment[node], proc) * instance.getComputationalDag().vertex_comm_weight(node);
52+
}
53+
}
54+
}
55+
}
56+
57+
template<typename Graph_t>
58+
void compute_lazy_communication_costs(
59+
const BspSchedule<Graph_t> &schedule,
60+
std::vector<std::vector<v_commw_t<Graph_t>>> &rec,
61+
std::vector<std::vector<v_commw_t<Graph_t>>> &send) {
62+
compute_lazy_communication_costs(schedule.getInstance(), schedule.numberOfSupersteps(), schedule.assignedProcessors(), schedule.assignedSupersteps(), schedule.getStaleness(), rec, send);
63+
}
64+
2865
/**
2966
* @struct LazyCommunicationCost
3067
* @brief Implements the lazy communication cost model.
@@ -41,7 +78,7 @@ struct LazyCommunicationCost {
4178
std::vector<std::vector<v_commw_t<Graph_t>>> rec(number_of_processors, std::vector<v_commw_t<Graph_t>>(number_of_supersteps, 0));
4279
std::vector<std::vector<v_commw_t<Graph_t>>> send(number_of_processors, std::vector<v_commw_t<Graph_t>>(number_of_supersteps, 0));
4380

44-
cost_helpers::compute_lazy_communication_costs(schedule, rec, send);
81+
compute_lazy_communication_costs(schedule, rec, send);
4582
const auto max_comm_per_step = cost_helpers::compute_max_comm_per_step(schedule, rec, send);
4683

4784
v_commw_t<Graph_t> comm_costs = 0;

0 commit comments

Comments
 (0)