-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFineGrainDerivative
47 lines (42 loc) · 1.55 KB
/
FineGrainDerivative
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
#include "FineGrainDerivative.hpp"
void FineGrainDerivative::set_weights(Process &process)
{
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());
}
void FineGrainDerivative::find_min(Process &process)
{
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);
u++;
}
if(u>0)
process[k]->set_n_core(process[k]->get_n_core()+1);
}
set_weights(process);
}
}
}
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);
it++;
}
}
set_weights(process);
}
if (it==max_it+1)
std::cout << "While loop ended, reached max number of iterations" << std::endl;
}
}