-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
143 lines (112 loc) · 3.68 KB
/
Copy pathmain.cpp
File metadata and controls
143 lines (112 loc) · 3.68 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "ThreadedMatrixMult.h"
#include <chrono>
#include <iomanip>
#include <iostream>
#include <thread>
#include <vector>
using namespace std;
using namespace chrono;
const int DIMENSION = 1024;
const int tests = 20;
ostream& printMatrix(const SquareMatrix&, ostream&);
SquareMatrix* readMatrix(istream&);
void makeMatrix(SquareMatrix&);
int main() {
SquareMatrix testA(DIMENSION), testB(DIMENSION);
makeMatrix(testA);
makeMatrix(testB);
{
cout << "---------BRUTE FORCE---------" << endl;
vector<decltype(high_resolution_clock::now() - high_resolution_clock::now())> data;
for (int m = 0; m < tests; m++) {
auto start = high_resolution_clock::now();
BruteForce(testA, testB);
auto stop = high_resolution_clock::now();
data.emplace_back(duration_cast<milliseconds>(stop - start));
}
double average = 0;
for (auto i: data) {
average += i.count();
}
average /= data.size();
cout << setprecision(20) << average << endl;
}
{
cout << "---------D&CThreaded---------" << endl;
vector<decltype(high_resolution_clock::now() - high_resolution_clock::now())> data;
for (int m = 0; m < tests; m++) {
auto start = high_resolution_clock::now();
ThreadedDivideAndConquer(testA, testB);
auto stop = high_resolution_clock::now();
data.emplace_back(duration_cast<milliseconds>(stop - start));
}
double average = 0;
for (auto i: data) {
average += i.count();
}
average /= data.size();
cout << setprecision(20) << average << endl;
}
{
cout << "---------Strassen---------" << endl;
vector<decltype(high_resolution_clock::now() - high_resolution_clock::now())> data;
for (int m = 0; m < tests; m++) {
auto start = high_resolution_clock::now();
Strassen(testA, testB);
auto stop = high_resolution_clock::now();
data.emplace_back(duration_cast<milliseconds>(stop - start));
}
double average = 0;
for (auto i: data) {
average += i.count();
}
average /= data.size();
cout << setprecision(20) << average << endl;
}
{
cout << "---------ThreadedStrassen---------" << endl;
vector<decltype(high_resolution_clock::now() - high_resolution_clock::now())> data;
for (int m = 0; m < tests; m++) {
auto start = high_resolution_clock::now();
ThreadedStrassen(testA, testB);
auto stop = high_resolution_clock::now();
data.emplace_back(duration_cast<milliseconds>(stop - start));
}
double average = 0;
for (auto i: data) {
average += i.count();
}
average /= data.size();
cout << setprecision(20) << average << endl;
}
return 0;
}
ostream& printMatrix(const SquareMatrix& m, ostream& out) {
for(int i = 0; i < m.dim; i++) {
for(int j = 0; j < m.dim; j++) {
out << m.data[i][j] << " ";
}
out << endl;
}
return out;
}
SquareMatrix* readMatrix(istream& in) {
int dim;
cin >> dim;
SquareMatrix* m = new SquareMatrix(dim);
int count = 0;
for(int i = 0; i < dim; i++) {
for(int j = 0; j < dim; j++) {
in >> m->data[i][j];
cout << "Curr: " << m->data[i][j] << " " << "Count: " << ++count << endl;
}
}
return m;
}
void makeMatrix(SquareMatrix& m) {
for (int i = 0; i < m.dim; i++) {
for (int j = 0; j < m.dim; j++) {
m.data[i][j] = rand() % 100;
}
}
}