Skip to content

Commit 665abf1

Browse files
authored
Ilp timlimit fix (#71)
* timlimit fix * fix output recomp schedule
1 parent 915f4c2 commit 665abf1

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

apps/ilp_bsp_scheduler.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ using ComputationalDag = ComputationalDagEdgeIdxVectorImplDefIntT;
3838

3939
int main(int argc, char *argv[]) {
4040
if (argc < 4) {
41-
std::cerr << "Usage: " << argv[0] << " <input_file> <machine_file> <max_number_step> <optional:recomp>" << std::endl;
41+
std::cerr << "Usage: " << argv[0] << " <input_file> <machine_file> <max_number_step> [time_limit_seconds] [recomp]"
42+
<< std::endl;
4243
return 1;
4344
}
4445

@@ -57,17 +58,33 @@ int main(int argc, char *argv[]) {
5758
return 1;
5859
}
5960

61+
unsigned steps = static_cast<unsigned>(stepInt);
62+
63+
// Default time limit: 3600 seconds (1 hour)
64+
unsigned timeLimitSeconds = 3600;
6065
bool recomp = false;
6166

62-
if (argc > 4 && std::string(argv[4]) == "recomp") {
63-
recomp = true;
64-
} else if (argc > 4) {
65-
std::cerr << "Unknown argument: " << argv[4] << ". Expected 'recomp' for recomputation." << std::endl;
66-
return 1;
67+
// Parse optional arguments
68+
for (int i = 4; i < argc; ++i) {
69+
std::string arg = argv[i];
70+
if (arg == "recomp") {
71+
recomp = true;
72+
} else {
73+
// Try to parse as time limit
74+
try {
75+
int timeLimitInt = std::stoi(arg);
76+
if (timeLimitInt < 1) {
77+
std::cerr << "Argument time_limit_seconds must be a positive integer: " << timeLimitInt << std::endl;
78+
return 1;
79+
}
80+
timeLimitSeconds = static_cast<unsigned>(timeLimitInt);
81+
} catch (const std::exception &) {
82+
std::cerr << "Unknown argument: " << arg << ". Expected a time limit (integer) or 'recomp'." << std::endl;
83+
return 1;
84+
}
85+
}
6786
}
6887

69-
unsigned steps = static_cast<unsigned>(stepInt);
70-
7188
BspInstance<ComputationalDag> instance;
7289
ComputationalDag &graph = instance.GetComputationalDag();
7390

@@ -88,6 +105,9 @@ int main(int argc, char *argv[]) {
88105

89106
CoptFullScheduler<ComputationalDag> scheduler;
90107
scheduler.SetMaxNumberOfSupersteps(steps);
108+
scheduler.SetTimeLimitSeconds(timeLimitSeconds);
109+
110+
std::cout << "Time limit set to " << timeLimitSeconds << " seconds." << std::endl;
91111

92112
if (recomp) {
93113
BspScheduleRecomp<ComputationalDag> schedule(instance);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CoptFullScheduler : public Scheduler<GraphT> {
6767
bool writeSolutionsFound_;
6868
bool isMaxBsp_ = false;
6969

70-
unsigned timeLimitSeconds_ = 0;
70+
unsigned timeLimitSeconds_ = 3600;
7171

7272
const BspScheduleCS<GraphT> *initialSchedule_;
7373
const BspScheduleRecomp<GraphT> *initialScheduleRecomp_;
@@ -277,7 +277,7 @@ class CoptFullScheduler : public Scheduler<GraphT> {
277277

278278
for (unsigned node = 0; node < schedule.GetInstance().NumberOfVertices(); node++) {
279279
for (unsigned processor = 0; processor < schedule.GetInstance().NumberOfProcessors(); processor++) {
280-
for (unsigned step = 0; step < numberOfSupersteps - 1; step++) {
280+
for (unsigned step = 0; step < numberOfSupersteps; step++) {
281281
if (nodeToProcessorSuperstepVar_[node][processor][static_cast<int>(step)].Get(COPT_DBLINFO_VALUE) >= .99) {
282282
schedule.Assignments(node).emplace_back(processor, step);
283283
}
@@ -290,7 +290,7 @@ class CoptFullScheduler : public Scheduler<GraphT> {
290290
for (unsigned int pFrom = 0; pFrom < schedule.GetInstance().NumberOfProcessors(); pFrom++) {
291291
for (unsigned int pTo = 0; pTo < schedule.GetInstance().NumberOfProcessors(); pTo++) {
292292
if (pFrom != pTo) {
293-
for (unsigned int step = 0; step < maxNumberSupersteps_; step++) {
293+
for (unsigned int step = 0; step < numberOfSupersteps - 1; step++) {
294294
if (commProcessorToProcessorSuperstepNodeVar_[pFrom][pTo][step][static_cast<int>(node)].Get(
295295
COPT_DBLINFO_VALUE)
296296
>= .99) {

0 commit comments

Comments
 (0)