Commit fcca1a74 authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

New algorithm truehp for faster running times when there are many types of tasks

parent 540d2ec1
......@@ -2,6 +2,7 @@
#include <getopt.h>
#include <iostream>
#include <OnlineZhang.h>
#include <TrueHeteroPrio.h>
#include "algorithm.h"
#include "listAlgorithm.h"
......@@ -282,6 +283,8 @@ Algorithm* createAlg(const string& name, const AlgOptions& options) {
alg = new ListAlgorithm(options);
if(name == "hetprio")
alg = new HeteroPrio(options);
if(name == "truehp")
alg = new TrueHeteroPrio(options);
if(name == "indep")
alg = makeIndep(options);
if(name == "dmdas")
......
......@@ -250,6 +250,13 @@ finish before the victim.
if the best suited available task is less suited than a steal
candidate, steal it. Should be paired with `ssbaf` to make
sense.
#### True Hetero Prio
There is another implementation of heteroprio called `truehp`, restricted to the case of 2 types of processors.
It is faster when there are many types of tasks (and thus few tasks of each type) because it
stores all tasks in one queue order by acceleration factor, whereas `hetprio` maintains one queue
per type of task, ordered according to its `rank` option. `truehp` does not accept any option for now.
### indep
......
//
// Created by eyraud on 25/07/18.
//
#ifndef PMTOOL_TRUEHETEROPRIO_H
#define PMTOOL_TRUEHETEROPRIO_H
#include "GreedyAlgorithm.h"
class TrueHeteroPrio : public GreedyAlgorithm {
private:
RankComputer ranker;
std::set<int, strictCompare> *taskSet;
Instance* ins;
public:
double compute(Instance &ins, SchedAction *action) override;
TrueHeteroPrio(const AlgOptions &options);
int chooseTask(int worker, double now) override;
void onTaskPush(int task, double now) override;
};
#endif //PMTOOL_TRUEHETEROPRIO_H
......@@ -15,7 +15,7 @@ set(SCHED_SRC
availSequence.cpp
GreedyAlgorithm.cpp
HeftAlgorithm.cpp
OnlineZhang.cpp ../include/OnlineZhang.h GreedyPerType.cpp ../include/GreedyPerType.h)
OnlineZhang.cpp ../include/OnlineZhang.h GreedyPerType.cpp ../include/GreedyPerType.h TrueHeteroPrio.cpp ../include/TrueHeteroPrio.h)
if(CPLEX_FOUND)
set(SCHED_SRC ${SCHED_SRC} SchedLPIndep.cpp ../include/SchedLPIndep.h AreaRound.cpp ../include/AreaRound.h)
......
//
// Created by eyraud on 25/07/18.
//
#include <iostream>
#include "TrueHeteroPrio.h"
using namespace std;
int TrueHeteroPrio::chooseTask(int worker, double now) {
int wType = ins->getType(worker);
if(taskSet->empty()) {
int bestTask = -1;
int chosenVictim = -1;
// Steal: copy/paste from GreedyPerType
for (int victim = 0; victim < ins->totalWorkers; victim++) {
int victimType = ins->getType(victim);
// ins->getType not efficient, but easier to read
if (victimType != wType && runningTasks[victim] != -1
&& ins->isValidType(wType, runningTasks[victim])
&& now + ins->execType(wType, runningTasks[victim]) < endTimesWorkers[victim]) {
int task = runningTasks[victim];
double taskAF = ins->execType(victimType, task) / ins->execType(wType, task);
double bestAF = ins->execType(victimType, bestTask) / ins->execType(wType, bestTask);
if (bestTask == -1 || (taskAF > bestAF) ) {
bestTask = task;
chosenVictim = victim;
}
}
}
if (bestTask != -1) {
runningTasks[chosenVictim] = -1;
return bestTask;
} else {
return -1;
}
} else {
auto pos = taskSet->begin();
if (wType == 0) {
pos = taskSet->end();
--pos;
}
int task = *pos;
taskSet->erase(pos);
return task;
}
}
void TrueHeteroPrio::onTaskPush(int task, double now) {
taskSet->insert(task);
}
double TrueHeteroPrio::compute(Instance &ins, SchedAction *action) {
if(ins.nbTaskTypes != 2) {
cerr << "TrueHeteroPrio: only works with two worker types" << endl;
throw(1);
}
vector<double> accelFactors(ins.nbTasks);
for(int i = 0; i < ins.nbTasks; i++)
accelFactors[i] = ins.execType(0, i) / ins.execType(1, i);
rankCompare compareByAccelFactor = rankCompare(accelFactors);
strictCompare strict(&compareByAccelFactor, false);
taskSet = new set<int, strictCompare>(strict);
this->ins = &ins;
return GreedyAlgorithm::compute(ins, action);
}
TrueHeteroPrio::TrueHeteroPrio(const AlgOptions &options) : GreedyAlgorithm(options), ranker(options) {
}
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