-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.cpp
127 lines (111 loc) · 3.12 KB
/
Application.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
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
#include "Application.hpp"
void Application::set_id(const std::string& id){
id_application = id;
}
void Application::add_job(Job j){
jobs.push_back(j);
}
void Application::add_stage(Stage s){
stages.push_back(s);
}
Job::time_instant Application::execution_time_avg() const{
//return the approximate execution time_instant
//this method uses the following formula: sum of wave * stage average time
Job::time_instant sum = 0;
for(auto s : stages){
if(s.get_n_tasks() % n_core != 0){
sum += s.get_avg();
}
unsigned coeff = s.get_n_tasks()/n_core;
sum += coeff * s.get_avg();
}
return sum;
}
Job::time_instant Application::execution_time_avg(unsigned int n) const{
//return the approximate execution time_instant
//this method uses the following formula: sum of wave * stage average time
Job::time_instant sum = 0;
for(auto s : stages){
if(s.get_n_tasks() % n != 0){
sum += s.get_avg();
}
unsigned coeff = s.get_n_tasks()/n;
sum += coeff * s.get_avg();
}
return sum;
}
void Application::print() const{
std::cout << "Application name: " << id_application << '\n';
std::cout << "dead: " << deadline << '\n';
}
void Application::print_job() const{
print();
for(auto j : jobs){
j.printj();
}
}
void Application::print_stage() const{
// print();
//print_job();
for(auto s : stages){
s.prints();
}
}
Application& Application::operator=(const Application& app){
id_application = app.get_id_app();
submission_time = app.get_submission_time();
deadline = app.get_deadline();
jobs = app.get_jobs();
stages = app.get_stages();
alpha = app.get_alpha();
beta = app.get_beta();
n_core = app.get_n_core();
n_core_log = app.get_n_core_log();
real_execution_time = app.get_real_execution_time();
weight = app.get_weight();
return *this;
}
void Application::set_alpha_beta(unsigned int n1, unsigned int n2){
if (n1 == n2){
std::cerr << "n1 = n2" << '\n';
return;
}
if(n1 > n2){
Job::time_instant r1 = execution_time_avg(n2);
Job::time_instant r2 = execution_time_avg(n1);
alpha = double(r1-r2) * n1 * n2/(n1-n2);
beta = double(r1) - alpha/n2;
}else{
Job::time_instant r1 = execution_time_avg(n1);
Job::time_instant r2 = execution_time_avg(n2);
alpha = double(r1-r2) * n1 * n2/(n2-n1);
beta = double(r1) - alpha/n1;
}
//std::cout << "!real_execution_time: " << real_execution_time << '\n';
//std::cout << "ex_avg: " << execution_time_avg() << '\n';
//std::cout << "diff: "<< real_execution_time - execution_time_avg() << '\n';
//beta += double(real_execution_time - execution_time_avg());
}
void Application::set_n1(const Job::time_instant D){
n1 = alpha/(d_line+D-beta);
}
void Application::set_n2(const Job::time_instant D){
n2 = alpha/(d_line-D-beta);
}
void Application::controlRD(){
if (d_line > execution_time_avg()){
while (d_line > execution_time_avg()){
set_n_core(n_core-1);
}
set_n_core(n_core+1);
}
}
unsigned int Application::max_tasks() const
{
unsigned int max = 0;
for (auto s:stages){
if (max < s.get_n_tasks())
max = s.get_n_tasks();
}
return max;
}