-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestbench.cpp
More file actions
executable file
·114 lines (100 loc) · 2.65 KB
/
Copy pathtestbench.cpp
File metadata and controls
executable file
·114 lines (100 loc) · 2.65 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
#include "testbench.h"
#include "timer.h"
#include <map>
#include "omp.h"
#include "matrix.h"
#include <fstream>
extern int thread;
TestBench::TestBench(int iter, int size_strong)
{
this->iter = iter;
this->size_strong = size_strong;
this->strong();
cout << endl;
this->weak();
cout << endl << endl;
}
void TestBench::weak()
{
cout << "### RUNNING BEGIN WEAK ###" << endl;
int cores[] = {1,2,4};
for(int j = 0; j<3; j++)
{
double sum_in = 0;
cout << "Number of threads : "<< cores[j] << endl;
cout << "Matrix size : " << this->size_strong*cores[j] << endl;
omp_set_num_threads(cores[j]);
thread = cores[j];
for(int i = 0; i<iter; i++)
{
Timer t;
t.start();
Matrix ma(this->size_strong*cores[j], this->size_strong*cores[j]);
ma.init(2);
Matrix m2 = ma;
m2.init(4);
Matrix m4 = ((ma*m2)*2+ma);
unsigned long long int sum = m4.sum();
t.stop();
sum_in += t.time();
}
result_weak[cores[j]] = sum_in/iter;
}
cout << "### RUNNING END WEAK ###" << endl;
}
void TestBench::strong()
{
cout << "### RUNNING BEGIN STRONG ###" << endl;
int cores[] = {1,2,4};
for(int j = 0; j<3; j++)
{
double sum_in = 0;
cout << "Number of threads : "<< cores[j] << endl;
cout << "Matrix size : " << this->size_strong << endl;
omp_set_num_threads(cores[j]);
thread = cores[j];
for(int i = 0; i<iter; i++)
{
Timer t;
t.start();
Matrix ma(this->size_strong, this->size_strong);
ma.init(2);
Matrix m2 = ma;
m2.init(4);
Matrix m4 = ((ma*m2)*2+ma);
unsigned long long int sum = m4.sum();
t.stop();
sum_in += t.time();
}
result_strong[cores[j]] = sum_in/iter;
}
cout << "### RUNNING END STRONG ###" << endl;
}
void TestBench::print_result()
{
cout << "### RESULT BEGIN STRONG ###" << endl;
for (auto it=this->result_strong.begin(); it!=this->result_strong.end(); ++it){
cout << "Number of cores : " << it->first << endl;
cout << "Average time : "<< it->second << endl;
}
cout << "### RESULT END STRONG ###" << endl << endl;
cout << "### RESULT BEGIN WEAK ###" << endl;
for (auto it=this->result_weak.begin(); it!=this->result_weak.end(); ++it){
cout << "Number of cores : " << it->first << endl;
cout << "Average time : "<< it->second << endl;
}
cout << "### RESULT END WEAK ###" << endl;
}void TestBench::print_csv()
{
ofstream myfile;
myfile.open ("results.csv");
myfile << "Strong\n";
for (auto it=this->result_strong.begin(); it!=this->result_strong.end(); ++it){
myfile << it->first << ","<< it->second << "\n";
}
myfile << "Weak\n";
for (auto it=this->result_weak.begin(); it!=this->result_weak.end(); ++it){
myfile << it->first << ","<< it->second << "\n";
}
myfile.close();
}