-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.test.c
154 lines (135 loc) · 4.2 KB
/
main.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Stencil Probe
Main function.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common.h"
#include "util.h"
#include "cycle.h"
#ifdef HAVE_PAPI
#include <papi.h>
#endif
/* run.h has the run parameters */
#include "run.h"
void StencilProbe(double* A0, double* Anext, int nx, int ny, int nz,
int tx, int ty, int tz, int timesteps);
void check_vals(double* A, double* B, int nx, int ny, int nz);
int main(int argc,char *argv[]) {
double *A0_naive, *A0_test;
double *Anext_naive, *Anext_test;
double *Afinal_naive, *Afinal_test;
int nx,ny,nz,tx,ty,tz,timesteps;
int i,j;
ticks t1, t2;
double spt;
/* parse command line options */
if (argc < 8) {
printf("\nUSAGE:\n%s <grid x> <grid y> <grid z> <block x> <block y> <block z> <timesteps>\n", argv[0]);
printf("\nTIME SKEWING CONSTRAINTS:\nIn each dimension, <grid size - 2> should be a multiple of <block size>.\n");
printf("\nCIRCULAR QUEUE CONSTRAINTS:\n<grid y - 2> should be a multiple of <block y>. The block sizes in the other dimensions are ignored.\n\n");
return EXIT_FAILURE;
}
nx = atoi(argv[1]);
ny = atoi(argv[2]);
nz = atoi(argv[3]);
tx = atoi(argv[4]);
ty = atoi(argv[5]);
tz = atoi(argv[6]);
timesteps = atoi(argv[7]);
printf("%dx%dx%d, blocking: %dx%dx%d, timesteps: %d\n",
nx,ny,nz,tx,ty,tz,timesteps);
#ifdef HAVE_PAPI
PAPI_library_init(PAPI_VER_CURRENT);
#endif
/* find conversion factor from ticks to seconds */
spt = seconds_per_tick();
// allocate arrays
A0_naive=(double*)malloc(sizeof(double)*nx*ny*nz);
A0_test=(double*)malloc(sizeof(double)*nx*ny*nz);
Anext_naive=(double*)malloc(sizeof(double)*nx*ny*nz);
Anext_test=(double*)malloc(sizeof(double)*nx*ny*nz);
// Run Naive Code
StencilInit(nx,ny,nz,A0_naive);
StencilInit(nx,ny,nz,Anext_naive);
StencilProbe_naive(A0_naive, Anext_naive, nx, ny, nz, tx, ty, tz, timesteps);
if (timesteps%2 == 0) {
Afinal_naive = A0_naive;
}
else {
Afinal_naive = Anext_naive;
}
printf("USING TIMER: %s \t SECONDS PER TICK:%g \n", TIMER_DESC, spt);
// Test Rivera Blocking
StencilInit(nx,ny,nz,A0_test);
StencilInit(nx,ny,nz,Anext_test);
printf("Checking Rivera (single-timestep) blocking...\n");
StencilProbe_rivera(A0_test, Anext_test, nx, ny, nz, tx, ty, tz, timesteps);
if (timesteps%2 == 0) {
Afinal_test = A0_test;
}
else {
Afinal_test = Anext_test;
}
check_vals(Afinal_naive, Afinal_test, nx, ny, nz);
// Test Cache-Oblivious Blocking
StencilInit(nx,ny,nz,A0_test);
StencilInit(nx,ny,nz,Anext_test);
printf("Checking Cache-Oblivious blocking...\n");
StencilProbe_oblivious(A0_test, Anext_test, nx, ny, nz, tx, ty, tz, timesteps);
if (timesteps%2 == 0) {
Afinal_test = A0_test;
}
else {
Afinal_test = Anext_test;
}
check_vals(Afinal_naive, Afinal_test, nx, ny, nz);
// Test Time-Skewed Blocking
StencilInit(nx,ny,nz,A0_test);
StencilInit(nx,ny,nz,Anext_test);
printf("Checking Time-Skewed blocking...\n");
StencilProbe_timeskew(A0_test, Anext_test, nx, ny, nz, tx, ty, tz, timesteps);
if (timesteps%2 == 0) {
Afinal_test = A0_test;
}
else {
Afinal_test = Anext_test;
}
check_vals(Afinal_naive, Afinal_test, nx, ny, nz);
// Test Circular-Queue Blocking
StencilInit(nx,ny,nz,A0_test);
StencilInit(nx,ny,nz,Anext_test);
if (timesteps > 1) {
CircularQueueInit(nx, ty, timesteps);
}
printf("Checking Circular-Queue blocking...\n");
StencilProbe_circqueue(A0_test, Anext_test, nx, ny, nz, tx, ty, tz, timesteps);
Afinal_test = Anext_test;
check_vals(Afinal_naive, Afinal_test, nx, ny, nz);
/* free arrays */
free(Anext_naive);
free(A0_naive);
free(Anext_test);
free(A0_test);
return EXIT_SUCCESS;
}
void check_vals(double* A, double* B, int nx, int ny, int nz) {
int same, different;
int i, j, k;
same=different=0;
for (k=0; k<nz; k++) {
for (j=0; j<ny; j++) {
for (i=0; i<nx; i++) {
if (fabs(A[Index3D(nx,ny,i,j,k)] - B[Index3D(nx,ny,i,j,k)]) < 0.001)
same++;
else {
different++;
printf("at index %d %d %d --- A: %3.2g, B %3.2g\n", i, j, k,
A[Index3D(nx,ny,i,j,k)], B[Index3D(nx,ny,i,j,k)]);
}
}
}
}
printf("Same: %d Different: %d\n", same, different);
}