forked from gravitino/HPC2014-Ex1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.cpp
45 lines (31 loc) · 849 Bytes
/
matrix.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
#include <iostream>
#define N (1024)
void mult(float *A, float *B, float *C) {
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) {
float sum = 0.0f;
for (int k = 0; k < N; k++)
sum += A[i * N + k] * B[k * N + j];
C[i * N + j] = sum;
}
}
int main() {
float *A = new float[N * N];
float *B = new float[N * N];
float *C = new float[N * N];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) {
A[i * N + j] = 1;
B[i * N + j] = 1;
}
mult(A, B, C);
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) {
std::cout << C[i * N + j]
<< (j == N - 1 ? "\n" : "\t");
}
std::cout << std::endl;
delete[] A;
delete[] B;
delete[] C;
}