From f47f9b170dd287265d8a273de495971823910534 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Thu, 18 Jul 2019 07:10:59 -0600 Subject: [PATCH] working on nf_free_decomp --- src/clib/pioc.c | 4 ++-- src/flib/ncint_mod.F90 | 48 ++++++++++++++++++++++++++++++++++++++- src/flib/pio.F90 | 2 +- src/ncint/ncint_pio.c | 1 + tests/fncint/ftst_pio.f90 | 11 +++++---- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/clib/pioc.c b/src/clib/pioc.c index 1c5dd32bd63..4535dfd0207 100644 --- a/src/clib/pioc.c +++ b/src/clib/pioc.c @@ -705,10 +705,10 @@ PIOc_InitDecomp(int iosysid, int pio_type, int ndims, const int *gdimlen, int ma /* Broadcast next ioid to all tasks from io root.*/ if (ios->async) { - PLOG((3, "createfile bcasting pio_next_ioid %d", pio_next_ioid)); + PLOG((3, "initdecomp bcasting pio_next_ioid %d", pio_next_ioid)); if ((mpierr = MPI_Bcast(&pio_next_ioid, 1, MPI_INT, ios->ioroot, ios->my_comm))) return check_mpi(ios, NULL, mpierr, __FILE__, __LINE__); - PLOG((3, "createfile bcast pio_next_ioid %d", pio_next_ioid)); + PLOG((3, "initdecomp bcast pio_next_ioid %d", pio_next_ioid)); } /* Set the decomposition ID. */ diff --git a/src/flib/ncint_mod.F90 b/src/flib/ncint_mod.F90 index 19505d5f7d4..1602a6fe7a8 100644 --- a/src/flib/ncint_mod.F90 +++ b/src/flib/ncint_mod.F90 @@ -31,7 +31,7 @@ module ncint_mod include 'mpif.h' ! _EXTERNAL #endif - public :: nf_def_iosystem, nf_free_iosystem + public :: nf_def_iosystem, nf_free_iosystem, nf_free_decomp contains @@ -123,6 +123,52 @@ end function PIOc_finalize status = ierr end function nf_free_iosystem + !> + !! @public + !! @ingroup PIO_finalize + !! Free a decomposition. + !! + !! @param decompid the decompostion ID. + !! @author Ed Hartnett + !< + function nf_free_decomp(decompid) result(status) + integer, intent(in) :: decompid + integer(C_INT) :: cdecompid + integer(i4) :: iosysid; + integer(i4) :: ierr + integer :: status + + interface + integer(C_INT) function nc_get_iosystem(iosysid) & + bind(C, name="nc_get_iosystem") + use iso_c_binding + integer(C_INT), intent(out) :: iosysid + end function nc_get_iosystem + end interface + + interface + integer(C_INT) function PIOc_freedecomp(iosysid, ioid) & + bind(C,name="PIOc_freedecomp") + use iso_c_binding + integer(C_INT), intent(in), value :: iosysid, ioid + end function PIOc_freedecomp + end interface + + interface + integer(C_INT) function nc_free_decomp(decompid) & + bind(C, name="nc_free_decomp") + use iso_c_binding + integer(C_INT), intent(in), value :: decompid + end function nc_free_decomp + end interface + + ierr = nc_get_iosystem(iosysid) + cdecompid = decompid +! ierr = PIOc_freedecomp(iosysid, cdecompid) + ierr = nc_free_decomp(cdecompid) + status = ierr + end function nf_free_decomp + ! !> ! !! @public ! !! @ingroup PIO_initdecomp diff --git a/src/flib/pio.F90 b/src/flib/pio.F90 index b3ea14ae79d..1b48ad865e1 100644 --- a/src/flib/pio.F90 +++ b/src/flib/pio.F90 @@ -25,7 +25,7 @@ module pio pio_set_rearr_opts #ifdef NETCDF_INTEGRATION - use ncint_mod, only: nf_def_iosystem, nf_free_iosystem + use ncint_mod, only: nf_def_iosystem, nf_free_iosystem, nf_free_decomp #endif use pio_types, only : io_desc_t, file_desc_t, var_desc_t, iosystem_desc_t, & diff --git a/src/ncint/ncint_pio.c b/src/ncint/ncint_pio.c index 552f18bdd08..7664a176781 100644 --- a/src/ncint/ncint_pio.c +++ b/src/ncint/ncint_pio.c @@ -112,5 +112,6 @@ nc_def_decomp(int iosysid, int pio_type, int ndims, const int *gdimlen, int nc_free_decomp(int ioid) { + PLOG((1, "nc_free_decomp ioid %d", ioid)); return PIOc_freedecomp(diosysid, ioid); } diff --git a/tests/fncint/ftst_pio.f90 b/tests/fncint/ftst_pio.f90 index 4916bd5b016..57eabb276d9 100644 --- a/tests/fncint/ftst_pio.f90 +++ b/tests/fncint/ftst_pio.f90 @@ -15,7 +15,8 @@ program ftst_pio parameter (FILE_NAME='ftst_pio.nc') integer, dimension(3) :: data_buffer, compdof integer, dimension(1) :: dims - type(io_desc_t) :: iodesc_nCells + type(io_desc_t) :: iodesc + integer :: decompid integer :: ierr ! Set up MPI. @@ -24,7 +25,7 @@ program ftst_pio call MPI_Comm_size(MPI_COMM_WORLD, ntasks, ierr) ! These control logging in the PIO and netCDF libraries. - ierr = pio_set_log_level(2) + ierr = pio_set_log_level(3) ierr = nf_set_log_level(2) ! Define an IOSystem. @@ -34,7 +35,8 @@ program ftst_pio ! Define a decomposition. dims(1) = 3 * ntasks compdof = 3 * myRank + (/1, 2, 3/) ! Where in the global array each task writes - call PIO_initdecomp(ioSystem, PIO_int, dims, compdof, iodesc_nCells) + call PIO_initdecomp(ioSystem, PIO_int, dims, compdof, iodesc) + decompid = iodesc%ioid ! Create a file. ierr = nf_create(FILE_NAME, 64, ncid) @@ -45,7 +47,8 @@ program ftst_pio ierr = nf_close(ncid) ! Free resources. - call PIO_freedecomp(ioSystem, iodesc_nCells) + ierr = nf_free_decomp(decompid) +! call PIO_freedecomp(ioSystem, iodesc_nCells) ierr = nf_free_iosystem() ! We're done!