Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 1f6a2240 authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

getType is now a member of Instance ; Generalized usage of Instance::exec

parent 2cb2afde
......@@ -21,8 +21,8 @@ void AreaBound::clear() {
void AreaBound::init(Instance& inputIns) {
if(ins) clear();
ins = &inputIns;
nbWorkerTypes = ins->nbWorkers.size();
nbTaskTypes = ins->execTimes[0].size();
nbWorkerTypes = ins->nbWorkerTypes;
nbTaskTypes = ins->nbTaskTypes;
indepModel = IloModel(env);
qtityConstraints = IloRangeArray(env, nbTaskTypes);
......
......@@ -43,7 +43,12 @@ void DepBound::init(Instance& ins) {
for(j = 0; j < nbWorkerTypes; j++) {
IloExpr e(env);
for(i = 0; i < nbTasks; i++) {
e += wType[i][j] * instance->execTimes[j][instance->taskTypes[i]];
if(instance->isValidType(j, i)) {
e += wType[i][j] * instance->execType(j, i);
}
else {
idc.add(wType[i][j] == 0);
}
}
idc.add(e / instance->nbWorkers[j] <= load);
e.end();
......@@ -53,7 +58,7 @@ void DepBound::init(Instance& ins) {
for(i = 0; i < nbTasks; i++){
execTime[i] = IloExpr(env);
for(j = 0; j < nbWorkerTypes; j++)
execTime[i] += wType[i][j] * instance->execTimes[j][instance->taskTypes[i]];
execTime[i] += wType[i][j] * instance->execType(j, i);
}
// Dependencies
......
......@@ -85,7 +85,7 @@ double Dmdas::compute(Instance &ins, SchedAction* action) {
auto getFinishedTime = [&] (int task, int w) {
double s = max(endtimesWorkers[w], currentTime);
return (s + assignedLoad[w]
+ ins.exec(getType(w, ins.nbWorkers, NULL), task));
+ ins.execWorker(w, task));
};
auto getBestWorker = [&] (int task) {
......@@ -107,7 +107,7 @@ double Dmdas::compute(Instance &ins, SchedAction* action) {
cout << "dmdas @ " << currentTime << " assigning task " << task << " to worker " << w << endl;
}
localQueues[w]->insert(task);
assignedLoad[w] += ins.exec(getType(w, ins.nbWorkers, NULL), task);
assignedLoad[w] += ins.execWorker(w, task);
readyTasks->eraseFront();
};
......@@ -121,8 +121,8 @@ double Dmdas::compute(Instance &ins, SchedAction* action) {
for(int w = 0; w < nbWorkers; w++) {
if((endtimesWorkers[w] <= currentTime) && (!localQueues[w]->empty())) {
int task = localQueues[w]->front();
int wType = getType(w, ins.nbWorkers, NULL);
double finishTime = currentTime + ins.exec(wType, task);
int wType = ins.getType(w);
double finishTime = currentTime + ins.execType(wType, task);
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;
......@@ -131,7 +131,7 @@ double Dmdas::compute(Instance &ins, SchedAction* action) {
action->onSchedule(task, w, currentTime, finishTime);
localQueues[w]->eraseFront();
assignedLoad[w] -= ins.exec(wType, task);
assignedLoad[w] -= ins.execType(wType, task);
endtimesWorkers[w] = finishTime;
endtimesTasks[task] = finishTime;
}
......
......@@ -61,26 +61,9 @@ double HeftAlgorithm::compute(Instance& ins, SchedAction *action) {
double bestStart = -1;
int bestK = 0; int bestT = 0;
timeSeq::iterator bestPeriod; // Should belond to workerAvailability[bestK]
int targetType = -1;
/* if((action != NULL) && ((targetType = action->chooseType(i, queue->size())) >= 0)) {
k = 0;
for(t = 0; t < targetType; t++) k += ins.nbWorkers[t];
for(j = 0; j < ins.nbWorkers[targetType]; j++, k++) {
double e = -1; double l = ins.execTimes[targetType][ins.taskTypes[i]];
timeSeq::iterator p = workerAvailability[k].getAvail(depTime, l, e);
if(e +l < bestTime){
bestK = k;
bestTime = e + l;
bestStart = e;
bestPeriod = p;
bestT = targetType;
}
}
} else { */
for(t = 0; t < (int) ins.nbWorkers.size(); t++) {
for(t = 0; t < ins.nbWorkerTypes; t++) {
for(j = 0; j < ins.nbWorkers[t]; j++, k++) {
// TODO: remove copy-paste ?
double e = -1; double l = ins.execTimes[t][ins.taskTypes[i]];
double e = -1; double l = ins.execType(t, i);
timeSeq::iterator p = workerAvailability[k].getAvail(depTime, l, e);
if(e +l < bestTime){
bestK = k;
......@@ -91,7 +74,6 @@ double HeftAlgorithm::compute(Instance& ins, SchedAction *action) {
}
}
}
//}
double startTime = bestStart;
if(verbosity >= 3)
......@@ -100,7 +82,7 @@ double HeftAlgorithm::compute(Instance& ins, SchedAction *action) {
if(action != NULL) {
action->onSchedule(i, bestK, startTime, bestTime);
}
workerAvailability[bestK].insertBusy(bestPeriod, startTime, ins.execTimes[bestT][ins.taskTypes[i]]);
workerAvailability[bestK].insertBusy(bestPeriod, startTime, ins.execType(bestT, i));
endtimesTasks[i] = bestTime;
for(j = 0; j < (int) revDependencies[i].size(); j++) {
......
......@@ -146,7 +146,7 @@ int HeteroPrio::performSteal(Instance &ins, int wType, int wLocalID, double curr
currentInfo &l = *candIt;
taskInfo &c = tasks[l.taskID];
if(c.startTime + c.duration
> currentTime + ins.execTimes[wType][ins.taskTypes[l.taskID]]) {
> currentTime + ins.execType(wType, l.taskID)) {
if(verbosity >= 4)
cout << "HP: stealing task " << l.taskID << " from worker " << workers[l.wType].firstID + l.wLocalID << endl;
......@@ -240,7 +240,7 @@ double HeteroPrio::compute(Instance& ins, SchedAction* action) {
if(t != -1) {
// Schedule chosen task
tasks[t].startTime = currentTime;
tasks[t].duration = ins.execTimes[*wkPollit][ins.taskTypes[t]];
tasks[t].duration = ins.execType(*wkPollit, t);
double endDate = tasks[t].startTime + tasks[t].duration;
events.emplace(t, endDate, *wkPollit, w.firstID + idleLocalID);
w.runningTasks ++;
......
......@@ -22,8 +22,8 @@ double HybridBound::compute(Instance& ins) {
int i, j;
int nbTask = ins.nbTasks;
int nbTaskTypes = ins.execTimes[0].size();
int nbWorkerTypes = ins.execTimes.size();
int nbTaskTypes = ins.nbTaskTypes;
int nbWorkerTypes = ins.nbWorkerTypes;
vector<int> topOrder = ins.getTopOrder();
vector< vector<int> > revDep = ins.getRevDependencies();
......
......@@ -19,10 +19,10 @@ const int IA_CPU = 0;
const int IA_GPU = 1;
double gpuTime(Instance& ins, int t) {
return ins.exec(IA_GPU, t);
return ins.execType(IA_GPU, t);
}
double cpuTime(Instance& ins, int t) {
return ins.exec(IA_CPU, t);
return ins.execType(IA_CPU, t);
}
bool IndepAccel::tryGuess(Instance& ins, std::vector<int> taskSet, double target, IndepResult& result) {
......@@ -32,7 +32,7 @@ bool IndepAccel::tryGuess(Instance& ins, std::vector<int> taskSet, double target
vector<int> setG1, setG2, setC1, setC2;
for(auto t: taskSet) {
if(ins.execTimes[IA_CPU][ins.taskTypes[t]] <= target)
if(ins.execType(IA_CPU, t) <= target)
setC2.push_back(t);
else
setG1.push_back(t);
......@@ -155,10 +155,10 @@ IndepResult IndepAccel::compute(Instance& instance, vector<int> taskSet, vector<
if(verbosity >= 4) {
cout << "IndepAccel: called with TS=" << taskSet << " and loads=" << loads << endl;
cout << " CPU times: ";
for(int i : taskSet) cout << instance.execTimes[0][instance.taskTypes[i]] << " ";
for(int i : taskSet) cout << instance.execType(0, i) << " ";
cout << endl;
cout << " GPU times: ";
for(int i : taskSet) cout << instance.execTimes[1][instance.taskTypes[i]] << " ";
for(int i : taskSet) cout << instance.execType(1, i) << " ";
cout << endl;
}
......
......@@ -55,7 +55,7 @@ public:
}
void onSchedule(int task, int worker, double start, double end) {
int t = getType(worker, instance.nbWorkers, NULL);
int t = instance.getType(worker);
allocated[t].erase(find(allocated[t].begin(), allocated[t].end(), task));
endtimesWorkers[worker] = end;
}
......@@ -177,7 +177,7 @@ public:
if(do_sort)
for(int i = 0; i < instance.nbWorkerTypes; i++)
sort(allocated[i].begin(), allocated[i].end(), [&](int a, int b) {
return instance.execTimes[i][instance.taskTypes[a]] > instance.execTimes[i][instance.taskTypes[b]];
return instance.execType(i, a) > instance.execType(i, b);
});
}
......
......@@ -105,10 +105,10 @@ IndepResult IndepDP2::compute(Instance& instance, vector<int> taskSet, vector<do
if(verbosity >= 4) {
cout << "IndepDP2: called with TS=" << taskSet << " and loads=" << loads << endl;
cout << " CPU times: ";
for(int i : taskSet) cout << instance.execTimes[0][instance.taskTypes[i]] << " ";
for(int i : taskSet) cout << instance.execType(0, i) << " ";
cout << endl;
cout << " GPU times: ";
for(int i : taskSet) cout << instance.execTimes[1][instance.taskTypes[i]] << " ";
for(int i : taskSet) cout << instance.execType(1, i) << " ";
cout << endl;
}
......
......@@ -27,19 +27,19 @@ bool IndepDualHP::tryGuess(Instance& instance, std::vector<int> taskSet, vector<
std::vector<int> remaining;
// First: assign tasks that need can not go to one resource to the other.
for(int t: taskSet) {
if(instance.exec(0, t) > lambda) {
if(instance.exec(1, t) > lambda) {
if(instance.execType(0, t) > lambda) {
if(instance.execType(1, t) > lambda) {
if(verbosity >= 4)
cout << "IndepDualHP: guess " << lambda << " infeasible because task " << t << " too long on both resources" << endl;
return false;
} else {
result[1].push_back(t);
tmploads[1] += instance.exec(1, t);
tmploads[1] += instance.execType(1, t);
}
} else {
if(instance.exec(1, t) > lambda) {
if(instance.execType(1, t) > lambda) {
result[0].push_back(t);
tmploads[0] += instance.exec(0, t);
tmploads[0] += instance.execType(0, t);
} else {
remaining.push_back(t);
}
......@@ -48,7 +48,7 @@ bool IndepDualHP::tryGuess(Instance& instance, std::vector<int> taskSet, vector<
// For remaining tasks: sort them by acceleration factor, fill the GPU until more than lambda load.
std::function<double(int)> accel = [&] (int a) {
return (instance.exec(0, a) / instance.exec(1, a));
return (instance.execType(0, a) / instance.execType(1, a));
};
std::function<bool(int, int)> accelCmp = [&] (int a, int b) {
return ( accel(a) > accel(b) );
......@@ -60,14 +60,14 @@ bool IndepDualHP::tryGuess(Instance& instance, std::vector<int> taskSet, vector<
auto it = remaining.begin();
while(it != remaining.end() && tmploads[1] < nbGPU * lambda) {
result[1].push_back(*it);
tmploads[1] += instance.exec(1, *it);
tmploads[1] += instance.execType(1, *it);
++it;
}
// Then: remaining tasks go on CPU, guess is valid iff CPU load is not exceeded.
while(it != remaining.end()) {
result[0].push_back(*it);
tmploads[0] += instance.exec(0, *it);
tmploads[0] += instance.execType(0, *it);
++it;
}
......@@ -86,10 +86,10 @@ IndepResult IndepDualHP::compute(Instance& instance, vector<int> taskSet, vector
if(verbosity >= 4) {
cout << "IndepDualHP: called with TS=" << taskSet << " and loads=" << loads << endl;
cout << " CPU times: ";
for(int i : taskSet) cout << instance.execTimes[0][instance.taskTypes[i]] << " ";
for(int i : taskSet) cout << instance.execType(0, i) << " ";
cout << endl;
cout << " GPU times: ";
for(int i : taskSet) cout << instance.execTimes[1][instance.taskTypes[i]] << " ";
for(int i : taskSet) cout << instance.execType(1, i) << " ";
cout << endl;
}
......
......@@ -67,7 +67,7 @@ double IterDepBound::compute() {
if(not isRemoved[i]) {
idcCplex.getValues(weights[i], wType[i]);
for(j = 0; j < nbWorkerTypes; j++)
weights[i][j] = weights[i][j] * instance->execTimes[j][instance->taskTypes[i]];
weights[i][j] = weights[i][j] * instance->execType(j, i);
}
}
int s = -1, t = -1;
......
......@@ -81,6 +81,21 @@ void Instance::display(int verbosity) {
}
int Instance::getType(int m, int* index) {
int i;
for(i = 0; i < (int) nbWorkerTypes; i++) {
if(m < nbWorkers[i]){
if (index != NULL)
*index = m;
return i;
} else
m -= nbWorkers[i];
}
// That's an error if I get here: m was higher than total nb of workers.
throw(-1);
}
void Instance::autoMerge(double tolerance /*default = 0.01*/ ) {
bool hasChanged = true;
......
......@@ -3,6 +3,7 @@
#include <vector>
#include <string>
#include <limits>
class Instance {
public:
......@@ -30,10 +31,24 @@ public:
Instance();
public:
Instance(const std::string input_file, int convertIndices);
inline double exec(int wType, int task) {
int getType(int m, int* index = NULL);
inline double execType(int wType, int task) {
return execTimes[wType][taskTypes[task]];
}
inline bool isValidType(int wType, int task) {
return (execType(wType, task) != std::numeric_limits<double>::infinity());
}
inline double execWorker(int w, int task) {
return execType(getType(w), task);
}
inline bool isValidWorker(int w, int task) {
return isValidType(getType(w), task);
}
void display(int verbosity);
void autoMerge(double tolerance = 0.10);
void mergeWorkerTypes(std::vector<int> indicesToMerge);
......
......@@ -92,7 +92,7 @@ double ListAlgorithm::compute(Instance& ins, SchedAction* action) {
while(tasksToSchedule > 0) {
int index = 0;
int t = getType(idle, ins.nbWorkers, &index);
int t = ins.getType(idle, &index);
int chosenTask = -1;
bool chosenFromFront = false;
......@@ -115,7 +115,7 @@ double ListAlgorithm::compute(Instance& ins, SchedAction* action) {
readyTasks->eraseFront();
else
readyTasks->erase(chosenTask);
double finishTime = currentTime + ins.execTimes[t][ins.taskTypes[chosenTask]];
double finishTime = currentTime + ins.execType(t, chosenTask);
if(verbosity >= 1)
cout << "List: starting " << chosenTask << " of type " << ins.taskTypes[chosenTask] << " at " << currentTime << " to end at " << finishTime << " on worker " << idle << " of type " << t << endl;
tasksToSchedule --;
......
......@@ -76,7 +76,7 @@ UtilAnalysis::~UtilAnalysis(){
}
void UtilAnalysis::onSchedule(int i, int w, double s, double f) {
repartition[getType(w, ins->nbWorkers, NULL)][ins->taskTypes[i]] += 1;
repartition[ins->getType(w)][ins->taskTypes[i]] += 1;
}
std::vector<std::vector<int> > UtilAnalysis::getRepartition() {
......
......@@ -30,18 +30,5 @@ bool readThisChar(istream &input, char c) {
}
int getType(int m, vector<int> nbWorkersPerType, int* index) {
int i;
for(i = 0; i < (int) nbWorkersPerType.size(); i++) {
if(m < nbWorkersPerType[i]){
if (index != NULL)
*index = m;
return i;
} else
m -= nbWorkersPerType[i];
}
// That's an error if I get here: m was higher than total nb of workers.
throw(-1);
}
......@@ -19,9 +19,6 @@ bool readChar(std::istream &input, char &c);
bool readThisChar(std::istream &input, char c);
int getType(int m, std::vector<int> nbWorkersPerType, int* index);
template <class T> int readArray(std::istream &input, std::vector<T> &v);
template<class T> std::ostream& operator<<(std::ostream& out, std::vector<T> v);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment