/********************************************************************* * * Copyright (C) 2018, Northwestern University and Argonne National Laboratory * See COPYRIGHT notice in top-level directory. * *********************************************************************/ /* $Id$ */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This program shows how to use a single vard API call to write or read two * consecutive variables. This example uses two MPI datatype constructors, * MPI_Type_create_subarray and MPI_Type_create_hindexed, to create the same * subarray view for two variables, but with different lower and upper bound * MPI type maps. The two datatypes are then concatenated into a single * filetype. * * To compile: * mpicc -O2 vard_mvars.c -o vard_mvars -lpnetcdf * * Example commands for MPI run and outputs from running ncmpidump on the * NetCDF file produced by this example program: * * % mpiexec -n 4 ./vard_mvars /pvfs2/wkliao/testfile.nc * * The expected results from the output file contents are: * * % ncmpidump testfile.nc * netcdf testfile { * // file format: CDF-1 * dimensions: * REC_DIM = UNLIMITED ; // (2 currently) * Y = 2 ; * X = 20 ; * variables: * int fix_var0(Y, X) ; * int fix_var1(Y, X) ; * int rec_var2(REC_DIM, Y, X) ; * int rec_var3(REC_DIM, Y, X) ; * data: * * fix_var0 = * 0, 1, 2, 3, 4, 100, 101, 102, 103, 104, 200, 201, 202, 203, 204, 300, 301, * 302, 303, 304, * 10, 11, 12, 13, 14, 110, 111, 112, 113, 114, 210, 211, 212, 213, 214, 310, * 311, 312, 313, 314 ; * * fix_var1 = * 1000, 1001, 1002, 1003, 1004, 1100, 1101, 1102, 1103, 1104, 1200, 1201, * 1202, 1203, 1204, 1300, 1301, 1302, 1303, 1304, * 1010, 1011, 1012, 1013, 1014, 1110, 1111, 1112, 1113, 1114, 1210, 1211, * 1212, 1213, 1214, 1310, 1311, 1312, 1313, 1314 ; * * rec_var2 = * _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, * _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, * 2000, 2001, 2002, 2003, 2004, 2100, 2101, 2102, 2103, 2104, 2200, 2201, * 2202, 2203, 2204, 2300, 2301, 2302, 2303, 2304, * 2010, 2011, 2012, 2013, 2014, 2110, 2111, 2112, 2113, 2114, 2210, 2211, * 2212, 2213, 2214, 2310, 2311, 2312, 2313, 2314 ; * * rec_var3 = * _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, * _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, * 3000, 3001, 3002, 3003, 3004, 3100, 3101, 3102, 3103, 3104, 3200, 3201, * 3202, 3203, 3204, 3300, 3301, 3302, 3303, 3304, * 3010, 3011, 3012, 3013, 3014, 3110, 3111, 3112, 3113, 3114, 3210, 3211, * 3212, 3213, 3214, 3310, 3311, 3312, 3313, 3314 ; * } */ #include #include #include #include /* getopt() */ #include #include #define NY 2 #define NX 5 #define ERR {if(err!=NC_NOERR){printf("Error at line %d in %s: %s\n", __LINE__,__FILE__, ncmpi_strerror(err));nerrs++;}} #define CHECK_VALUE(buf,base) { \ for (j=0; j------------------------------------------------------------*/ int main(int argc, char **argv) { extern int optind; char filename[256]; int i, j, err, verbose=1, ncid, varid[4], dimids[3], nerrs=0; int rank, nprocs, *buf[2]; int array_of_sizes[2], array_of_subsizes[2], array_of_starts[2]; int array_of_blocklengths[NY]; MPI_Offset recsize, start[2], count[2], offset[2]; MPI_Aint a0, a1, array_of_displacements[NY]; MPI_Datatype buftype, vtype[2], filetype; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* get command-line arguments */ while ((i = getopt(argc, argv, "hq")) != EOF) switch(i) { case 'q': verbose = 0; break; case 'h': default: if (rank==0) usage(argv[0]); MPI_Finalize(); return 1; } if (argv[optind] == NULL) strcpy(filename, "testfile.nc"); else snprintf(filename, 256, "%s", argv[optind]); MPI_Bcast(filename, 256, MPI_CHAR, 0, MPI_COMM_WORLD); if (verbose && rank == 0) printf("%s: example of using vard APIs to write/read two variables\n",__FILE__); buf[0] = (int*)malloc(NY * NX * sizeof(int)); for (j=0; j 0) printf("heap memory allocated by PnetCDF internally has %lld bytes yet to be freed\n", sum_size); } MPI_Allreduce(MPI_IN_PLACE, &nerrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); MPI_Finalize(); return (nerrs > 0); }