...
 
Commits (2)
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "instance.h" #include "instance.h"
#include "algorithm.h" #include "algorithm.h"
#include "algoptions.h" #include "algoptions.h"
#include "listAlgorithm.h"
class Dmdas : public Algorithm { class Dmdas : public Algorithm {
......
#include "Dmdas.h" #include "Dmdas.h"
#include "listAlgorithm.h"
#include "util.h" #include "util.h"
#include <vector> #include <vector>
...@@ -81,24 +80,32 @@ double Dmdas::compute(Instance &ins, SchedAction* action) { ...@@ -81,24 +80,32 @@ double Dmdas::compute(Instance &ins, SchedAction* action) {
// For now keep the "old" version of dmdas where the assigned load also // For now keep the "old" version of dmdas where the assigned load also
// counts lower priority tasks // counts lower priority tasks
auto getFinishedTime = [&] (int task, int w) { auto getFinishedTime = [&] (int task, int w, int wType) {
if(ins.isValidWorker(w, task)) { double execTime = ins.execType(wType, task);
if(ins.isValidValue(execTime)) {
double s = max(endtimesWorkers[w], currentTime); double s = max(endtimesWorkers[w], currentTime);
return (s + assignedLoad[w] return (s + assignedLoad[w]
+ ins.execWorker(w, task)); + execTime);
} else } else
return std::numeric_limits<double>::infinity(); return std::numeric_limits<double>::infinity();
}; };
auto getBestWorker = [&] (int task) { auto getBestWorker = [&] (int task) {
double bestSoFar = getFinishedTime(task, 0); double bestSoFar = std::numeric_limits<double>::infinity();
int bestWorker = 0; int bestWorker = -1;
for(int i = 1; i < nbWorkers; i++) { int i = 0;
double t = getFinishedTime(task, i); for(int wType = 0; wType < ins.nbWorkerTypes; ++wType) {
if(t < bestSoFar) { for(int j = 0; j < ins.nbWorkers[wType]; ++j, ++i) {
bestSoFar = t; bestWorker = i; double t = getFinishedTime(task, i, wType);
if(t < bestSoFar) {
bestSoFar = t; bestWorker = i;
}
} }
} }
if(bestWorker < 0) {
cerr << "Dmdas: no valid worker for task " << task << endl;
throw(1);
}
return bestWorker; return bestWorker;
}; };
...@@ -115,31 +122,34 @@ double Dmdas::compute(Instance &ins, SchedAction* action) { ...@@ -115,31 +122,34 @@ double Dmdas::compute(Instance &ins, SchedAction* action) {
// int idle = wStartIndex[wTypeOrdering[0]]; // int idle = wStartIndex[wTypeOrdering[0]];
while(tasksToSchedule > 0) { while(tasksToSchedule > 0) {
while(!readyTasks->empty()) while(!readyTasks->empty())
assignFront(); assignFront();
for(int w = 0; w < nbWorkers; w++) { int w = 0;
if((endtimesWorkers[w] <= currentTime) && (!localQueues[w]->empty())) { for(int wType = 0; wType < ins.nbWorkerTypes; ++wType) {
int task = localQueues[w]->front(); for(int j = 0; j < ins.nbWorkers[wType]; ++j, ++w) {
int wType = ins.getType(w); if((endtimesWorkers[w] <= currentTime) && (!localQueues[w]->empty())) {
double finishTime = currentTime + ins.execType(wType, task); int task = localQueues[w]->front();
if(verbosity >= 1) double finishTime = currentTime + ins.execType(wType, task);
cout << "dmdas: starting " << task << " of type " << ins.taskTypes[task] << " at " << currentTime << " to end at " << finishTime << " on worker " << w << " of type " << wType << endl; if(verbosity >= 1)
cout << "dmdas: starting " << task << " of type " << ins.taskTypes[task] << " at " << currentTime << " to end at " << finishTime << " on worker " << w << " of type " << wType << endl;
tasksToSchedule --; tasksToSchedule --;
if(action != NULL) if(action != NULL)
action->onSchedule(task, w, currentTime, finishTime); action->onSchedule(task, w, currentTime, finishTime);
localQueues[w]->eraseFront(); localQueues[w]->eraseFront();
assignedLoad[w] -= ins.execType(wType, task); assignedLoad[w] -= ins.execType(wType, task);
endtimesWorkers[w] = finishTime; endtimesWorkers[w] = finishTime;
endtimesTasks[task] = finishTime; endtimesTasks[task] = finishTime;
currentRunningTask[w] = task; currentRunningTask[w] = task;
}
} }
} }
double nextTime = -1; double nextTime = -1;
for(int w = 0; w < nbWorkers; w++) { for(int w = 0; w < nbWorkers; w++) {
if((endtimesWorkers[w] > currentTime) && if((endtimesWorkers[w] > currentTime) &&
...@@ -163,8 +173,7 @@ double Dmdas::compute(Instance &ins, SchedAction* action) { ...@@ -163,8 +173,7 @@ double Dmdas::compute(Instance &ins, SchedAction* action) {
cout << "List: Finishing task " << i << " at time " << currentTime << endl; cout << "List: Finishing task " << i << " at time " << currentTime << endl;
finishedTasks[i] = true; finishedTasks[i] = true;
currentRunningTask[j] = -1; currentRunningTask[j] = -1;
for(int j = 0; j < (int) revDependencies[i].size(); j++) { for(int & k: revDependencies[i]) {
int k = revDependencies[i][j];
nbDep[k]--; nbDep[k]--;
if(verbosity >= 7) if(verbosity >= 7)
cout << " Dependent task: " << k << " remaining dependencies: " << nbDep[k] << endl; cout << " Dependent task: " << k << " remaining dependencies: " << nbDep[k] << endl;
......