-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixMulti64.cpp
More file actions
57 lines (42 loc) · 1.24 KB
/
Copy pathMatrixMulti64.cpp
File metadata and controls
57 lines (42 loc) · 1.24 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
#include <iostream>
#include <chrono>
const int N = 64; // Size of the matrices (N x N)
void multiplyMatrix(float A[N][N], float B[N][N], float result[N][N]) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
result[i][j] = 0;
for (int k = 0; k < N; ++k) {
result[i][j] += A[i][k] * B[k][j];
}
}
}
}
int main() {
using std::chrono::high_resolution_clock;
using std::chrono::duration_cast;
using std::chrono::duration;
using std::chrono::milliseconds;
float A[N][N];
float B[N][N] ;
int value = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
A[i][j] = ++value;
B[i][j] = value;
}
}
float result[N][N];
auto t1 = high_resolution_clock::now();
multiplyMatrix(A, B, result);
auto t2 = high_resolution_clock::now();
duration<double, std::milli> ms_double = t2 - t1;
std::cout << ms_double.count() << "ms\n";
// std::cout << "Result Matrix:\n";
// for (int i = 0; i < N; ++i) {
// for (int j = 0; j < N; ++j) {
// std::cout << result[i][j] << " ";
// }
// std::cout << "\n";
// }
return 0;
}