-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrassen_test.cpp
153 lines (106 loc) · 3.65 KB
/
strassen_test.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/////////////////////////////*** Utilites ***//////////////////////////////////////////////////
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <chrono>
#include <thread>
#include <ctime>
#include "./matrix/matrix.hpp"
#include "./matrix/mfunctions.hpp"
#include "./matrix/strassenMul.hpp"
using namespace std;
void speed_test_int()
{
using namespace std;
matrix<double>Ad(file2Matrix("A.dat"));
matrix<double>Bd(file2Matrix("B.dat"));
matrix<int> A(Ad.toInt());
matrix<int> B(Bd.toInt());
makeConsistent(A,B);
cout<<"\n\n\n";
cout<< "A.r= "<<A.r<<endl;
cout<< "A.c= "<<A.c<<endl;
cout<< "B.r= "<<B.r<<endl;
cout<< "B.c= "<<B.c<<endl;
clock_t t;
std::chrono::time_point<std::chrono::steady_clock> start, end;
start = std::chrono::steady_clock::now();
t=clock();
matrix<int> Sp=strassenMul(A,B,'p'); // parallel Strassen (7 threads)
end = std::chrono::steady_clock::now();
t=clock()-t;
ty ms_Sp= std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
ty tics_Sp = t;
std::this_thread::sleep_for(std::chrono::seconds(5));
start = std::chrono::steady_clock::now();
t=clock();
matrix<int> S_mul=dot(A,B); //straightforvard product for the comparison with Strassen
end = std::chrono::steady_clock::now();
t=clock()-t;
ty ms_mul= std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
ty tics_mul=t;
start = std::chrono::steady_clock::now();
cout<<"\n\n\n";
std::cout<< " Speed test for Strassen parallel: "<< ms_Sp<<" ms, "<< tics_Sp<<" tics\n";
std::cout<< " Speed test for straightforward dot: "<< ms_mul<<" ms, "<< tics_mul<<" tics\n";
cout<< "PROVERKA:\n";
if(Sp==S_mul)
{
cout << "results of Parallel Strassen and straightforward dot product are identical\n";
}
else
{
cout << "results of Parallel Strassen and straightforward dot product differ!\n Something went wrong!\n";
}
}
void speed_test_double()
{
using namespace std;
matrix<double>A(std::move(file2Matrix("A.dat"))); //read the file and make matrix<double>
matrix<double>B(std::move(file2Matrix("B.dat")));
makeConsistent(A,B);
cout<<"\n\n\n";
cout<< "A.r= "<<A.r<<endl;
cout<< "A.c= "<<A.c<<endl;
cout<< "B.r= "<<B.r<<endl;
cout<< "B.c= "<<B.c<<endl;
clock_t t;
std::chrono::time_point<std::chrono::steady_clock> start, end;
start = std::chrono::steady_clock::now();
t=clock();
matrix<double> Sp=strassenMul(A,B,'p'); // parallel Strassen (7 threads)
end = std::chrono::steady_clock::now();
t=clock()-t;
ty ms_Sp= std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
ty tics_Sp=t;
std::this_thread::sleep_for(std::chrono::seconds(5));
start = std::chrono::steady_clock::now();
t=clock();
matrix<double> S_mul=dot(A,B); //straightforvard product for the comparison with Strassen
end = std::chrono::steady_clock::now();
t=clock()-t;
ty ms_mul= std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
ty tics_mul=t;
cout<<"\n\n\n";
cout<< "test on matrix<double>:\n\n";
cout<< " Speed test for Strassen parallel: "<< ms_Sp<<" ms, "<< tics_Sp<<" tics\n";
cout<< " Speed test for straightforward_dot: "<< ms_mul<<" ms, "<< tics_mul<<" tics\n";
// matrix2File(Sp,"S_p_d.txt");
// matrix2File(S_mul,"S_mul_d.txt");
cout<< "PROVERKA:\n";
if(Sp==S_mul)
{
cout << "results of Parallel Strassen and straightforward dot product are identical\n";
}
else
{
cout << "results of Parallel Strassen and straightforward dot product differ!\n Something went wrong!\n";
}
}
int main(int argc, char const *argv[])
{
speed_test_int();
speed_test_double();
return 0;
}