Skip to content

Commit 1c9c29e

Browse files
authored
revise scheduler interface (#51)
* revise scheduler interface removed timeout method of scheduler documentation for scheduler multi * removed semicolon * removed-commented-line * reorder
1 parent 412437d commit 1c9c29e

File tree

11 files changed

+245
-261
lines changed

11 files changed

+245
-261
lines changed

apps/ilp_bsp_scheduler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ int main(int argc, char *argv[]) {
9090

9191
CoptFullScheduler<ComputationalDag> scheduler;
9292
scheduler.setMaxNumberOfSupersteps(steps);
93-
scheduler.setTimeLimitHours(48);
94-
93+
9594
if (recomp) {
9695

9796
BspScheduleRecomp<ComputationalDag> schedule(instance);

apps/test_suite_runner/StringToScheduler/run_bsp_scheduler.hpp

Lines changed: 86 additions & 51 deletions
Large diffs are not rendered by default.

include/osp/bsp/scheduler/GreedySchedulers/GreedyChildren.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ class GreedyChildren : public Scheduler<Graph_t> {
3434
bool ensure_enough_sources;
3535

3636
public:
37-
GreedyChildren(bool ensure_enough_sources_ = true) : ensure_enough_sources(ensure_enough_sources_) {};
38-
GreedyChildren(unsigned time_limit, bool ensure_enough_sources_ = true)
39-
: Scheduler<Graph_t>(time_limit), ensure_enough_sources(ensure_enough_sources_) {};
37+
38+
GreedyChildren(bool ensure_enough_sources_ = true) : Scheduler<Graph_t>(), ensure_enough_sources(ensure_enough_sources_) {};
4039

4140
RETURN_STATUS computeSchedule(BspSchedule<Graph_t> &sched) override {
4241

@@ -75,7 +74,7 @@ class GreedyChildren : public Scheduler<Graph_t> {
7574
if (nodes_assigned_this_superstep.count(par)) {
7675
if (!processor_set) {
7776
const unsigned par_proc = sched.assignedProcessor(par);
78-
if(!instance.isCompatible(node, par_proc)) {
77+
if (!instance.isCompatible(node, par_proc)) {
7978
failed_to_allocate = true;
8079
break;
8180
}
@@ -106,7 +105,7 @@ class GreedyChildren : public Scheduler<Graph_t> {
106105
}
107106
}
108107
sched.setAssignedProcessor(node, best_proc);
109-
}
108+
}
110109

111110
nodes_assigned_this_superstep.emplace(node);
112111
processor_weights[sched.assignedProcessor(node)] += graph.vertex_work_weight(node);

include/osp/bsp/scheduler/GreedySchedulers/RandomGreedy.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ class RandomGreedy : public Scheduler<Graph_t> {
3737
bool ensure_enough_sources;
3838

3939
public:
40-
RandomGreedy(bool ensure_enough_sources_ = true) : ensure_enough_sources(ensure_enough_sources_) {};
41-
RandomGreedy(unsigned time_limit, bool ensure_enough_sources_)
42-
: Scheduler<Graph_t>(time_limit), ensure_enough_sources(ensure_enough_sources_) {};
40+
41+
RandomGreedy(bool ensure_enough_sources_ = true) : Scheduler<Graph_t>(), ensure_enough_sources(ensure_enough_sources_) {};
4342

4443
RETURN_STATUS computeSchedule(BspSchedule<Graph_t> &sched) override {
4544

include/osp/bsp/scheduler/IlpSchedulers/CoptFullScheduler.hpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ class CoptFullScheduler : public Scheduler<Graph_t> {
6565
bool is_max_bsp = false;
6666
bool use_memory_constraint;
6767
bool use_initial_schedule = false;
68-
const BspScheduleCS<Graph_t> *initial_schedule;
69-
68+
bool write_solutions_found;
7069
bool use_initial_schedule_recomp = false;
71-
const BspScheduleRecomp<Graph_t> *initial_schedule_recomp;
7270

73-
bool write_solutions_found;
71+
unsigned timeLimitSeconds = 0;
72+
73+
const BspScheduleCS<Graph_t> *initial_schedule;
74+
const BspScheduleRecomp<Graph_t> *initial_schedule_recomp;
75+
7476
std::string write_solutions_path;
7577
std::string solution_file_prefix;
7678

@@ -822,8 +824,8 @@ class CoptFullScheduler : public Scheduler<Graph_t> {
822824

823825
public:
824826
CoptFullScheduler(unsigned steps = 5)
825-
: allow_recomputation(false), use_memory_constraint(false), use_initial_schedule(false), initial_schedule(0),
826-
write_solutions_found(false), max_number_supersteps(steps) {
827+
: allow_recomputation(false), use_memory_constraint(false), use_initial_schedule(false),
828+
write_solutions_found(false), initial_schedule(0), max_number_supersteps(steps) {
827829

828830
// solution_callback.comm_processor_to_processor_superstep_node_var_ptr =
829831
// &comm_processor_to_processor_superstep_node_var;
@@ -832,7 +834,7 @@ class CoptFullScheduler : public Scheduler<Graph_t> {
832834

833835
CoptFullScheduler(const BspScheduleCS<Graph_t> &schedule)
834836
: allow_recomputation(false), use_memory_constraint(false), use_initial_schedule(true),
835-
initial_schedule(&schedule), write_solutions_found(false),
837+
write_solutions_found(false), initial_schedule(&schedule),
836838
max_number_supersteps(schedule.numberOfSupersteps()) {
837839

838840
// solution_callback.comm_processor_to_processor_superstep_node_var_ptr =
@@ -842,7 +844,7 @@ class CoptFullScheduler : public Scheduler<Graph_t> {
842844

843845
CoptFullScheduler(const BspScheduleRecomp<Graph_t> &schedule)
844846
: allow_recomputation(true), use_memory_constraint(false), use_initial_schedule_recomp(true),
845-
initial_schedule_recomp(&schedule), write_solutions_found(false),
847+
write_solutions_found(false), initial_schedule_recomp(&schedule),
846848
max_number_supersteps(schedule.numberOfSupersteps()) {
847849
}
848850

@@ -869,6 +871,13 @@ class CoptFullScheduler : public Scheduler<Graph_t> {
869871
return status;
870872
}
871873
}
874+
875+
virtual RETURN_STATUS computeScheduleWithTimeLimit(BspSchedule<Graph_t> &schedule, unsigned timeLimit) {
876+
877+
timeLimitSeconds = timeLimit;
878+
return computeSchedule(schedule);
879+
}
880+
872881
virtual RETURN_STATUS computeMaxBspSchedule(MaxBspSchedule<Graph_t> &schedule) {
873882

874883
MaxBspScheduleCS<Graph_t> schedule_cs(schedule.getInstance());
@@ -934,7 +943,9 @@ class CoptFullScheduler : public Scheduler<Graph_t> {
934943

935944
virtual void computeScheduleBase(const BspScheduleRecomp<Graph_t> &schedule, Model &model) {
936945

937-
model.SetDblParam(COPT_DBLPARAM_TIMELIMIT, Scheduler<Graph_t>::timeLimitSeconds);
946+
if (timeLimitSeconds > 0) {
947+
model.SetDblParam(COPT_DBLPARAM_TIMELIMIT, timeLimitSeconds);
948+
}
938949
model.SetIntParam(COPT_INTPARAM_THREADS, 128);
939950

940951
model.SetIntParam(COPT_INTPARAM_STRONGBRANCHING, 1);

include/osp/bsp/scheduler/IlpSchedulers/TotalCommunicationScheduler.hpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ limitations under the License.
2121
#include <callbackbase.h>
2222
#include <coptcpp_pch.h>
2323

24+
#include "osp/auxiliary/io/DotFileWriter.hpp"
2425
#include "osp/bsp/scheduler/LocalSearch/KernighanLin/kl_total_comm.hpp"
2526
#include "osp/bsp/scheduler/Scheduler.hpp"
2627
#include "osp/graph_algorithms/directed_graph_edge_view.hpp"
27-
#include "osp/auxiliary/io/DotFileWriter.hpp"
2828

2929
namespace osp {
3030

@@ -76,9 +76,9 @@ class TotalCommunicationScheduler : public Scheduler<Graph_t> {
7676

7777
auto sched = constructBspScheduleFromCallback();
7878
DotFileWriter sched_writer;
79-
sched_writer.write_schedule(write_solutions_path_cb + "intmed_sol_" + solution_file_prefix_cb + "_" +
80-
std::to_string(counter) + "_schedule.dot",
81-
sched);
79+
sched_writer.write_schedule(write_solutions_path_cb + "intmed_sol_" + solution_file_prefix_cb +
80+
"_" + std::to_string(counter) + "_schedule.dot",
81+
sched);
8282
counter++;
8383
}
8484

@@ -95,8 +95,8 @@ class TotalCommunicationScheduler : public Scheduler<Graph_t> {
9595

9696
for (unsigned processor = 0; processor < instance_ptr->numberOfProcessors(); processor++) {
9797

98-
for (unsigned step = 0; step < static_cast<unsigned>((*node_to_processor_superstep_var_ptr)[0][0].Size());
99-
step++) {
98+
for (unsigned step = 0;
99+
step < static_cast<unsigned>((*node_to_processor_superstep_var_ptr)[0][0].Size()); step++) {
100100

101101
assert(size < std::numeric_limits<int>::max());
102102
if (GetSolution(
@@ -170,8 +170,8 @@ class TotalCommunicationScheduler : public Scheduler<Graph_t> {
170170

171171
for (unsigned processor = 0; processor < instance_ptr->numberOfProcessors(); processor++) {
172172

173-
for (unsigned step = 0; step < static_cast<unsigned>((*node_to_processor_superstep_var_ptr)[0][0].Size());
174-
step++) {
173+
for (unsigned step = 0;
174+
step < static_cast<unsigned>((*node_to_processor_superstep_var_ptr)[0][0].Size()); step++) {
175175
assert(step <= std::numeric_limits<int>::max());
176176
if (GetSolution(
177177
(*node_to_processor_superstep_var_ptr)[node][processor][static_cast<int>(step)]) >=
@@ -203,8 +203,8 @@ class TotalCommunicationScheduler : public Scheduler<Graph_t> {
203203

204204
for (unsigned processor = 0; processor < instance_ptr->numberOfProcessors(); processor++) {
205205

206-
for (unsigned step = 0; step < static_cast<unsigned>((*node_to_processor_superstep_var_ptr)[0][0].Size());
207-
step++) {
206+
for (unsigned step = 0;
207+
step < static_cast<unsigned>((*node_to_processor_superstep_var_ptr)[0][0].Size()); step++) {
208208

209209
if (schedule.assignedProcessor(node) == processor && schedule.assignedSuperstep(node) == step) {
210210
assert(step <= std::numeric_limits<int>::max());
@@ -425,7 +425,8 @@ class TotalCommunicationScheduler : public Scheduler<Graph_t> {
425425
model.AddConstr(superstep_used_var[0] == 1);
426426

427427
for (unsigned int step = 0; step < max_number_supersteps - 1; step++) {
428-
model.AddConstr(superstep_used_var[static_cast<int>(step)] >= superstep_used_var[static_cast<int>(step + 1)]);
428+
model.AddConstr(superstep_used_var[static_cast<int>(step)] >=
429+
superstep_used_var[static_cast<int>(step + 1)]);
429430
}
430431

431432
// superstep is used at all
@@ -579,7 +580,7 @@ class TotalCommunicationScheduler : public Scheduler<Graph_t> {
579580
Expr expr_work;
580581
for (const auto &node : instance.vertices()) {
581582
expr_work += instance.getComputationalDag().vertex_work_weight(node) *
582-
node_to_processor_superstep_var[node][processor][static_cast<int>(step)];
583+
node_to_processor_superstep_var[node][processor][static_cast<int>(step)];
583584
}
584585

585586
model.AddConstr(max_work_superstep_var[static_cast<int>(step)] >= expr_work);
@@ -632,6 +633,11 @@ class TotalCommunicationScheduler : public Scheduler<Graph_t> {
632633

633634
virtual ~TotalCommunicationScheduler() = default;
634635

636+
virtual RETURN_STATUS computeScheduleWithTimeLimit(BspSchedule<Graph_t> &schedule, unsigned timeout) override {
637+
model.SetDblParam(COPT_DBLPARAM_TIMELIMIT, timeout);
638+
return computeSchedule(schedule);
639+
}
640+
635641
/**
636642
* @brief Compute the schedule for the given BspInstance using the COPT solver.
637643
*
@@ -662,13 +668,11 @@ class TotalCommunicationScheduler : public Scheduler<Graph_t> {
662668
loadInitialSchedule();
663669
}
664670

665-
model.SetDblParam(COPT_DBLPARAM_TIMELIMIT, Scheduler<Graph_t>::timeLimitSeconds);
671+
666672
model.SetIntParam(COPT_INTPARAM_THREADS, 128);
667-
668673
model.SetIntParam(COPT_INTPARAM_STRONGBRANCHING, 1);
669674
model.SetIntParam(COPT_INTPARAM_LPMETHOD, 1);
670675
model.SetIntParam(COPT_INTPARAM_ROUNDINGHEURLEVEL, 1);
671-
672676
model.SetIntParam(COPT_INTPARAM_SUBMIPHEURLEVEL, 1);
673677
// model.SetIntParam(COPT_INTPARAM_PRESOLVE, 1);
674678
// model.SetIntParam(COPT_INTPARAM_CUTLEVEL, 0);

include/osp/bsp/scheduler/ImprovementScheduler.hpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,6 @@ class ComboScheduler : public Scheduler<Graph_t> {
102102
ComboScheduler(Scheduler<Graph_t> &base, ImprovementScheduler<Graph_t> &improvement)
103103
: Scheduler<Graph_t>(), base_scheduler(base), improvement_scheduler(improvement) {}
104104

105-
virtual void setTimeLimitSeconds(unsigned int limit) override {
106-
107-
Scheduler<Graph_t>::timeLimitSeconds = limit;
108-
base_scheduler.setTimeLimitSeconds(limit);
109-
improvement_scheduler.setTimeLimitSeconds(limit);
110-
}
111-
112-
virtual void setTimeLimitHours(unsigned int limit) override {
113-
114-
Scheduler<Graph_t>::timeLimitSeconds = limit * 3600;
115-
base_scheduler.setTimeLimitHours(limit);
116-
improvement_scheduler.setTimeLimitHours(limit);
117-
}
118-
119105
virtual ~ComboScheduler() = default;
120106

121107
virtual std::string getScheduleName() const override {

include/osp/bsp/scheduler/LocalSearch/HillClimbing/hill_climbing.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ limitations under the License.
2222
#include "osp/bsp/scheduler/ImprovementScheduler.hpp"
2323
#include "osp/graph_algorithms/directed_graph_top_sort.hpp"
2424

25+
#include <chrono>
26+
2527
namespace osp{
2628

2729
template<typename Graph_t>

0 commit comments

Comments
 (0)