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 18fd4fc9 authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

New AlgOptions class

parent 348f4a33
......@@ -8,7 +8,7 @@ using namespace std;
typedef priority_queue<int, vector<int>, rankCompare> rankSet;
HeftAlgorithm::HeftAlgorithm(AlgOptions options) {
HeftAlgorithm::HeftAlgorithm(const AlgOptions &options): ranker(options) {
}
......@@ -23,7 +23,7 @@ string HeftAlgorithm::name() {
double HeftAlgorithm::compute(Instance& ins, SchedAction *action) {
int nbWorkers = getSum(ins.nbWorkers);
int n = ins.nbTasks;
vector<double> rank = ins.computeHEFTRank(); // TODO: an option for this.
vector<double> rank = ranker.computeRanks(ins);
vector< vector<int> > revDependencies = ins.getRevDependencies();
......
......@@ -11,17 +11,15 @@
class HeftAlgorithm : public Algorithm {
protected:
std::vector<double> computeRanks(Instance& ins);
std::vector<double> computeHEFTRank(Instance& ins);
std::vector<double> computeMinRank(Instance& ins);
RankComputer ranker;
public:
// List of options:
// Rank
//
HeftAlgorithm(const std::map<std::string, std::string> options);
HeftAlgorithm(const AlgOptions &options);
double compute(Instance& ins, SchedAction* action);
string name();
std::string name();
};
#endif
......@@ -9,7 +9,7 @@ using namespace std;
// TODO: test that it actually still works when used twice in a row with different instances.
HeteroPrio::HeteroPrio(map<string, string> options) {
HeteroPrio::HeteroPrio(const AlgOptions & options): ranker(options) {
// TODO: options: minRank, areaDistribution (requires CPLEX), Combined GPU, show steals, verbose
......@@ -20,7 +20,7 @@ string HeteroPrio::name() {
}
void HeteroPrio::init(Instance& ins) {
priorities = ins.computeHEFTRank();
priorities = ranker.computeRanks(ins);
rankCompare taskCmp(priorities, true);
rankSet protoQueue(taskCmp);
......
......@@ -8,7 +8,7 @@
#include "instance.h"
#include "algorithm.h"
#include "util.h"
typedef set<int, rankCompare> rankSet;
typedef std::set<int, rankCompare> rankSet;
class HeteroPrio : public Algorithm {
......@@ -49,6 +49,8 @@ class HeteroPrio : public Algorithm {
};
protected:
RankComputer ranker;
std::vector<double> priorities;
std::vector<taskInfo> tasks;
std::vector<workerInfo> workers;
......@@ -56,14 +58,15 @@ class HeteroPrio : public Algorithm {
std::vector<int> workerPollOrder; /* they are sorted by speedIndex */
std::set<event, evCmp> events;
vector< vector<int> > revDependencies;
std::vector< std::vector<int> > revDependencies;
void init(Instance& ins);
int performSteal(Instance &ins, int wType, int wLocalID, double currentTime);
public:
HeteroPrio(std::map<std::string, std::string> options);
HeteroPrio(const AlgOptions & options);
double compute(Instance& ins, SchedAction* action);
string name();
std::string name();
};
#endif
......@@ -7,19 +7,16 @@
using namespace std;
HybridBound::HybridBound(ModifiableBound *_alg, map<string, string> options) :
HybridBound::HybridBound(ModifiableBound *_alg, const AlgOptions &options) :
alg(_alg) {
auto verb_it = options.find("verbosity");
if(verb_it != options.end())
verbosity = stoi(verb_it->second);
auto tl_it = options.find("limit");
if(tl_it != options.end())
timeLimit = stoi(tl_it->second);
if(options.isPresent("verbosity"))
verbosity = options.asInt("verbosity");
if(options.isPresent("limit"))
timeLimit = options.asInt("limit");
}
string HybridBound::name() {
string mine = "Hybrid";
string mine = "Hybrid.";
return mine.append(alg->name());
}
......
......@@ -10,8 +10,9 @@ class HybridBound : public Bound {
int timeLimit;
public:
HybridBound(ModifiableBound *_alg, std::map<std::string, std::string> options); double compute(Instance&);
string name();
HybridBound(ModifiableBound *_alg, const AlgOptions &options);
double compute(Instance&);
std::string name();
};
......
......@@ -8,7 +8,7 @@ CCOPT = -DIL_STD
CCFLAGS = -Wall -g $(CCOPT)
LNFLAGS=
OBJS = pmtool.o schedAction.o listAlgorithm.o instance.o util.o HeftAlgorithm.o availSequence.o HybridBound.o HeteroPrio.o
OBJS = pmtool.o algoptions.o algorithm.o schedAction.o listAlgorithm.o instance.o util.o HeftAlgorithm.o availSequence.o HybridBound.o HeteroPrio.o
CPLEX_OBJS = AreaBound.o
......
#include "algoptions.h"
#include <vector>
#include <sstream>
using namespace std;
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
void AlgOptions::insert(const string & key, const string &value) {
emplace(key, value);
}
void AlgOptions::remove(const string& key) {
if(isPresent(key)) {
erase(key);
}
}
string AlgOptions::parseWithName(const string &line) {
vector<string> opts = split(line, ':');
auto it = opts.begin();
string name = *it;
for(it++; it < opts.end(); it++) {
vector<string> vals = split(*it, '=');
if(vals.size() > 1)
insert(vals[0], vals[1]);
else
insert(vals[0], "");
}
return name;
}
string AlgOptions::serialize () const {
// TODO. Use streambuf or sstream or something
return "";
}
bool AlgOptions::isPresent(const string& key) const {
auto opt = find(key);
return(opt != end());
}
string AlgOptions::asString(const string& key, const string& def) const {
auto opt = find(key);
if(opt == end()) return (def);
return(opt->second);
}
int AlgOptions::asInt(const string& key, const int def) const {
auto opt = find(key);
if(opt == end()) return(def);
return (stoi(opt->second));
}
double AlgOptions::asDouble(const string& key, const double def) const {
auto opt = find(key);
if(opt == end()) return(def);
return (stod(opt->second));
}
#ifndef ALGOPTIONS_H
#define ALGOPTIONS_H
#include <string>
#include <map>
class AlgOptions : public std::map<std::string, std::string> {
public:
void insert(const std::string &key, const std::string &value);
void remove(const std::string &key);
bool isPresent(const std::string& key) const;
std::string asString(const std::string &key, const std::string& def = "") const;
int asInt(const std::string &key, const int def = 0) const ;
double asDouble(const std::string &key, const double def = 0.0) const;
std::string parseWithName(const std::string &line);
std::string serialize() const;
};
#endif
......@@ -2,17 +2,29 @@
#define ALGORITHM_H
#include "instance.h"
#include "schedAction.h"
#include "algoptions.h"
#include <vector>
#include <string>
class Algorithm {
public:
virtual double compute(Instance& instance, SchedAction* action) = 0;
virtual string name() = 0 ;
virtual std::string name() = 0 ;
};
class RankComputer {
protected:
std::string rankOpt;
public:
std::vector<double> computeRanks(Instance& ins);
RankComputer(const AlgOptions &options);
};
class Bound {
public:
virtual double compute(Instance& instance)= 0;
virtual string name() = 0;
virtual std::string name() = 0;
};
class ModifiableBound : public Bound {
......
#ifndef INSTANCE_H
#define INSTANCE_H
#include <vector>
#include <vector>
#include <string>
class Instance {
public:
......
......@@ -24,26 +24,25 @@ int getType(int m, vector<int> nbWorkersPerType, int* index) {
}
vector<double> ListAlgorithm::computeRanks(Instance& ins) {
vector<double> w;
if(rankOpt == "heft")
w = ins.computeHEFTRank();
else if(rankOpt == "min")
w = ins.computeMinRank();
else {
cerr << "ListAlgorithm: unknown rank " << rankOpt << endl;
exit(-1);
}
return w;
}
// vector<double> ListAlgorithm::computeRanks(Instance& ins) {
// vector<double> w;
// if(rankOpt == "heft")
// w = ins.computeHEFTRank();
// else if(rankOpt == "min")
// w = ins.computeMinRank();
// else {
// cerr << "ListAlgorithm: unknown rank " << rankOpt << endl;
// exit(-1);
// }
// return w;
// }
// List of options:
// Rank
//
ListAlgorithm::ListAlgorithm(AlgOptions options) {
rankOpt = options.asString("rank", "heft");
ListAlgorithm::ListAlgorithm(const AlgOptions & options): ranker(options) {
}
static const string listAlgName = "list";
......@@ -55,7 +54,7 @@ string ListAlgorithm::name() {
double ListAlgorithm::compute(Instance& ins, SchedAction* action) {
// Compute ranks
vector<double> rank = computeRanks(ins);
vector<double> rank = ranker.computeRanks(ins);
int nbWorkers = getSum(ins.nbWorkers);
......
......@@ -8,16 +8,14 @@
#include "algorithm.h"
#include "algoptions.h"
class ListAlgorithm : public RankAlgorithm {
class ListAlgorithm : public Algorithm {
/* protected:
std::vector<double> computeRanks(Instance& ins);
string rankOpt;
*/
protected:
RankComputer ranker;
public:
ListAlgorithm(AlgOptions options);
ListAlgorithm(const AlgOptions &options);
double compute(Instance& ins, SchedAction* action);
string name();
std::string name();
};
#endif
......@@ -5,9 +5,9 @@
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#include <getopt.h>
#include "algoptions.h"
#include "instance.h"
#include "algorithm.h"
#include "listAlgorithm.h"
......@@ -36,46 +36,14 @@ static struct option long_options[] = {
};
static const char* optstring = "i:v:o:a:b:g:s";
static const char* optstring = "i:v:o:a:b:g:s:";
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
typedef pair<Algorithm*, AlgOptions> fullAlg;
typedef pair<Bound*, AlgOptions> fullBound;
typedef map<string, string> algopt;
typedef pair<Algorithm*, algopt> fullAlg;
typedef pair<Bound*, algopt> fullBound;
// TODO: include in an algOptions class, and
// take proper care of overwriting
string parseOptions(const string& s, algopt &result) {
vector<string> opts = split(s, ':');
auto it = opts.begin();
string name = *it;
for(it++; it < opts.end(); it++) {
vector<string> vals = split(*it, '=');
if(vals.size() > 1)
result.emplace(vals[0], vals[1]);
else
result.emplace(vals[0], "");
}
return name;
}
void displayAlgList() {
cout << "Algorithms avilable:" << endl;
cout << "list" << " " << "HEFT-list algorithm" <<endl;
......@@ -85,7 +53,7 @@ void displayAlgList() {
cout << "hetprio" << " " << "HeteroPrio algorithm" <<endl;
cout << " " << " " << "Options: rank, .." << endl;
}
Algorithm* createAlg(const string& name, const algopt& options) {
Algorithm* createAlg(const string& name, const AlgOptions& options) {
Algorithm* alg = NULL;
if(name == "heft")
alg = new HeftAlgorithm(options);
......@@ -108,7 +76,7 @@ void displayBoundList() {
#endif
}
Bound* createBound(const string& name, const algopt& options) {
Bound* createBound(const string& name, const AlgOptions& options) {
Bound* bound = NULL;
/* if(name == "DRA")
bound = new DRABound(parsedOptions);
......@@ -154,7 +122,7 @@ int main(int argc, char** argv) {
string input_file;
int convertIndices = 1;
// int outputValues = 0;
algopt globalOptions;
AlgOptions globalOptions;
int verbosity = 0;
vector<int> toMerge;
string saveFile;
......@@ -175,8 +143,8 @@ int main(int argc, char** argv) {
break;
case 'a':
{
algopt options = algopt(globalOptions);
string name = parseOptions(s_optarg, options);
AlgOptions options(globalOptions);
string name = options.parseWithName(s_optarg);
if(name == "show")
displayAlgList();
else
......@@ -185,8 +153,8 @@ int main(int argc, char** argv) {
}
case 'b':
{
algopt options = algopt(globalOptions);
string name = parseOptions(s_optarg, options);
AlgOptions options(globalOptions);
string name = options.parseWithName(s_optarg);
if(name == "show")
displayBoundList();
else
......@@ -194,10 +162,11 @@ int main(int argc, char** argv) {
break;
}
case 'g':
globalOptions.emplace("merge", s_optarg);
globalOptions.insert("merge", s_optarg);
break;
case 's':
globalOptions.emplace("save", s_optarg);
// globalOptions.insert("save", s_optarg);
saveFile = s_optarg;
break;
case opt_no_convert:
convertIndices = 0;
......@@ -237,10 +206,18 @@ int main(int argc, char** argv) {
cout << input_file << " " << ((*it).first)->name() << " " << result << endl;
}
ActionSequence seq;
ExportToFile* globalExport = NULL;
if(saveFile != "") {
globalExport = new ExportToFile(saveFile, &instance, true, "NA");
seq.add(globalExport);
}
// Iterate through algorithm list, execute all
for(auto it = algs.begin(); it < algs.end(); it++) {
auto opts = (*it).second;
auto opts = it->second;
// Instance* usedInstance = &instance;
// // Do the merge if required, starting from the original instance
// auto mergeOpt = opts.find("merge");
......@@ -248,21 +225,24 @@ int main(int argc, char** argv) {
// usedInstance = getMergedInstance(instance, mergeOpt->second);
// }
ActionSequence seq;
ExportToFile* e = NULL;
auto saveOpt = opts.find("save");
if(saveOpt != opts.end()) {
e = new ExportToFile(saveOpt->second, &instance, true);
seq.add(e);
ExportToFile* localExport = NULL;
if(opts.isPresent("save")) {
localExport = new ExportToFile(opts.asString("save"), &instance, true);
seq.add(localExport);
}
double result = (it->first)->compute(instance, &seq);
if(e) free(e);
if(globalExport)
globalExport->changeName(it->first->name());
double result = it->first->compute(instance, &seq);
// TODO: Which name should I use ?
cout << input_file << " " << ((*it).first)->name() << " " << result << endl;
cout << input_file << " " << it->first->name() << " " << result << endl;
if(localExport) free(localExport);
}
if(globalExport) free(globalExport);
return(0);
......
#include "schedAction.h"
#include <iostream>
using namespace std;
void ActionSequence::add(SchedAction* a) {
actions.push_back(a);
}
......
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