Skip to content

Commit 6c671a6

Browse files
committed
test/C add an option to run in indep I/O mode
1 parent 50e639e commit 6c671a6

4 files changed

Lines changed: 114 additions & 34 deletions

File tree

test/C/pres_temp_4D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define NREC 2
99
#define REC_NAME "time"
1010
#define LVL_NAME "level"
11-
#define NLVL 10
11+
#define NLVL 512
1212

1313
/* Names of things. */
1414
#define PRES_NAME "pressure"

test/C/pres_temp_4D_rd.c

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,32 @@
2222
#include <stdio.h>
2323
#include <stdlib.h>
2424
#include <string.h>
25+
#include <unistd.h> /* getopt() */
2526
#include <libgen.h> /* basename() */
26-
#include <pnetcdf.h>
27+
2728
#include <mpi.h>
29+
#include <pnetcdf.h>
2830
#include <testutils.h>
2931

3032
#include "pres_temp_4D.h"
3133

34+
static void
35+
usage(char *argv0)
36+
{
37+
char *help =
38+
"Usage: %s [OPTIONS]...[filename]\n"
39+
" [-h] Print help\n"
40+
" [-a] use independent I/O\n"
41+
" [filename]: input netCDF file name (default: %s)\n";
42+
fprintf(stderr, help, argv0, FILE_NAME);
43+
}
44+
3245
int main(int argc, char **argv)
3346
{
34-
int rank, nprocs, ncid, pres_varid, temp_varid;
47+
extern int optind;
48+
extern char *optarg;
49+
char filename[256];
50+
int rank, nprocs, ncid, pres_varid, temp_varid, indep_io;
3551
int lat_varid, lon_varid;
3652

3753
/* The start and count arrays will tell the netCDF library where to
@@ -52,20 +68,22 @@ int main(int argc, char **argv)
5268
/* Error handling. */
5369
int err, nerrs = 0;
5470

55-
char *filename = FILE_NAME;
56-
5771
MPI_Init(&argc, &argv);
5872
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
5973
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
6074

61-
if (argc > 3) {
62-
if (!rank)
63-
printf("Usage: %s [filename]\n", argv[0]);
64-
MPI_Finalize();
65-
return 1;
66-
}
67-
68-
if (argc > 1) filename = argv[1];
75+
indep_io = 0;
76+
while ((i = getopt(argc, argv, "ha")) != EOF)
77+
switch(i) {
78+
case 'a': indep_io = 1;
79+
break;
80+
case 'h':
81+
default: if (rank==0) usage(argv[0]);
82+
MPI_Finalize();
83+
return 1;
84+
}
85+
if (argv[optind] == NULL) strcpy(filename, FILE_NAME);
86+
else snprintf(filename, 256, "%s", argv[optind]);
6987

7088
/* Open the file. */
7189
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_NOWRITE, MPI_INFO_NULL, &ncid);
@@ -75,6 +93,11 @@ int main(int argc, char **argv)
7593
goto err_out;
7694
}
7795

