2525 *
2626 * % m4 column_wise.m4 > column_wise.c
2727 * % mpicc -O2 -o column_wise column_wise.c -lpnetcdf
28- * % mpiexec -l -n 4 ./column_wise /pvfs2/wkliao/testfile.nc
28+ * % mpiexec -l -n 4 ./column_wise -l 4 /pvfs2/wkliao/testfile.nc
2929 * 0: 0: myOff= 0 myNX= 4
3030 * 1: 1: myOff= 4 myNX= 4
3131 * 2: 2: myOff= 8 myNX= 4
6767# include <stdlib.h>
6868# include <string.h> /* strcpy() */
6969# include <libgen.h> /* basename() */
70+ # include <unistd.h> /* getopt() */
71+
7072# include <mpi.h>
7173# include <pnetcdf.h>
7274
7375# include <testutils.h>
7476
7577# define NY 10
76- # define NX 4
78+ # define NX 70
7779
7880typedef char text;
7981
8082include ( `foreach.m4' ) dnl
8183include ( `utils.m4' ) dnl
8284
85+ define ( `TEST_DATA_TYPE' ,`test_column_wise_$1 ( filename , cdf_formats [ fmt] , coll_io , len ) ' )
86+
8387define ( `TEST_COLUMN_WISE' ,`dnl
8488static
85- int test_column_wise_$1 ( char * filename , int cdf )
89+ int test_column_wise_$1 ( char * filename , int cdf , int coll_io , int len )
8690{
8791 int i , j , nerrs=0 , rank , nprocs , err , myNX , G_NX , myOff , num_reqs;
8892 int ncid , cmode , varid , dimid [ 2] , * reqs , * sts;
@@ -100,10 +104,10 @@ int test_column_wise_$1(char *filename, int cdf)
100104 err = ncmpi_create ( MPI_COMM_WORLD , filename , cmode , MPI_INFO_NULL , &ncid ) ;
101105 CHECK_ERR
102106
103- /* the global array is NY * ( NX * nprocs ) */
104- G_NX = NX * nprocs;
105- myOff = NX * rank;
106- myNX = NX ;
107+ /* the global array is NY * ( len * nprocs ) */
108+ G_NX = len * nprocs;
109+ myOff = len * rank;
110+ myNX = len ;
107111
108112 err = ncmpi_def_dim ( ncid , "Y" , NY , &dimid [ 0] ) ; CHECK_ERR
109113 err = ncmpi_def_dim ( ncid , "X" , G_NX , &dimid [ 1] ) ; CHECK_ERR
@@ -124,6 +128,11 @@ int test_column_wise_$1(char *filename, int cdf)
124128 */
125129 err = ncmpi_flush ( ncid ) ; CHECK_ERR
126130
131+ if ( !coll_io ) {
132+ err = ncmpi_begin_indep_data ( ncid ) ;
133+ CHECK_ERR
134+ }
135+
127136 /* initialize the buffer with rank ID. Also make the case interesting ,
128137 by allocatsing buffersd separately */
129138 for ( i=0; i<myNX; i++ ) {
@@ -187,7 +196,11 @@ int test_column_wise_$1(char *filename, int cdf)
187196 reqs [ 2*i+1] = tmp;
188197 }
189198
190- err = ncmpi_wait_all ( ncid , num_reqs , reqs , sts ) ; CHECK_ERR
199+ if ( coll_io )
200+ err = ncmpi_wait_all ( ncid , num_reqs , reqs , sts ) ;
201+ else
202+ err = ncmpi_wait ( ncid , num_reqs , reqs , sts ) ;
203+ CHECK_ERR
191204
192205 /* check if write buffer contents have been altered after wait */
193206 for ( i=0; i<myNX; i++ ) {
@@ -221,6 +234,11 @@ int test_column_wise_$1(char *filename, int cdf)
221234 err = ncmpi_open ( MPI_COMM_WORLD , filename , NC_NOWRITE , MPI_INFO_NULL , &ncid ) ;
222235 CHECK_ERR
223236
237+ if ( !coll_io ) {
238+ err = ncmpi_begin_indep_data ( ncid ) ;
239+ CHECK_ERR
240+ }
241+
224242 err = ncmpi_inq_varid ( ncid , "var" , &varid ) ; CHECK_ERR
225243
226244 /* read back using the same access pattern */
@@ -248,7 +266,12 @@ int test_column_wise_$1(char *filename, int cdf)
248266 &reqs [ num_reqs++] ) ; CHECK_ERR
249267 start [ 1] + = nprocs;
250268 }
251- err = ncmpi_wait_all ( ncid , num_reqs , reqs , sts ) ; CHECK_ERR
269+
270+ if ( coll_io )
271+ err = ncmpi_wait_all ( ncid , num_reqs , reqs , sts ) ;
272+ else
273+ err = ncmpi_wait ( ncid , num_reqs , reqs , sts ) ;
274+ CHECK_ERR
252275
253276 /* check status of all requests */
254277 for ( i=0; i<num_reqs; i++ )
@@ -294,23 +317,42 @@ TEST_COLUMN_WISE(double)
294317TEST_COLUMN_WISE(longlong)
295318TEST_COLUMN_WISE(ulonglong)
296319
320+ # define FILE_NAME "testfile.nc"
321+
322+ static void
323+ usage(char *argv0)
324+ {
325+ char *help =
326+ "Usage: %s [ OPTIONS] ...[ filename] \n"
327+ " [ -h] Print help\n"
328+ " [ -l num] : X dimension size of local array\n"
329+ " [ filename] : output netCDF file name (default: %s)\n";
330+ fprintf(stderr, help, argv0, FILE_NAME);
331+ }
332+
297333int main(int argc, char** argv)
298334{
335+ extern int optind;
336+ extern char *optarg;
299337 char filename[ 256] ;
300- int i, nerrs=0, rank, err;
338+ int i, fmt, nerrs=0, rank, err, len, coll_io ;
301339 int cdf_formats[ 3] ={NC_FORMAT_CLASSIC, NC_FORMAT_CDF2, NC_FORMAT_CDF5};
302340
303341 MPI_Init(&argc, &argv);
304342 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
305343
306- if (argc > 2) {
307- if (!rank) printf("Usage: %s [ filename] \n",argv[ 0] );
308- MPI_Finalize();
309- return 1;
310- }
311- if (argc == 2) snprintf(filename, 256, "%s", argv[ 1] );
312- else strcpy(filename, "testfile.nc");
313- MPI_Bcast(filename, 256, MPI_CHAR, 0, MPI_COMM_WORLD);
344+ len = NX;
345+ while ((i = getopt(argc, argv, "hl:")) != EOF)
346+ switch(i) {
347+ case 'l': len = atoi(optarg);
348+ break;
349+ case 'h':
350+ default: if (rank==0) usage(argv[ 0] );
351+ MPI_Finalize();
352+ return 1;
353+ }
354+ if (argv[ optind] == NULL) strcpy(filename, FILE_NAME);
355+ else snprintf(filename, 256, "%s", argv[ optind] );
314356
315357 if (rank == 0) {
316358 char *cmd_str = (char*)malloc(strlen(argv[ 0] ) + 256);
@@ -319,30 +361,21 @@ int main(int argc, char** argv)
319361 free(cmd_str);
320362 }
321363
322- for (i=0; i<3; i++) {
323- nerrs += test_column_wise_text(filename, cdf_formats[ i] );
324- if (nerrs > 0) break;
325- nerrs += test_column_wise_schar(filename, cdf_formats[ i] );
326- if (nerrs > 0) break;
327- nerrs += test_column_wise_short(filename, cdf_formats[ i] );
328- if (nerrs > 0) break;
329- nerrs += test_column_wise_int(filename, cdf_formats[ i] );
330- if (nerrs > 0) break;
331- nerrs += test_column_wise_float(filename, cdf_formats[ i] );
332- if (nerrs > 0) break;
333- nerrs += test_column_wise_double(filename, cdf_formats[ i] );
334- if (nerrs > 0) break;
335- if (cdf_formats[ i] == NC_FORMAT_CDF5) {
336- nerrs += test_column_wise_uchar(filename, cdf_formats[ i] );
337- if (nerrs > 0) break;
338- nerrs += test_column_wise_ushort(filename, cdf_formats[ i] );
339- if (nerrs > 0) break;
340- nerrs += test_column_wise_uint(filename, cdf_formats[ i] );
341- if (nerrs > 0) break;
342- nerrs += test_column_wise_longlong(filename, cdf_formats[ i] );
343- if (nerrs > 0) break;
344- nerrs += test_column_wise_ulonglong(filename, cdf_formats[ i] );
345- if (nerrs > 0) break;
364+ for (coll_io=0; coll_io<2; coll_io++) {
365+ for (fmt=0; fmt<3; fmt++) {
366+ nerrs = TEST_DATA_TYPE(text); if (nerrs > 0) goto err_out;
367+ nerrs = TEST_DATA_TYPE(schar); if (nerrs > 0) goto err_out;
368+ nerrs = TEST_DATA_TYPE(short); if (nerrs > 0) goto err_out;
369+ nerrs = TEST_DATA_TYPE(int); if (nerrs > 0) goto err_out;
370+ nerrs = TEST_DATA_TYPE(float); if (nerrs > 0) goto err_out;
371+ nerrs = TEST_DATA_TYPE(double); if (nerrs > 0) goto err_out;
372+ if (cdf_formats[ fmt] == NC_FORMAT_CDF5) {
373+ nerrs = TEST_DATA_TYPE(uchar); if (nerrs > 0) goto err_out;
374+ nerrs = TEST_DATA_TYPE(ushort); if (nerrs > 0) goto err_out;
375+ nerrs = TEST_DATA_TYPE(uint); if (nerrs > 0) goto err_out;
376+ nerrs = TEST_DATA_TYPE(longlong); if (nerrs > 0) goto err_out;
377+ nerrs = TEST_DATA_TYPE(ulonglong); if (nerrs > 0) goto err_out;
378+ }
346379 }
347380 }
348381
@@ -357,6 +390,7 @@ int main(int argc, char** argv)
357390 if (malloc_size > 0) ncmpi_inq_malloc_list();
358391 }
359392
393+ err_out:
360394 MPI_Allreduce(MPI_IN_PLACE, &nerrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
361395 if (rank == 0) {
362396 if (nerrs) printf(FAIL_STR,nerrs);
0 commit comments