-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalg1.c
56 lines (44 loc) · 1.12 KB
/
alg1.c
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
#include <stdlib.h>
#include <string.h>
void matrix_fill_rand(int n, double *restrict _A)
{
#define A(i, j) _A[n*(i) + (j)]
int i, j;
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
A(i, j) = 10*(double) rand() / (double) RAND_MAX;
#undef A
}
void matrix_dgemm_1(int n, double *restrict _C, double *restrict _A, double *restrict _B)
{
#define A(i, j) _A[n*(i) + (j)]
#define B(i, j) _B[n*(i) + (j)]
#define C(i, j) _C[n*(i) + (j)]
int i, j, k;
//int *x=&i,*y=&k,*z=&j;
int @ORD@;
for (*x = 0; *x < n; ++*x)
for (*y = 0; *y < n; ++*y)
for (*z = 0; *z < n; ++*z) {
C(i, j) += A(i, k)*B(k, j);
}
#undef A
#undef B
#undef C
}
int main()
{
int n = 1024;
double *restrict A, *restrict B, *restrict C = NULL;
posix_memalign((void **)&A, 8, n*n*sizeof(*A));
posix_memalign((void **)&B, 8, n*n*sizeof(*B));
posix_memalign((void **)&C, 8, n*n*sizeof(*C));
matrix_fill_rand(n, A);
matrix_fill_rand(n, B);
memset(C, 0x00, n*n*sizeof(*A));
matrix_dgemm_1(n, C, A, B);
free(A);
free(B);
free(C);
return 0;
}