62
62
63
63
#include <stdio.h>
64
64
#include <stdlib.h>
65
+ #include <string.h> /* strcpy() */
65
66
#include <unistd.h> /* getopt() */
66
67
67
68
#include <mpi.h>
@@ -90,7 +91,7 @@ static void
90
91
usage (char * argv0 )
91
92
{
92
93
char * help =
93
- "Usage: %s [-hvrw | -n num | -k num | -c num | -g num | file_name] \n"
94
+ "Usage: %s [-hvrw | -n num | -k num | -c num | -g num ] -f file_name\n"
94
95
" [-h] Print this help\n"
95
96
" [-v] verbose mode\n"
96
97
" [-w] performs write only (default: both write and read)\n"
@@ -99,7 +100,7 @@ usage(char *argv0)
99
100
" [-k num] number of rows in each global variable (default: %d)\n"
100
101
" [-c num] number of columns in each global variable (default: %d)\n"
101
102
" [-g num] gap in bytes between first 2 blocks (default: %d)\n"
102
- " [ file_name] output file name\n" ;
103
+ " -f file_name: output file name\n" ;
103
104
fprintf (stderr , help , argv0 , NVARS , NROWS , NCOLS , GAP );
104
105
}
105
106
@@ -109,12 +110,12 @@ int main(int argc, char **argv)
109
110
extern int optind ;
110
111
extern char * optarg ;
111
112
char filename [256 ];
112
- int i , err , nerrs = 0 , rank , nprocs , mode , verbose = 0 , nvars , nreqs ;
113
- int gap , ncols_g , nrows , ncols , * blocklen , btype_size , ftype_size ;
113
+ int i , err , nerrs = 0 , max_nerrs , rank , nprocs , mode , verbose = 0 , nvars ;
114
+ int nreqs , gap , ncols_g , nrows , ncols , * blocklen , btype_size , ftype_size ;
114
115
int do_write , do_read ;
115
116
char * buf ;
116
117
double timing [2 ], max_timing [2 ];
117
- MPI_Aint lb , * displace , buf_ext , file_ext ;
118
+ MPI_Aint j , lb , * displace , buf_ext , file_ext ;
118
119
MPI_Datatype bufType , fileType , * subTypes ;
119
120
MPI_File fh ;
120
121
MPI_Offset wlen ;
@@ -131,9 +132,10 @@ int main(int argc, char **argv)
131
132
gap = GAP ;
132
133
do_write = 1 ;
133
134
do_read = 1 ;
135
+ filename [0 ] = '\0' ;
134
136
135
137
/* get command-line arguments */
136
- while ((i = getopt (argc , argv , "hvwrn:k:c:g:" )) != EOF )
138
+ while ((i = getopt (argc , argv , "hvwrn:k:c:g:f: " )) != EOF )
137
139
switch (i ) {
138
140
case 'v' : verbose = 1 ;
139
141
break ;
@@ -162,15 +164,20 @@ int main(int argc, char **argv)
162
164
break ;
163
165
case 'r' : do_write = 0 ;
164
166
break ;
167
+ case 'f' : strcpy (filename , optarg );
168
+ break ;
169
+
165
170
case 'h' :
166
171
default : if (rank == 0 ) usage (argv [0 ]);
167
172
MPI_Finalize ();
168
173
return 1 ;
169
174
}
170
- if (argv [optind ] == NULL )
171
- sprintf (filename , "%s.out" , argv [0 ]);
172
- else
173
- snprintf (filename , 256 , "%s" , argv [optind ]);
175
+
176
+ if (filename [0 ] == '\0' ) {
177
+ if (rank == 0 ) usage (argv [0 ]);
178
+ MPI_Finalize ();
179
+ return 1 ;
180
+ }
174
181
175
182
/* Calculate number of subarray requests each aggregator writes or reads.
176
183
* Each original MPI process client forwards all its requests to one of
@@ -227,6 +234,13 @@ int main(int argc, char **argv)
227
234
err = MPI_Type_get_extent (bufType , & lb , & buf_ext ); ERR
228
235
buf = (char * ) calloc (buf_ext , 1 );
229
236
237
+ for (j = 0 ; j < buf_ext ; j ++ ) buf [j ] = -1 ;
238
+ for (j = 0 ; j < blocklen [0 ]; j ++ )
239
+ buf [j ] = (j + rank ) % 127 ;
240
+ j += gap ;
241
+ for (; j < blocklen [0 ]+ blocklen [1 ]; j ++ )
242
+ buf [j ] = (j + rank ) % 127 ;
243
+
230
244
/* construct file type:
231
245
* + there are nreqs subarrays, each uses a subarray datatype
232
246
* + all subarray datatypes are concatenated into one to be used as fileview
@@ -305,10 +319,32 @@ int main(int argc, char **argv)
305
319
306
320
/* read from the file */
307
321
if (do_read ) {
322
+ /* reset contents of buffer */
323
+ for (j = 0 ; j < buf_ext ; j ++ ) buf [j ] = -1 ;
324
+
308
325
MPI_Barrier (MPI_COMM_WORLD );
309
326
timing [1 ] = MPI_Wtime ();
310
327
err = MPI_File_read_at_all (fh , 0 , buf , 1 , bufType , & status ); ERR
311
328
timing [1 ] = MPI_Wtime () - timing [1 ];
329
+
330
+ /* check contents of read buffer */
331
+ for (j = 0 ; j < nrows ; j ++ ) {
332
+ char exp = (j + rank ) % 127 ;
333
+ if (buf [j ] != exp ) {
334
+ printf ("Error: buf[%zd] expect %d but got %d\n" ,j ,exp ,buf [j ]);
335
+ nerrs ++ ;
336
+ break ;
337
+ }
338
+ }
339
+ j += gap ;
340
+ for (; j < nrows * ncols * (nreqs - 1 ); j ++ ) {
341
+ char exp = (j + rank ) % 127 ;
342
+ if (buf [j ] != exp ) {
343
+ printf ("Error: buf[%zd] expect %d but got %d\n" ,j ,exp ,buf [j ]);
344
+ nerrs ++ ;
345
+ break ;
346
+ }
347
+ }
312
348
}
313
349
314
350
err = MPI_File_close (& fh ); ERR
@@ -317,8 +353,9 @@ int main(int argc, char **argv)
317
353
err = MPI_Type_free (& bufType ); ERR
318
354
free (buf );
319
355
356
+ MPI_Reduce (& nerrs , & max_nerrs , 1 , MPI_INT , MPI_MAX , 0 , MPI_COMM_WORLD );
320
357
MPI_Reduce (timing , max_timing , 2 , MPI_DOUBLE , MPI_MAX , 0 , MPI_COMM_WORLD );
321
- if (rank == 0 ) {
358
+ if (max_nerrs == 0 && rank == 0 ) {
322
359
printf ("---------------------------------------------------------\n" );
323
360
if (do_write )
324
361
printf ("Time of collective write = %.2f sec\n" , max_timing [0 ]);
0 commit comments