/* This is part of the netCDF package. Copyright 2018 University Corporation for Atmospheric Research/Unidata See COPYRIGHT file for conditions of use. Test fix of bug involving creation of a file with PnetCDF APIs, then opening and modifying the file with netcdf. Author: Wei-keng Liao. */ #include #include "err_macros.h" #include #include #include #include #include #include #include #define NVARS 6 #define NX 5 #define FILENAME "tst_pnetcdf.nc" #define CHK_ERR(e) { \ if (e != NC_NOERR) { \ printf("Error at %s:%d : %s\n", __FILE__,__LINE__, nc_strerror(e)); \ goto fn_exit; \ } \ } #define EXP_ERR(e, exp) { \ if (e != exp) { \ printf("Error at %s:%d : expect "#exp" but got %d\n", __FILE__,__LINE__, e); \ } \ } int main(int argc, char* argv[]) { int i, j, rank, nprocs, ncid, cmode, varid[NVARS], dimid[2], *buf; int st, nerrs=0; char str[32]; size_t start[2], count[2]; MPI_Comm comm=MPI_COMM_SELF; MPI_Info info=MPI_INFO_NULL; printf("\n*** Testing bug fix with changing PnetCDF variable offsets..."); MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs > 1 && rank == 0) printf("This test program is intended to run on ONE process\n"); if (rank > 0) goto fn_exit; /* first, use PnetCDF to create a file with default header/variable alignment */ #ifdef DISABLE_PNETCDF_ALIGNMENT MPI_Info_create(&info); MPI_Info_set(info, "nc_header_align_size", "1"); MPI_Info_set(info, "nc_var_align_size", "1"); #endif cmode = NC_CLOBBER; st = nc_create_par(FILENAME, cmode, comm, info, &ncid); #ifdef USE_PNETCDF CHK_ERR(st) #else EXP_ERR(st, NC_ENOTBUILT) goto fn_exit; #endif /* define dimension */ st = nc_def_dim(ncid, "Y", NC_UNLIMITED, &dimid[0]); CHK_ERR(st) st = nc_def_dim(ncid, "X", NX, &dimid[1]); CHK_ERR(st) /* Odd numbers are fixed variables, even numbers are record variables */ for (i=0; i 0); } /* Compile: mpicc -g -o nc_pnc nc_pnc.c -lnetcdf -lcurl -lhdf5_hl -lhdf5 -lpnetcdf -lz -lm Run: nc_pnc Standard Output: At the time of this test is written, I used the following libraries. HDF5 version 1.8.10 netCDF version 4.2.1.1 and PnetCDF version 1.3.1 If macro DISABLE_PNETCDF_ALIGNMENT is defined (i.e. disable PnetCDF alignment) then there is no standard output. If macro DISABLE_PNETCDF_ALIGNMENT is NOT defined (i.e. default PnetCDF alignment) then this test reports unexpected read values below. unexpected read value var i=1 buf[j=0]=0 should be 10 unexpected read value var i=1 buf[j=1]=0 should be 11 unexpected read value var i=1 buf[j=2]=0 should be 12 unexpected read value var i=1 buf[j=3]=0 should be 13 unexpected read value var i=1 buf[j=4]=0 should be 14 unexpected read value var i=3 buf[j=0]=0 should be 30 unexpected read value var i=3 buf[j=1]=0 should be 31 unexpected read value var i=3 buf[j=2]=0 should be 32 unexpected read value var i=3 buf[j=3]=0 should be 33 unexpected read value var i=3 buf[j=4]=0 should be 34 unexpected read value var i=5 buf[j=0]=0 should be 50 unexpected read value var i=5 buf[j=1]=0 should be 51 unexpected read value var i=5 buf[j=2]=0 should be 52 unexpected read value var i=5 buf[j=3]=0 should be 53 unexpected read value var i=5 buf[j=4]=0 should be 54 */