/********************************************************************* * * Copyright (C) 2014, Northwestern University and Argonne National Laboratory * See COPYRIGHT notice in top-level directory. * *********************************************************************/ /* $Id$ */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This example tests nonblocking buffered write varn APIs, including * ncmpi_bput_varn_uint() and ncmpi_bput_varn(), * It first writes a sequence of requests with arbitrary array indices and * lengths to four variables of type NC_UINT, and reads back. * * The compile and run commands are given below, together with an ncmpidump of * the output file. * * % mpicc -O2 -o bput_varn_uint bput_varn_uint.c -lpnetcdf * % mpiexec -n 4 ./bput_varn_uint /pvfs2/wkliao/testfile.nc * % ncmpidump /pvfs2/wkliao/testfile.nc * netcdf testfile { * // file format: CDF-5 (big variables) * dimensions: * Y = 4 ; * X = 10 ; * variables: * uint var0(Y, X) ; * uint var1(Y, X) ; * uint var2(Y, X) ; * uint var3(Y, X) ; * data: * * var0 = * 1, 1, 1, 3, 3, 0, 0, 2, 3, 3, * 0, 2, 2, 2, 1, 3, 3, 2, 2, 2, * 3, 3, 2, 1, 1, 1, 0, 0, 3, 3, * 0, 0, 0, 2, 3, 3, 3, 1, 1, 1 ; * * var1 = * 2, 2, 2, 0, 0, 1, 1, 3, 0, 0, * 1, 3, 3, 3, 2, 0, 0, 3, 3, 3, * 0, 0, 3, 2, 2, 2, 1, 1, 0, 0, * 1, 1, 1, 3, 0, 0, 0, 2, 2, 2 ; * * var2 = * 3, 3, 3, 1, 1, 2, 2, 0, 1, 1, * 2, 0, 0, 0, 3, 1, 1, 0, 0, 0, * 1, 1, 0, 3, 3, 3, 2, 2, 1, 1, * 2, 2, 2, 0, 1, 1, 1, 3, 3, 3 ; * * var3 = * 0, 0, 0, 2, 2, 3, 3, 1, 2, 2, * 3, 1, 1, 1, 0, 2, 2, 1, 1, 1, * 2, 2, 1, 0, 0, 0, 3, 3, 2, 2, * 3, 3, 3, 1, 2, 2, 2, 0, 0, 0 ; * } * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include #include #include /* strcpy(), strncpy() */ #include /* getopt() */ #include #include #define NY 4 #define NX 10 #define NDIMS 2 #define ERR {if(err!=NC_NOERR){printf("Error at line %d in %s: %s\n", __LINE__,__FILE__, ncmpi_strerror(err));nerrs++;}} #define ERRS(n,a) { \ int _i; \ for (_i=0; _i<(n); _i++) { \ if ((a)[_i] != NC_NOERR) { \ printf("Error at line %d in %s: err[%d] %s\n", __LINE__,__FILE__, _i, \ ncmpi_strerror((a)[_i])); \ nerrs++; \ } \ } \ } static MPI_Offset *** calloc_3D(size_t z, size_t y, size_t x) { if (z*y*x == 0) return NULL; int _j, _k; MPI_Offset ***buf = (MPI_Offset***) malloc(z * sizeof(MPI_Offset**)); MPI_Offset **bufy = (MPI_Offset**) malloc(z*y * sizeof(MPI_Offset*)); MPI_Offset *bufx = (MPI_Offset*) calloc(z*y*x, sizeof(MPI_Offset)); for (_k=0; _k= 4) nreqs = 0; /* bufsize must be max of data type converted before and after */ MPI_Offset bufsize = 0; /* calculate length of each varn request, number of segments in each * varn request, and allocate write buffer */ for (i=0; i 0) { err = ncmpi_buffer_attach(ncid, bufsize); ERR } /* write using varn API */ for (i=0; i= 4) check_contents(ncid, varid); for (i=0; i= 4) check_contents(ncid, varid); /* free the buffer space for bput */ if (bufsize > 0) { err = ncmpi_buffer_detach(ncid); ERR } err = ncmpi_close(ncid); ERR for (i=0; i 0) printf("heap memory allocated by PnetCDF internally has %lld bytes yet to be freed\n", sum_size); } MPI_Finalize(); return (nerrs > 0); }