-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFineGrainWeights.cpp
69 lines (58 loc) · 1.98 KB
/
FineGrainWeights.cpp
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
#include "FineGrainWeights.hpp"
void FineGrainWeights::set_weights(Process &process, std::ofstream &ofs)
{
weights.clear();
for (unsigned int k=0; k<process.size(); k++)
weights.push_back(process[k]->get_weight());
std::sort(weights.begin(), weights.end());
std::reverse(weights.begin(), weights.end());
std::vector<unsigned int> order_idx;
ofs << "Descending order of applications considering their weights \r\n";
for (auto w:weights){
for (unsigned int k=0; k<process.size(); k++){
if (process[k]->get_weight()==w)
order_idx.push_back(k+1);
}
}
for (auto i:order_idx)
ofs << "[" << i << "] ";
ofs << "\r\n \r\n";
}
void FineGrainWeights::find_min(Process &process, std::ofstream &ofs)
{
unsigned int it = 0;
unsigned int max_it = 1000;
// if we have room, we remove one core at a time starting from the one that cost the more
if (process.total_real_time() < process.get_d()){
for (auto w:weights){
for (unsigned int k=0; k<process.size(); k++){
if (process[k]->get_weight()==w){
unsigned int u=0;
while (process.total_real_time() < process.get_d() && it<=max_it){
process[k]->set_n_core(process[k]->get_n_core()-1);
u++;
it++;
ofs << "Application " << k+1 << " nr. of cores: " << process[k]->get_n_core() << "\r\n";
}
if(u>0)
process[k]->set_n_core(process[k]->get_n_core()+1);
}
}
}
ofs << "\r\n \r\n";
}
// otherwise, we have to we add one core at a time (the one that cost less)
else {
it = 0;
for (unsigned int k=0; k<process.size(); k++){
if (process[k]->get_weight()==weights.back()){
while (process.total_real_time() >= process.get_d() && it<=max_it){
process[k]->set_n_core(process[k]->get_n_core()+1);
it++;
ofs << "Application " << k+1 << " nr. of cores: " << process[k]->get_n_core() << "\r\n";
}
}
}
ofs << "\r\n \r\n";
}
}