Skip to content

Commit

Permalink
no longer automataically deflate vars for IOTYPE_PIO_NETCDF4C if open…
Browse files Browse the repository at this point in the history
…ed through netcdf integration
  • Loading branch information
edwardhartnett committed Dec 3, 2019
1 parent a8ea44c commit 65bef9b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 55 deletions.
5 changes: 5 additions & 0 deletions src/clib/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ typedef struct file_desc_t
/** True if this task should participate in IO (only true for one
* task with netcdf serial files. */
int do_io;

/** True if this file was opened with the netCDF integration
* feature. One consequence is that PIO_IOTYPE_NETCDF4C files will
* not have deflate automatically turned on for each var. */
int ncint_file;
} file_desc_t;

/**
Expand Down
6 changes: 4 additions & 2 deletions src/clib/pio_nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2278,8 +2278,10 @@ PIOc_def_var(int ncid, const char *name, nc_type xtype, int ndims,
PLOG((3, "defined var ierr %d file->iotype %d", ierr, file->iotype));

#ifdef _NETCDF4
/* For netCDF-4 serial files, turn on compression for this variable. */
if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4C)
/* For netCDF-4 serial files, turn on compression for this
* variable, unless this file was opened through the netCDF
* integration feature. */
if (!ierr && file->iotype == PIO_IOTYPE_NETCDF4C && !file->ncint_file)
ierr = nc_def_var_deflate(file->fh, varid, 0, 1, 1);

/* For netCDF-4 parallel files, set parallel access to collective. */
Expand Down
2 changes: 2 additions & 0 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,7 @@ PIOc_createfile_int(int iosysid, int *ncidp, int *iotype, const char *filename,
if ((ierr = nc4_file_change_ncid(*ncidp, file->pio_ncid)))
return pio_err(NULL, file, ierr, __FILE__, __LINE__);
file->pio_ncid = file->pio_ncid << ID_SHIFT;
file->ncint_file++;
PLOG((2, "changed ncid to file->pio_ncid = %d", file->pio_ncid));
}
#endif /* NETCDF_INTEGRATION */
Expand Down Expand Up @@ -2807,6 +2808,7 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename,
if ((ierr = nc4_file_change_ncid(*ncidp, file->pio_ncid)))
return pio_err(NULL, file, ierr, __FILE__, __LINE__);
file->pio_ncid = file->pio_ncid << ID_SHIFT;
file->ncint_file++;
PLOG((2, "changed ncid to file->pio_ncid = %d", file->pio_ncid));
}
else
Expand Down
68 changes: 15 additions & 53 deletions tests/ncint/tst_ncint_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#define DIM_NAME_UNLIMITED "dim_unlimited"
#define DIM_NAME_X "dim_x"
#define DIM_NAME_Y "dim_y"
#define DIM_LEN_X 3
#define DIM_LEN_Y 4
#define DIM_LEN_X 3072
#define DIM_LEN_Y 1536
/* #define DIM_LEN_X 3 */
/* #define DIM_LEN_Y 4 */
#define NDIM2 2
#define NDIM3 3
#define NUM_TIMESTEPS 1
Expand Down Expand Up @@ -75,12 +77,10 @@ main(int argc, char **argv)
struct timeval starttime, endtime;
long long startt, endt;
long long delta;
float num_megabytes = 0;
float num_megabytes = DIM_LEN_X * DIM_LEN_Y * sizeof(int) / (float)1000000 * NUM_TIMESTEPS;
float delta_in_sec;
float mb_per_sec;

/* Start the clock. */
gettimeofday(&starttime, NULL);
int t;

/* Create a file with a 3D record var. */
if (nc_create(FILE_NAME, NC_PIO|NC_NETCDF4, &ncid)) PERR;
Expand All @@ -93,6 +93,7 @@ main(int argc, char **argv)
/* Calculate a decomposition for distributed arrays. */
elements_per_pe = DIM_LEN_X * DIM_LEN_Y / (ntasks - num_io_procs);
/* printf("my_rank %d elements_per_pe %ld\n", my_rank, elements_per_pe); */

