|
| 1 | +/* Copyright 2022, UCAR/Unidata See COPYRIGHT file for copying and |
| 2 | + * redistribution conditions. |
| 3 | + * |
| 4 | + * This parallel I/O test checks the behavior of nc_inq_dimlen() after |
| 5 | + * parallel I/O writes. |
| 6 | + * |
| 7 | + * This program taken from a PNetCDF issue: |
| 8 | + * https://github.com/Parallel-NetCDF/PnetCDF/issues/72, thanks |
| 9 | + * wkliao! |
| 10 | + * |
| 11 | + * wkliao, Ed Hartnett, 4/11/22 |
| 12 | + */ |
| 13 | + |
| 14 | +#include <nc_tests.h> |
| 15 | +#include "err_macros.h" |
| 16 | +#include <stdio.h> |
| 17 | +#include <stdlib.h> |
| 18 | +#include <mpi.h> |
| 19 | +#include <netcdf.h> |
| 20 | +#include <netcdf_par.h> |
| 21 | + |
| 22 | +#define FILENAME "tst_parallel6.nc" |
| 23 | + |
| 24 | +int main(int argc, char** argv) |
| 25 | +{ |
| 26 | + int err = NC_NOERR, rank, nprocs; |
| 27 | + int ncid, varid, dimid; |
| 28 | + size_t start[1], count[1], nrecs; |
| 29 | + |
| 30 | + MPI_Init(&argc, &argv); |
| 31 | + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); |
| 32 | + MPI_Comm_rank(MPI_COMM_WORLD, &rank); |
| 33 | + |
| 34 | + if (!rank) |
| 35 | + printf("\n*** Testing parallel I/O.\n"); |
| 36 | + |
| 37 | + if (!rank) |
| 38 | + printf("*** testing record lenth with multiple processes writing records..."); |
| 39 | + |
| 40 | + /* nc_set_log_level(4); */ |
| 41 | + if (nc_create_par(FILENAME, NC_CLOBBER | NC_NETCDF4, MPI_COMM_WORLD, |
| 42 | + MPI_INFO_NULL, &ncid)) ERR; |
| 43 | + |
| 44 | + if (nc_def_dim(ncid, "time", NC_UNLIMITED, &dimid)) ERR; |
| 45 | + if (nc_def_var(ncid, "var", NC_INT, 1, &dimid, &varid)) ERR; |
| 46 | + if (nc_var_par_access(ncid, varid, NC_COLLECTIVE)) ERR; |
| 47 | + if (nc_enddef(ncid)) ERR; |
| 48 | + |
| 49 | + start[0] = rank; |
| 50 | + count[0] = 1; |
| 51 | + if (nc_put_vara_int(ncid, varid, start, count, &rank)) ERR; |
| 52 | + if (nc_inq_dimlen(ncid, dimid, &nrecs)) ERR; |
| 53 | + if (nc_close(ncid)) ERR; |
| 54 | + /* nc_set_log_level(-1); */ |
| 55 | + |
| 56 | + if (nrecs != nprocs) |
| 57 | + { |
| 58 | + printf("Rank %d error at line %d of file %s:\n",rank,__LINE__,__FILE__); |
| 59 | + printf("\tafter writing start=%zd count=%zd\n", start[0], count[0]); |
| 60 | + printf("\texpecting number of records = %d but got %ld\n", |
| 61 | + nprocs, nrecs); |
| 62 | + ERR; |
| 63 | + } |
| 64 | + |
| 65 | + if (!rank) |
| 66 | + SUMMARIZE_ERR; |
| 67 | + |
| 68 | + MPI_Finalize(); |
| 69 | + |
| 70 | + if (!rank) |
| 71 | + FINAL_RESULTS; |
| 72 | + |
| 73 | + return 0; |
| 74 | +} |
0 commit comments