-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
executable file
·358 lines (248 loc) · 11.1 KB
/
test.c
File metadata and controls
executable file
·358 lines (248 loc) · 11.1 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <GASPI.h>
#ifndef NITER
#define NITER 1000
#endif
#ifndef NELEM
#define NELEM 1024
#endif
#define SUCCESS_OR_DIE(f...) \
do \
{ \
const gaspi_return_t r = f; \
\
if (r != GASPI_SUCCESS) \
{ \
printf ("Error: '%s' [%s:%i]: %i\n", #f, __FILE__, __LINE__, r); \
\
exit (EXIT_FAILURE); \
} \
} while (0)
int main (){
struct timeval ti[4], tf[4];
double dT[4];
const gaspi_segment_id_t segment_id_leftSndBuf = 0;
const gaspi_segment_id_t segment_id_leftRxBuf = 1;
const gaspi_segment_id_t segment_id_rightSndBuf = 2;
const gaspi_segment_id_t segment_id_rightRxBuf = 3;
const gaspi_segment_id_t segment_id_topSndBuf = 4;
const gaspi_segment_id_t segment_id_topRxBuf = 5;
const gaspi_segment_id_t segment_id_botSndBuf = 6;
const gaspi_segment_id_t segment_id_botRxBuf = 7;
int leftError = 0, rightError = 0;
int leftNfailure = 0, rightNfailure=0;
int topError = 0, botError = 0;
int topNfailure = 0, botNfailure=0;
gaspi_size_t const segment_size = NELEM * sizeof (double);
gaspi_notification_id_t reqRight = 0;
gaspi_notification_id_t reqLeft = 1;
gaspi_notification_id_t reqTop = 2;
gaspi_notification_id_t reqBot = 3;
gaspi_notification_id_t id;
gaspi_notification_t value;
gaspi_rank_t rank;
gaspi_rank_t peer_left;
gaspi_rank_t peer_right;
gaspi_rank_t peer_top;
gaspi_rank_t peer_bot;
gaspi_rank_t size;
gaspi_queue_id_t queue_id = 0;
gaspi_offset_t off = 0;
gaspi_number_t queue_size_max;
gaspi_number_t queue_size;
SUCCESS_OR_DIE (gaspi_proc_init (GASPI_BLOCK));
SUCCESS_OR_DIE (gaspi_proc_rank (&rank));
SUCCESS_OR_DIE (gaspi_proc_num (&size));
/////////////////////////////////////////////////////////////////////////////
// Calculating peers
peer_left = ((rank % NPIX) == 0) ? (rank+NPIX-1) : (rank-1);
peer_right = (((rank+1) % NPIX) == 0) ? (rank-NPIX+1) : (rank+1);
peer_top = (rank >= (NPIX*(NPIY-1))) ? (rank-(NPIX*(NPIY-1))) : (rank+NPIX);
peer_bot = (rank < NPIX) ? (rank+(NPIX*(NPIY-1))) : (rank-NPIX);
/////////////////////////////////////////////////////////////////////////////
int i, k;
// Delta-times are initialized.
dT[0] = 0.0;
dT[1] = 0.0;
dT[2] = 0.0;
dT[3] = 0.0;
// Create segment for data
SUCCESS_OR_DIE(gaspi_segment_create(segment_id_leftSndBuf, segment_size, GASPI_GROUP_ALL, GASPI_BLOCK,GASPI_MEM_INITIALIZED));
SUCCESS_OR_DIE(gaspi_segment_create(segment_id_leftRxBuf, segment_size, GASPI_GROUP_ALL, GASPI_BLOCK,GASPI_MEM_INITIALIZED));
SUCCESS_OR_DIE(gaspi_segment_create(segment_id_rightSndBuf, segment_size, GASPI_GROUP_ALL, GASPI_BLOCK,GASPI_MEM_INITIALIZED));
SUCCESS_OR_DIE(gaspi_segment_create(segment_id_rightRxBuf, segment_size, GASPI_GROUP_ALL, GASPI_BLOCK,GASPI_MEM_INITIALIZED));
SUCCESS_OR_DIE(gaspi_segment_create(segment_id_topSndBuf, segment_size, GASPI_GROUP_ALL, GASPI_BLOCK,GASPI_MEM_INITIALIZED));
SUCCESS_OR_DIE(gaspi_segment_create(segment_id_topRxBuf, segment_size, GASPI_GROUP_ALL, GASPI_BLOCK,GASPI_MEM_INITIALIZED));
SUCCESS_OR_DIE(gaspi_segment_create(segment_id_botSndBuf, segment_size, GASPI_GROUP_ALL, GASPI_BLOCK,GASPI_MEM_INITIALIZED));
SUCCESS_OR_DIE(gaspi_segment_create(segment_id_botRxBuf, segment_size, GASPI_GROUP_ALL, GASPI_BLOCK,GASPI_MEM_INITIALIZED));
// Buffer pointers
double *leftSndBuf = NULL;
double *leftRxBuf = NULL;
double *rightSndBuf = NULL;
double *rightRxBuf = NULL;
double *topSndBuf = NULL;
double *topRxBuf = NULL;
double *botSndBuf = NULL;
double *botRxBuf = NULL;
// Get initial pointer to each segment
SUCCESS_OR_DIE (gaspi_segment_ptr (segment_id_leftSndBuf, (void **) &leftSndBuf));
SUCCESS_OR_DIE (gaspi_segment_ptr (segment_id_leftRxBuf, (void **) &leftRxBuf));
SUCCESS_OR_DIE (gaspi_segment_ptr (segment_id_rightSndBuf, (void **) &rightSndBuf));
SUCCESS_OR_DIE (gaspi_segment_ptr (segment_id_rightRxBuf, (void **) &rightRxBuf));
SUCCESS_OR_DIE (gaspi_segment_ptr (segment_id_topSndBuf, (void **) &topSndBuf));
SUCCESS_OR_DIE (gaspi_segment_ptr (segment_id_topRxBuf, (void **) &topRxBuf));
SUCCESS_OR_DIE (gaspi_segment_ptr (segment_id_botSndBuf, (void **) &botSndBuf));
SUCCESS_OR_DIE (gaspi_segment_ptr (segment_id_botRxBuf, (void **) &botRxBuf));
for(i = 0; i < NELEM; i++){
// Initialize right buffer
rightSndBuf[i] = (double)i + ((double)rank*0.1);
rightRxBuf[i] = -1.0;
// Initialize left buffer
leftSndBuf[i] = (double)i + ((double)rank*0.01);
leftRxBuf[i] = -1.0;
// Initialize top buffer
topSndBuf[i] = (double)i + ((double)rank*0.001);
topRxBuf[i] = -1.0;
// Initialize left buffer
botSndBuf[i] = (double)i + ((double)rank*0.0001);
botRxBuf[i] = -1.0;
}
if ( rank == 0 ){
fprintf(stdout, "running with %d GPI ranks w/ %d iterations \n", size, NITER);
}
SUCCESS_OR_DIE(gaspi_barrier (GASPI_GROUP_ALL, GASPI_BLOCK));
SUCCESS_OR_DIE (gaspi_queue_size_max (&queue_size_max));
// Start testing NITER times
for (k = 0; k < NITER; k++) {
SUCCESS_OR_DIE (gaspi_queue_size (queue_id, &queue_size));
if(queue_size == queue_size_max){
SUCCESS_OR_DIE (gaspi_wait(queue_id, GASPI_BLOCK));
}
gettimeofday(&ti[0], NULL);
// Sending right buffer
SUCCESS_OR_DIE(gaspi_write_notify(segment_id_rightSndBuf, off, peer_right, segment_id_rightRxBuf, off, NELEM*sizeof(double), reqRight, rank+1, queue_id, GASPI_BLOCK));
// Receiving right buffer
SUCCESS_OR_DIE(gaspi_notify_waitsome(segment_id_rightRxBuf, reqRight, 1, &id, GASPI_BLOCK));
SUCCESS_OR_DIE (gaspi_notify_reset (segment_id_rightRxBuf, id, &value));
gettimeofday(&tf[0], NULL);
dT[0] += (double)(tf[0].tv_sec - ti[0].tv_sec )*1.e6 +
(double)(tf[0].tv_usec - ti[0].tv_usec);
gettimeofday(&ti[1], NULL);
SUCCESS_OR_DIE (gaspi_queue_size (queue_id, &queue_size));
if(queue_size == queue_size_max){
SUCCESS_OR_DIE (gaspi_wait(queue_id, GASPI_BLOCK));
}
// Sending left buffer
SUCCESS_OR_DIE(gaspi_write_notify(segment_id_leftSndBuf, off, peer_left, segment_id_leftRxBuf, off, NELEM*sizeof(double), reqLeft, rank+1, queue_id, GASPI_BLOCK));
// Receiving left buffer
SUCCESS_OR_DIE(gaspi_notify_waitsome(segment_id_leftRxBuf, reqLeft, 1, &id, GASPI_BLOCK));
SUCCESS_OR_DIE (gaspi_notify_reset (segment_id_leftRxBuf, id, &value));
gettimeofday(&tf[1], NULL);
dT[1] += (double)(tf[1].tv_sec - ti[1].tv_sec )*1.e6 +
(double)(tf[1].tv_usec - ti[1].tv_usec);
if ( NPIY > 1 ) {
SUCCESS_OR_DIE (gaspi_queue_size (queue_id, &queue_size));
if(queue_size == queue_size_max){
SUCCESS_OR_DIE (gaspi_wait(queue_id, GASPI_BLOCK));
}
gettimeofday(&ti[2], NULL);
// Sending top buffer
SUCCESS_OR_DIE(gaspi_write_notify(segment_id_topSndBuf, off, peer_bot, segment_id_topRxBuf, off, NELEM*sizeof(double), reqTop, rank+1, queue_id, GASPI_BLOCK));
// Receiving top buffer
SUCCESS_OR_DIE(gaspi_notify_waitsome(segment_id_topRxBuf, reqTop, 1, &id, GASPI_BLOCK));
SUCCESS_OR_DIE (gaspi_notify_reset (segment_id_topRxBuf, id, &value));
gettimeofday(&tf[2], NULL);
dT[2] += (double)(tf[2].tv_sec - ti[2].tv_sec )*1.e6 +
(double)(tf[2].tv_usec - ti[2].tv_usec);
SUCCESS_OR_DIE (gaspi_queue_size (queue_id, &queue_size));
if(queue_size == queue_size_max){
SUCCESS_OR_DIE (gaspi_wait(queue_id, GASPI_BLOCK));
}
gettimeofday(&ti[3], NULL);
// Sending bottom buffer
SUCCESS_OR_DIE(gaspi_write_notify(segment_id_botSndBuf, off, peer_top, segment_id_botRxBuf, off, NELEM*sizeof(double), reqBot, rank+1, queue_id, GASPI_BLOCK));
// Receiving bottom buffer
SUCCESS_OR_DIE(gaspi_notify_waitsome(segment_id_botRxBuf, reqBot, 1, &id, GASPI_BLOCK));
SUCCESS_OR_DIE (gaspi_notify_reset (segment_id_botRxBuf, id, &value));
gettimeofday(&tf[3], NULL);
dT[3] += (double)(tf[3].tv_sec - ti[3].tv_sec )*1.e6 +
(double)(tf[3].tv_usec - ti[3].tv_usec);
}
leftError=0;
rightError=0;
topError=0;
botError=0;
for(i = 0; i < NELEM; i++){
// Checking right buffer
double rightExpData = (double)i+ ((double)peer_left*0.1);
if ( rightRxBuf[i] != rightExpData) {
rightError++;
}
rightRxBuf[i]=-1.0;
// Checking left buffer
double leftExpData = (double)i+ ((double)peer_right*0.01);
if ( leftRxBuf[i] != leftExpData) {
leftError++;
}
leftRxBuf[i]=-1.0;
if ( NPIY > 1 ) {
// Checking top buffer
double topExpData = (double)i+ ((double)peer_top*0.001);
if ( topRxBuf[i] != topExpData) {
topError++;
}
topRxBuf[i]=-1.0;
// Checking bot buffer
double botExpData = (double)i+ ((double)peer_bot*0.0001);
if ( botRxBuf[i] != botExpData) {
botError++;
}
botRxBuf[i]=-1.0;
}
}
if ( leftError > 0 ) {
leftNfailure++;
}
if ( rightError > 0 ) {
rightNfailure++;
}
if ( NPIY > 1 ) {
if ( topError > 0 ) {
topNfailure++;
}
if ( botError > 0 ) {
botNfailure++;
}
}
SUCCESS_OR_DIE(gaspi_barrier (GASPI_GROUP_ALL, GASPI_BLOCK));
} // End for of NITER tests
// Printing results of error checking
for (i=0; i<size; i++) {
if ( i == rank ) {
if ( leftNfailure > 0 )
fprintf(stderr,"RANK%d: %d/%d FAILED LEFT BUFFER\n", rank, leftNfailure, NITER);
else
fprintf(stdout,"RANK%d: SUCCESS LEFT BUFFER TOOK ON AVG %.2fs\n", rank, dT[0]/(double)NITER);
if ( rightNfailure > 0 )
fprintf(stderr,"RANK%d: %d/%d FAILED RIGHT BUFFER\n", rank, rightNfailure, NITER);
else
fprintf(stdout,"RANK%d: SUCCESS RIGHT BUFFER TOOK ON AVG %.2fs\n", rank, dT[1]/(double)NITER);
if ( NPIY > 1 ) {
if ( topNfailure > 0 )
fprintf(stderr,"RANK%d: %d/%d FAILED TOP BUFFER\n", rank, topNfailure, NITER);
else
fprintf(stdout,"RANK%d: SUCCESS TOP BUFFER TOOK ON AVG %.2fs\n", rank, dT[2]/(double)NITER);
if ( botNfailure > 0 )
fprintf(stderr,"RANK%d: %d/%d FAILED BOT BUFFER\n", rank, botNfailure, NITER);
else
fprintf(stdout,"RANK%d: SUCCESS BOT BUFFER TOOK ON AVG %.2fs\n", rank, dT[3]/(double)NITER);
}
}
SUCCESS_OR_DIE(gaspi_barrier (GASPI_GROUP_ALL, GASPI_BLOCK));
}
SUCCESS_OR_DIE (gaspi_proc_term (GASPI_BLOCK));
return - leftError - rightError - topError - botError;
}