if (!(compdof = malloc(elements_per_pe * sizeof(size_t))))
PERR;
for (i = 0; i < elements_per_pe; i++)
Expand All @@ -111,54 +112,14 @@ main(int argc, char **argv)
for (i = 0; i < elements_per_pe; i++)
my_data[i] = my_rank * 10 + i;

/* Start the clock. */
gettimeofday(&starttime, NULL);

/* Write some data with distributed arrays. */
if (nc_put_vard_int(ncid, varid, ioid, 0, my_data)) PERR;
for (t = 0; t < NUM_TIMESTEPS; t++)
if (nc_put_vard_int(ncid, varid, ioid, t, my_data)) PERR;
if (nc_close(ncid)) PERR;

/* Reopen the file using netCDF integration. */
{
int ndims, nvars, ngatts, unlimdimid;
nc_type xtype_in;
char var_name_in[NC_MAX_NAME + 1];
char dim_name_in[NC_MAX_NAME + 1];
int natts_in;
int dimids_in[NDIM3];
size_t dim_len_in;

/* Open the file. */
if (nc_open(FILE_NAME, NC_PIO, &ncid)) PERR;

/* Check the file. */
if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) PERR;
if (ndims != 3 || nvars != 1 || ngatts != 0 ||
unlimdimid != 0) PERR;
if (nc_inq_var(ncid, 0, var_name_in, &xtype_in, &ndims,
dimids_in, &natts_in)) PERR;
if (strcmp(var_name_in, VAR_NAME) || xtype_in != NC_INT || ndims != NDIM3
|| dimids_in[0] != 0 || dimids_in[1] != 1 || dimids_in[2] != 2 ||
natts_in != 0) PERR;
if (nc_inq_dim(ncid, 0, dim_name_in, &dim_len_in)) PERR;
if (strcmp(dim_name_in, DIM_NAME_UNLIMITED) || dim_len_in != 1) PERR;
if (nc_inq_dim(ncid, 1, dim_name_in, &dim_len_in)) PERR;
if (strcmp(dim_name_in, DIM_NAME_X) || dim_len_in != DIM_LEN_X) PERR;
if (nc_inq_dim(ncid, 2, dim_name_in, &dim_len_in)) PERR;
if (strcmp(dim_name_in, DIM_NAME_Y) || dim_len_in != DIM_LEN_Y) PERR;

/* Read distributed arrays. */
if (!(data_in = malloc(elements_per_pe * sizeof(int)))) PERR;
if (nc_get_vard_int(ncid, varid, ioid, 0, data_in)) PERR;

/* Check results. */
for (i = 0; i < elements_per_pe; i++)
if (data_in[i] != my_data[i]) PERR;

/* Close file. */
if (nc_close(ncid)) PERR;

/* Free resources. */
free(data_in);
}

/* Stop the clock. */
gettimeofday(&endtime, NULL);

Expand All @@ -168,8 +129,9 @@ main(int argc, char **argv)
delta = (endt - startt)/NUM_TIMESTEPS;
delta_in_sec = (float)delta / 1000000;
mb_per_sec = num_megabytes / delta_in_sec;
printf("\n%d\t%d\t%d\t%d\t%d\t%8.3f\t%8.1f\t%8.3f\n", ntasks, num_io_procs,
1, 0, 1, delta_in_sec, num_megabytes, mb_per_sec);
if (my_rank == num_io_procs)
printf("\n%d\t%d\t%d\t%d\t%d\t%8.3f\t%8.1f\t%8.3f\n", ntasks, num_io_procs,
1, 0, 1, delta_in_sec, num_megabytes, mb_per_sec);

free(my_data);
if (nc_free_decomp(ioid)) PERR;
Expand Down

0 comments on commit 65bef9b

Please sign in to comment.