-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
92 lines (67 loc) · 1.24 KB
/
test.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
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
#include<stdio.h>
// default N=10
#ifndef N
#define TEST_MODE
#define N 15 // array size
#define k 4 // tile size
#endif
// globally defined arrays
double A[N][N];
double B[N][N];
double C[N][N]; // test
double D[N][N]; // actual
// prototype
void printArray(double array[N][N]);
int main() {
#ifdef TEST_MODE
{
// init array with values
int i;
int j;
for(i = 0; i < N; i++) {
for(j = 0; j < N; j++) {
A[i][j] = i*N+j+1;
B[i][j] = i+j+1;
}
}
}
#endif
printArray(A);
printf("\n");
printArray(B);
printf("\n");
printf("\n");
int i, j, m, n, t;
// block version
t = (N%k == 0)? N/k : N/k + 1; // number of iterations
for(m = 0; m < t; m++) {
for(n = 0; n < t; n++) {
for(i = m*k; i < (m*k+k) && i<N; i++) {
for(j = n*k; j < (n*k+k) && j<N; j++) {
C[i][j] = A[i][j] + B[j][i];
}
}
}
}
printf("\n\n");
// regular version
for(i = 0; i < N; i++) {
for(j = 0; j < N; j++) {
D[i][j] = A[i][j] + B[j][i];
}
}
printArray(C);
printf("\n");
printArray(D);
printf("\n");
}
void printArray(double array[N][N]) {
int i;
int j;
for(i = 0; i < N; i++) {
for(j = 0; j < N; j++) {
printf("%.0lf\t", array[i][j]);
}
printf("\n");
}
}