-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFineGrainDerivative.cpp
67 lines (59 loc) · 2.32 KB
/
FineGrainDerivative.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
#include "FineGrainDerivative.hpp"
void FineGrainDerivative::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()/(process[k]->get_alpha()/double(process[k]->get_n_core()*(process[k]->get_n_core()-1))));
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()/(process[k]->get_alpha()/double(process[k]->get_n_core()*(process[k]->get_n_core()-1)))==w)
order_idx.push_back(k+1);
}
}
for (auto i:order_idx)
ofs << "[" << i << "] ";
ofs << "\r\n \r\n";
}
void FineGrainDerivative::find_min(Process &process, std::ofstream &ofs)
{
unsigned int it = 0;
unsigned int max_it = 10;
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()/(process[k]->get_alpha()/double(process[k]->get_n_core()*(process[k]->get_n_core()-1)))==w){
unsigned int u=0;
while (process.total_real_time() < process.get_d()){
process[k]->set_n_core(process[k]->get_n_core()-1);
ofs << "Application " << k+1 << " nr. of cores: " << process[k]->get_n_core() << "\r\n";
u++;
}
if(u>0)
process[k]->set_n_core(process[k]->get_n_core()+1);
}
}
ofs << "\r\n";
set_weights(process, ofs);
}
ofs << "\r\n \r\n";
}
else {
for (unsigned int k=0; k<process.size(); k++){
if (process[k]->get_weight()/(process[k]->get_alpha()/double(process[k]->get_n_core()*(process[k]->get_n_core()-1)))==weights.back()){
while (process.total_real_time() >= process.get_d() && it<=max_it){
process[k]->set_n_core(process[k]->get_n_core()+1);
ofs << "Application " << k+1 << " nr. of cores: " << process[k]->get_n_core() << "\r\n";
it++;
}
}
set_weights(process, ofs);
}
ofs << "\r\n \r\n";
// if (it==max_it+1)
// std::cout << "While loop ended, reached max number of iterations" << std::endl;
}
}