96+
if (indep_io) {
97+
err = ncmpi_begin_indep_data(ncid);
98+
CHECK_ERR
99+
}
100+
78101
if (rank == 0) {
79102
char *cmd_str = (char *)malloc(strlen(argv[0]) + 256);
80103
int format;
@@ -96,9 +119,15 @@ int main(int argc, char **argv)
96119
/* Read the coordinate variable data. */
97120
memset(lats, 0, sizeof(float) * NLAT);
98121
memset(lons, 0, sizeof(float) * NLON);
99-
err = ncmpi_get_var_float_all(ncid, lat_varid, &lats[0]);
122+
if (indep_io)
123+
err = ncmpi_get_var_float(ncid, lat_varid, &lats[0]);
124+
else
125+
err = ncmpi_get_var_float_all(ncid, lat_varid, &lats[0]);
100126
CHECK_ERR
101-
err = ncmpi_get_var_float_all(ncid, lon_varid, &lons[0]);
127+
if (indep_io)
128+
err = ncmpi_get_var_float(ncid, lat_varid, &lats[0]);
129+
else
130+
err = ncmpi_get_var_float_all(ncid, lon_varid, &lons[0]);
102131
CHECK_ERR
103132

104133
/* Check the coordinate variable data. */
@@ -164,9 +193,15 @@ int main(int argc, char **argv)
164193
/* Read and check one record at a time. */
165194
for (rec = 0; rec < NREC; rec++) {
166195
start[0] = rec;
167-
err = ncmpi_get_vara_float_all(ncid, pres_varid, start, count, &pres_in[0][0]);
196+
if (indep_io)
197+
err = ncmpi_get_vara_float(ncid, pres_varid, start, count, &pres_in[0][0]);
198+
else
199+
err = ncmpi_get_vara_float_all(ncid, pres_varid, start, count, &pres_in[0][0]);
168200
CHECK_ERR
169-
err = ncmpi_get_vara_float_all(ncid, temp_varid, start, count, &temp_in[0][0]);
201+
if (indep_io)
202+
err = ncmpi_get_vara_float(ncid, temp_varid, start, count, &temp_in[0][0]);
203+
else
204+
err = ncmpi_get_vara_float_all(ncid, temp_varid, start, count, &temp_in[0][0]);
170205
CHECK_ERR
171206

172207
/* Check the data. */

test/C/pres_temp_4D_wr.c

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,36 @@
2222
#include <stdio.h>
2323
#include <stdlib.h>
2424
#include <string.h>
25+
#include <unistd.h> /* getopt() */
2526
#include <libgen.h> /* basename() */
26-
#include <pnetcdf.h>
27+
2728
#include <mpi.h>
29+
#include <pnetcdf.h>
2830
#include <testutils.h>
2931

3032
#include "pres_temp_4D.h"
3133

34+
static void
35+
usage(char *argv0)
36+
{
37+
char *help =
38+
"Usage: %s [OPTIONS]...[filename]\n"
39+
" [-h] Print help\n"
40+
" [-a] use independent I/O\n"
41+
" [-f num]: output file format: 1,2,5 for classic, 4 for netCDF4\n"
42+
" [filename]: output netCDF file name (default: %s)\n";
43+
fprintf(stderr, help, argv0, FILE_NAME);
44+
}
45+
3246
int main(int argc, char **argv)
3347
{
48+
extern int optind;
49+
extern char *optarg;
50+
char filename[256];
51+
3452
/* IDs for the netCDF file, dimensions, and variables. */
3553
int nprocs, rank, nerrs = 0;
36-
int ncid;
54+
int ncid, indep_io, fmt;
3755
int lon_dimid, lat_dimid, lvl_dimid, rec_dimid;
3856
int lat_varid, lon_varid, pres_varid, temp_varid;
3957
int dimids[NDIMS];
@@ -57,23 +75,34 @@ int main(int argc, char **argv)
5775
/* Error handling. */
5876
int err;
5977

60-
char *filename = FILE_NAME;
61-
6278
MPI_Init(&argc, &argv);
6379
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
6480
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
6581

66-
if (argc > 3) {
67-
if (!rank)
68-
printf("Usage: %s [filename]\n", argv[0]);
69-
MPI_Finalize();
70-
return 1;
71-
}
72-
73-
if (argc > 1) filename = argv[1];
74-
75-
if (argc > 2 && atoi(argv[2]) == 4)
82+
indep_io = 0;
83+
fmt = 1;
84+
while ((i = getopt(argc, argv, "haf:")) != EOF)
85+
switch(i) {
86+
case 'a': indep_io = 1;
87+
break;
88+
case 'f': fmt = atoi(optarg);
89+
break;
90+
case 'h':
91+
default: if (rank==0) usage(argv[0]);
92+
MPI_Finalize();
93+
return 1;
94+
}
95+
if (argv[optind] == NULL) strcpy(filename, FILE_NAME);
96+
else snprintf(filename, 256, "%s", argv[optind]);
97+
98+
if (fmt == 1)
99+
format = NC_FORMAT_CLASSIC;
100+
else if (fmt == 2)
101+
format = NC_FORMAT_64BIT_OFFSET;
102+
else if (fmt == 4)
76103
format = NC_FORMAT_NETCDF4;
104+
else if (fmt == 5)
105+
format = NC_FORMAT_64BIT_DATA;
77106

78107
if (rank == 0) {
79108
char *cmd_str = (char *)malloc(strlen(argv[0]) + 256);
@@ -161,6 +190,11 @@ int main(int argc, char **argv)
161190
err = ncmpi_enddef(ncid);
162191
CHECK_ERR
163192

193+
if (indep_io) {
194+
err = ncmpi_begin_indep_data(ncid);
195+
CHECK_ERR
196+
}
197+
164198
err = ncmpi_begin_indep_data(ncid);
165199
/* Write the coordinate variable data. This will put the latitudes
166200
and longitudes of our data grid into the netCDF file. */
@@ -224,9 +258,15 @@ int main(int argc, char **argv)
224258

225259
for (rec = 0; rec < NREC; rec++) {
226260
start[0] = rec;
227-
err = ncmpi_put_vara_float_all(ncid, pres_varid, start, count, &pres_out[0][0]);
261+
if (indep_io)
262+
err = ncmpi_put_vara_float(ncid, pres_varid, start, count, &pres_out[0][0]);
263+
else
264+
err = ncmpi_put_vara_float_all(ncid, pres_varid, start, count, &pres_out[0][0]);
228265
CHECK_ERR
229-
err = ncmpi_put_vara_float_all(ncid, temp_varid, start, count, &temp_out[0][0]);
266+
if (indep_io)
267+
err = ncmpi_put_vara_float(ncid, temp_varid, start, count, &temp_out[0][0]);
268+
else
269+
err = ncmpi_put_vara_float_all(ncid, temp_varid, start, count, &temp_out[0][0]);
230270
CHECK_ERR
231271
}
232272

test/parallel_run.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ for i in ${check_PROGRAMS} ; do
290290
fi
291291

292292
done # safe_modes
293-
rm -f ${OUTDIR}/$i*nc*
293+
294+
if test "x$i" = xpres_temp_4D_wr ; then
295+
rm -f ${OUTDIR}/pres_temp_4D*.nc*
296+
else
297+
rm -f ${OUTDIR}/$i*nc*
298+
fi
294299
done # check_PROGRAMS
295300

0 commit comments

Comments
 (0)