Skip to content

Commit 3eb34d9

Browse files
committed
add command-line option -m for choosing datatype
1 parent e5b342f commit 3eb34d9

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

benchmarks/C/aggregation.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@
111111
pattern, i, j, start[0], start[1], count[0], count[1]); \
112112
}
113113

114-
#define XTYPE NC_FLOAT
115-
116114
static int debug;
117115

118116
typedef struct {
@@ -123,6 +121,7 @@ typedef struct {
123121
int block_star;
124122
int star_block;
125123
int blocking_io;
124+
int double_xtype;
126125
MPI_Offset len;
127126
MPI_Offset w_size;
128127
MPI_Offset r_size;
@@ -166,6 +165,7 @@ int benchmark_write(char *filename,
166165
MPI_Offset bb_gsizes[3], sc_gsizes[3], bs_gsizes[3], sb_gsizes[3];
167166
MPI_Offset start[3], count[3], stride[3], lenlen;
168167
MPI_Info info=MPI_INFO_NULL;
168+
nc_type xtype = (cfg->double_xtype) ? NC_DOUBLE : NC_FLOAT;
169169

170170
MPI_Comm_rank(comm, &rank);
171171
MPI_Comm_size(comm, &nprocs);
@@ -254,28 +254,28 @@ int benchmark_write(char *filename,
254254
if (cfg->block_block) {
255255
/* variables are block-block partitioned */
256256
sprintf(name,"block_block_var_%d",v);
257-
err = ncmpi_def_var(ncid, name, XTYPE, 3, bb_dimids, &varid[v++]);
257+
err = ncmpi_def_var(ncid, name, xtype, 3, bb_dimids, &varid[v++]);
258258
ERR(err)
259259
num_reqs++;
260260
}
261261
if (cfg->star_cyclic) {
262262
/* variables are *-cyclic partitioned */
263263
sprintf(name,"star_cyclic_var_%d",v);
264-
err = ncmpi_def_var(ncid, name, XTYPE, 3, sc_dimids, &varid[v++]);
264+
err = ncmpi_def_var(ncid, name, xtype, 3, sc_dimids, &varid[v++]);
265265
ERR(err)
266266
num_reqs++;
267267
}
268268
if (cfg->block_star) {
269269
/* variables are block-* partitioned */
270270
sprintf(name,"block_star_var_%d",v);
271-
err = ncmpi_def_var(ncid, name, XTYPE, 3, bs_dimids, &varid[v++]);
271+
err = ncmpi_def_var(ncid, name, xtype, 3, bs_dimids, &varid[v++]);
272272
ERR(err)
273273
num_reqs++;
274274
}
275275
if (cfg->star_block) {
276276
/* variables are *-block partitioned */
277277
sprintf(name,"star_block_var_%d",v);
278-
err = ncmpi_def_var(ncid, name, XTYPE, 3, sb_dimids, &varid[v++]);
278+
err = ncmpi_def_var(ncid, name, xtype, 3, sb_dimids, &varid[v++]);
279279
ERR(err)
280280
num_reqs++;
281281
}
@@ -627,6 +627,7 @@ usage(char *argv0)
627627
" [-c] *-cyclic partitioning pattern\n"
628628
" [-i] block-* partitioning pattern\n"
629629
" [-j] *-block partitioning pattern\n"
630+
" [-m] use double type in both memory buffer and file\n"
630631
" [-l len]: local variable of size len x len (default 10)\n"
631632
" [-n num]: number of variables each pattern (default 1)\n"
632633
" [-t num]: number of time records (default 1)\n"
@@ -643,7 +644,7 @@ int main(int argc, char** argv) {
643644
char filename[256];
644645
int i, rank, nprocs, verbose=1, nerrs=0, enable_read, enable_write;
645646
int nvars, block_block, star_cyclic, block_star, star_block, num_records;
646-
int blocking_io;
647+
int blocking_io, double_xtype;
647648
double timing[11], max_t[11];
648649
MPI_Offset len=0, sum_w_size, sum_r_size;
649650
MPI_Comm comm=MPI_COMM_WORLD;
@@ -662,10 +663,11 @@ int main(int argc, char** argv) {
662663
enable_write = 0;
663664
num_records = 1;
664665
blocking_io = 0;
666+
double_xtype = 0;
665667

666668
/* get command-line arguments */
667669
debug = 0;
668-
while ((i = getopt(argc, argv, "hqdbcijrwxl:n:t:")) != EOF)
670+
while ((i = getopt(argc, argv, "hqdbcijmrwxl:n:t:")) != EOF)
669671
switch(i) {
670672
case 'q': verbose = 0;
671673
break;
@@ -679,6 +681,8 @@ int main(int argc, char** argv) {
679681
break;
680682
case 'j': star_block = 1;
681683
break;
684+
case 'm': double_xtype = 1;
685+
break;
682686
case 'x': blocking_io = 1;
683687
break;
684688
case 'r': enable_read = 1;
@@ -713,6 +717,7 @@ int main(int argc, char** argv) {
713717
cfg.len = len;
714718
cfg.num_records = num_records;
715719
cfg.blocking_io = blocking_io;
720+
cfg.double_xtype = double_xtype;
716721

717722
if (enable_read == 0 && enable_write == 0)
718723
enable_read = enable_write = 1;
@@ -754,10 +759,10 @@ int main(int argc, char** argv) {
754759
printf("Output NetCDF file header extent: %lld B\n", cfg.header_extent);
755760
printf("Number of MPI processes: %d\n", nprocs);
756761
printf("Total number of variables: %d\n", nvars);
757-
if (XTYPE == NC_FLOAT)
758-
printf("Data type of variables in output file: NC_FLOAT\n");
759-
else if (XTYPE == NC_DOUBLE)
762+
if (cfg.double_xtype)
760763
printf("Data type of variables in output file: NC_DOUBLE\n");
764+
else
765+
printf("Data type of variables in output file: NC_FLOAT\n");
761766
printf("Data type of variables in memory: double\n");
762767
printf("Local 2D variable size in each process: %lld x %lld\n",len,len);
763768
printf("Number of time records: %d\n",num_records);

0 commit comments

Comments
 (0)