Skip to content

Commit 2f62581

Browse files
committed
add checking for contents of read back
1 parent 4991139 commit 2f62581

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

tests/pio_noncontig.c

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
#include <stdio.h>
6464
#include <stdlib.h>
65+
#include <string.h> /* strcpy() */
6566
#include <unistd.h> /* getopt() */
6667

6768
#include <mpi.h>
@@ -90,7 +91,7 @@ static void
9091
usage(char *argv0)
9192
{
9293
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"
9495
" [-h] Print this help\n"
9596
" [-v] verbose mode\n"
9697
" [-w] performs write only (default: both write and read)\n"
@@ -99,7 +100,7 @@ usage(char *argv0)
99100
" [-k num] number of rows in each global variable (default: %d)\n"
100101
" [-c num] number of columns in each global variable (default: %d)\n"
101102
" [-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";
103104
fprintf(stderr, help, argv0, NVARS, NROWS, NCOLS, GAP);
104105
}
105106

@@ -109,12 +110,12 @@ int main(int argc, char **argv)
109110
extern int optind;
110111
extern char *optarg;
111112
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;
114115
int do_write, do_read;
115116
char *buf;
116117
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;
118119
MPI_Datatype bufType, fileType, *subTypes;
119120
MPI_File fh;
120121
MPI_Offset wlen;
@@ -131,9 +132,10 @@ int main(int argc, char **argv)
131132
gap = GAP;
132133
do_write = 1;
133134
do_read = 1;
135+
filename[0] = '\0';
134136

135137
/* 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)
137139
switch(i) {
138140
case 'v': verbose = 1;
139141
break;
@@ -162,15 +164,20 @@ int main(int argc, char **argv)
162164
break;
163165
case 'r': do_write = 0;
164166
break;
167+
case 'f': strcpy(filename, optarg);
168+
break;
169+
165170
case 'h':
166171
default: if (rank==0) usage(argv[0]);
167172
MPI_Finalize();
168173
return 1;
169174
}
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+
}
174181

175182
/* Calculate number of subarray requests each aggregator writes or reads.
176183
* Each original MPI process client forwards all its requests to one of
@@ -227,6 +234,13 @@ int main(int argc, char **argv)
227234
err = MPI_Type_get_extent(bufType, &lb, &buf_ext); ERR
228235
buf = (char*) calloc(buf_ext, 1);
229236

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+
230244
/* construct file type:
231245
* + there are nreqs subarrays, each uses a subarray datatype
232246
* + all subarray datatypes are concatenated into one to be used as fileview
@@ -305,10 +319,32 @@ int main(int argc, char **argv)
305319

306320
/* read from the file */
307321
if (do_read) {
322+
/* reset contents of buffer */
323+
for (j=0; j<buf_ext; j++) buf[j] = -1;
324+
308325
MPI_Barrier(MPI_COMM_WORLD);
309326
timing[1] = MPI_Wtime();
310327
err = MPI_File_read_at_all(fh, 0, buf, 1, bufType, &status); ERR
311328
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+
}
312348
}
313349

314350
err = MPI_File_close(&fh); ERR
@@ -317,8 +353,9 @@ int main(int argc, char **argv)
317353
err = MPI_Type_free(&bufType); ERR
318354
free(buf);
319355

356+
MPI_Reduce(&nerrs, &max_nerrs, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD);
320357
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) {
322359
printf("---------------------------------------------------------\n");
323360
if (do_write)
324361
printf("Time of collective write = %.2f sec\n", max_timing[0]);

0 commit comments

Comments
 (0)