This repository was archived by the owner on Jul 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
133 lines (100 loc) · 3.97 KB
/
test.cpp
File metadata and controls
133 lines (100 loc) · 3.97 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
/**
* MATH3512 Matrix Computations, The Australian National University
* Supervisor : Professor Linda Stals
* Student : u6633756 Junming Zhao
* test.cpp : examples and tests of BLAS operation (a) and (d) implemented.
**/
#include "blas_routine.cpp"
// #include "matrix.cpp"
#include <iostream>
#include <chrono>
#include <math.h>
const int REPEAT = 5;
const int SIZE = 1000;
const int STEP = 10;
int main(){
// test for Strassen algorithm
// test 4.1 in report
/*
std::cout << "matrix dimension," << "Strassen," << "Standard" << std::endl;
for (int m=0; m<SIZE; m+=STEP){
for (int i=0; i<REPEAT; i++){
std::cout << m << ",";
// create matrix A
Matrix A = Matrix(m);
A.assign_random();
// create matrix B
Matrix B = Matrix(m);
B.assign_random();
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
// C = A*B
Matrix C = Matrix::strassen(A,B);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << ",";
// standard matrix multiplication
begin = std::chrono::steady_clock::now();
C = A*B;
end = std::chrono::steady_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << std::endl;
}
}
*/
// test for BLAS3-A routine
// test 4.2 in report
/*
std::cout << "matrix dimension," << "Strassen," << "Standard" << std::endl;
for (int m=0; m < SIZE; m+=STEP){
for (int i=0; i<REPEAT; i++){
std::cout << m << ",";
// create matrix A
Matrix A = Matrix(m);
A.assign_random();
// create matrix B
Matrix B = Matrix(m);
B.assign_random();
// create matrix C
Matrix C(m);
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
// C = 2.0*A*B + 2.0*C
BLAS_3A(2.0, 2.0, A, B, C);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << ",";
// standard matrix multiplication
begin = std::chrono::steady_clock::now();
C.assign_zeros();
// C = 2.0*A*B + 2.0*C
C *= 2.0;
C += A*B;
end = std::chrono::steady_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << std::endl;
}
}
*/
// test for BLAS3-D routine
// test 4.3 in report
std::cout << "matrix dimension," << "Strassen," << "Standard" << std::endl;
for (int n=1; n < 16; n+=1){
for (int i=0; i<REPEAT; i++){
int m = pow(2, n);
std::cout << m << ",";
// create matrix T
Matrix T = Matrix(m);
T.assign_triangular();
// create matrix B
Matrix B = Matrix(m);
B.assign_random();
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
// C = 2.0*T^-1*B
BLAS_3D(2.0, T, B, true);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << ",";
// standard matrix multiplication
begin = std::chrono::steady_clock::now();
// C = 2.0*T^-1*B
BLAS_3D(2.0, T, B, false);
end = std::chrono::steady_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << std::endl;
}
}
return 0;
}