-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskSim.cxx
98 lines (77 loc) · 2.81 KB
/
TaskSim.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "Scheduler.hxx"
#include "Loader.hxx"
#include <list>
#include <iostream>
#include <fstream>
#include <string>
#include <boost/program_options/option.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
namespace po = boost::program_options;
po::variables_map vm;
//int Task::taskIdGen = 1;
int main(int argc, char **argv) {
// Parse program options
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "Produce this help message")
("strategy,s", po::value<std::string>(), "Scheduling strategy. Valid values are rr, edf, priority, sjf, and fifo")
("cores,c", po::value<int>(), "Number of parallel virtual \"tasks\" to run")
("input-file,i", po::value<std::string>(), "Input file with list of tasks")
("output-file,o", po::value<std::string>(), "Output file. Default: standard output")
("verbose,v", "Enables step by step output")
;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << desc << "\n";
return 0;
}
std::ofstream outFile;
if (vm.count ("output-file")) {
freopen(vm["output-file"].as<std::string>().c_str(),"w",stdout);
}
int cores = 1;
if (vm.count("cores")) {
cores=vm["cores"].as <int> ();
}
bool verbose = false;
if(vm.count("verbose")) {
verbose = true;
}
Schedule* schedule = NULL;
Scheduler scheduler(cores, verbose);
if (!vm.count ("strategy")) {
schedule = new Schedule(scheduler.getTaskQueue());
}else{
std::string strategy=vm["strategy"].as < std::string > ();
if(strategy=="rr"){
schedule = new RR_Schedule(scheduler.getTaskQueue());
}else if(strategy=="edf"){
schedule = new EDF_Schedule(scheduler.getTaskQueue());
}else if(strategy=="priority"){
schedule = new Priority_Schedule(scheduler.getTaskQueue());
}else if(strategy=="sjf"){
schedule = new SJF_Schedule(scheduler.getTaskQueue());
}else if(strategy=="fifo"){
schedule = new Schedule(scheduler.getTaskQueue());
}
}
if(schedule == NULL) {
std::cerr<<"Invalid strategy provided. Terminating program...\n";
return -1;
}
if (!vm.count ("input-file")) {
std::cerr<<"No input file provided. Terminating program...\n";
return -1;
}
std::string inFile=vm["input-file"].as < std::string > ();
scheduler.setSchedule(schedule);
Loader loader(scheduler.getTaskQueue(),inFile);
for(int i = 0;scheduler.getTaskQueue()->size()||scheduler.getBlockedQueue()->size()||i<5;i++) {
loader.update(i);
scheduler.updateTasks(1);
}
scheduler.logOutput();
return 0;
}