-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
152 lines (123 loc) · 3.47 KB
/
Copy pathmain.cpp
File metadata and controls
152 lines (123 loc) · 3.47 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <complex>
using namespace std;
#include "utils/matrix_exponential.hpp"
#include "utils/test_matrix_exponential.hpp"
#include "utils/c8lib.hpp"
#include "utils/r8lib.hpp"
#include "CMI.h"
//#include "performance_counter/PerformanceCounters.h"
#include "utils/Parser.h"
#include "utils/utils.h"
#include "utils/FileOperator.h"
#include "UnitTest/UnitTest.h"
void displayAllQueues(std::vector <std::vector <Task *> > queues)
{
for (int i = 0; i < (int)queues.size(); ++i)
{
for (int j = 0; j < (int)queues[i].size(); ++j)
{
cout << "Task: " << queues[i][j]->getTaskId() <<
" Job: " << queues[i][j]->getId() << " *** ";
}
cout << endl << "----------------------------------------------" << endl;
}
}
void test_online_approach1(CMI *cmi, const DynamicInfo& p, std::vector <StateTable>& c)
{
unsigned long t = cmi->getRelativeTimeUsec();
if (t > 3000000)
{
if (p.coreinfos[0].onGoJobId > 0)
{
cmi->displayAllQueues();
cout << "task migration " << endl;
cmi->taskMigrate(0, 2);
cmi->displayAllQueues();
}
}
}
void test_online_approach2(CMI *cmi, const DynamicInfo& p, std::vector <StateTable>& c)
{
if (p.tasksInQueue[0].size() > 10)
{
cmi->displayAllQueues();
cout << "task move" << endl;
cmi->moveJobToAnotherQueue(0, 2, 1, 2);
cmi->moveJobToAnotherQueue(0, 4, 2, 3);
cmi->displayAllQueues();
}
}
void test_online_approach3(CMI *cmi, const DynamicInfo& p, std::vector <StateTable>& c)
{
if (p.tasksInQueue[0].size() > 10)
{
cmi->displayAllQueues();
cout << "task advance" << endl;
cmi->advanceJobInQueue(0, 8, 9);
cmi->advanceJobInQueue(2, 4, 2);
cmi->displayAllQueues();
}
}
int test_online_task_allocator(CMI *cmi, int _taskId)
{
return(_taskId);
}
int main(int argc, char **argv)
{
/******************* PARSE INPUT ARGUMENTS *******************/
string file;
int isAppendSaveFile = 0;
if (argc > 1)
{
for (int i = 1; i <= argc; i++)
{
if (argv[i] == NULL)
{
continue;
}
if (argv[i] == string("-a"))
{
i++;
isAppendSaveFile = atoi(argv[i]);
}
else
{
file = string(argv[i]);
if (file.find(".xml") == string::npos)
{
file = file + ".xml";
}
}
}
}
else
{
file = "example.xml";
}
// create the experiment
CMI *cmi = new CMI(file, isAppendSaveFile);
/******************* SETTINGS ABOUT THE EXPERIMENT *******************/
// Modify below functions to customize the experiment
/* Set dynamic thermal approach*/
// cmi->setOnlineThermalApproach(test_online_approach1);
/* Set the period of online thermal approach*/
// cmi->setOnlineThermalApproachPeriod(200000);
/* Statically set the cores that tasks should be executed*/
// vector<int> ids = cmi->getAllTaskIds();
// for (int i = 0; i < (int)ids.size(); ++i)
// {
// cmi->setTaskRunningCore(ids[i], 0);
// }
/* Or define an online task allocator to replace the static task allocator*/
cmi->setOnlineTaskAllocator(test_online_task_allocator);
/******************* START THE EXPERIMENT *******************/
cmi->initializeComponents();
cmi->startRunning();
delete cmi;
return(0);
}