From 3b08eb8fc18f4494f31ff315d9f507138941ba37 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 10 Jul 2019 13:32:05 -0600 Subject: [PATCH] finally got fortran working with netcdf integration! --- configure.ac | 1 + src/clib/Makefile.am | 1 + src/clib/pio.h | 1 + src/clib/pioc.c | 15 ++++++++++ src/flib/pio.F90 | 2 +- src/flib/piolib_mod.F90 | 58 ++++++++++++++++++++++++++++++++++++++- src/ncint/ncint_pio.c | 18 +++++++++--- src/ncint/ncintdispatch.c | 13 +++++++-- tests/fncint/ftst_pio.f90 | 9 ++++-- 9 files changed, 106 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index e9efb137784..7bdced12fd7 100644 --- a/configure.ac +++ b/configure.ac @@ -280,6 +280,7 @@ fi if test "x$enable_netcdf_integration" = xyes; then AC_DEFINE([HDF5_PARALLEL],[1],[Does HDF5 library provide parallel access]) AC_DEFINE([USE_NETCDF4],[1],[Does HDF5 library provide parallel access]) + AC_DEFINE([NETCDF_INTEGRATION],[1],[Are we building with netCDF integration]) fi AM_CONDITIONAL(BUILD_NCINT, [test "x$enable_netcdf_integration" = xyes]) diff --git a/src/clib/Makefile.am b/src/clib/Makefile.am index a938e0d867a..66c7a948825 100644 --- a/src/clib/Makefile.am +++ b/src/clib/Makefile.am @@ -7,6 +7,7 @@ lib_LTLIBRARIES = libpioc.la # Are we building with netCDF integration? if BUILD_NCINT libpioc_la_LIBADD = ../ncint/libncint.la +libpioc_la_CPPFLAGS = -I${top_srcdir}/src/ncint endif # BUILD_NCINT # These linker flags specify libtool version info. diff --git a/src/clib/pio.h b/src/clib/pio.h index f1203456ca0..56b36bd732d 100644 --- a/src/clib/pio.h +++ b/src/clib/pio.h @@ -1250,6 +1250,7 @@ extern "C" { int nc_init_intracomm(MPI_Comm comp_comm, int num_iotasks, int stride, int base, int rearr, int *iosysidp); + int nc_set_iosystem(int iosysid); int nc_free_iosystem(int iosysid); int nc_init_decomp(int iosysid, int pio_type, int ndims, const int *gdimlen, diff --git a/src/clib/pioc.c b/src/clib/pioc.c index 1f0c1ab2ff8..1c5dd32bd63 100644 --- a/src/clib/pioc.c +++ b/src/clib/pioc.c @@ -9,12 +9,20 @@ #include #include #include +#ifdef NETCDF_INTEGRATION +#include "ncintdispatch.h" +#endif /* NETCDF_INTEGRATION */ #ifdef USE_MPE /* The event numbers for MPE logging. */ extern int event_num[2][NUM_EVENTS]; #endif /* USE_MPE */ +#ifdef NETCDF_INTEGRATION +/* Have we initialized? */ +extern int ncint_initialized; +#endif /* NETCDF_INTEGRATION */ + /** * @defgroup PIO_init_c Initialize the IO System * Initialize the IOSystem, including specifying number of IO and @@ -934,6 +942,13 @@ PIOc_Init_Intracomm(MPI_Comm comp_comm, int num_iotasks, int stride, int base, if ((ret = pio_init_logging())) return pio_err(NULL, NULL, ret, __FILE__, __LINE__); +#ifdef NETCDF_INTEGRATION + PLOG((1, "Initializing netcdf integration")); + /* Initialize netCDF integration layer if we need to. */ + if (!ncint_initialized) + PIO_NCINT_initialize(); +#endif /* NETCDF_INTEGRATION */ + #ifdef USE_MPE pio_start_mpe_log(INIT); #endif /* USE_MPE */ diff --git a/src/flib/pio.F90 b/src/flib/pio.F90 index b4939e29060..89c2870063d 100644 --- a/src/flib/pio.F90 +++ b/src/flib/pio.F90 @@ -21,7 +21,7 @@ module pio pio_freedecomp, pio_syncfile, & pio_finalize, pio_set_hint, pio_getnumiotasks, pio_file_is_open, & PIO_deletefile, PIO_get_numiotasks, PIO_iotype_available, & - pio_set_rearr_opts + pio_set_rearr_opts, nf_init_intracom use pio_types, only : io_desc_t, file_desc_t, var_desc_t, iosystem_desc_t, & pio_rearr_opt_t, pio_rearr_comm_fc_opt_t, pio_rearr_comm_fc_2d_enable,& diff --git a/src/flib/piolib_mod.F90 b/src/flib/piolib_mod.F90 index 8fa5e0123b9..2b77af19cd5 100644 --- a/src/flib/piolib_mod.F90 +++ b/src/flib/piolib_mod.F90 @@ -97,7 +97,8 @@ module piolib_mod PIO_deletefile, & PIO_get_numiotasks, & PIO_iotype_available, & - PIO_set_rearr_opts + PIO_set_rearr_opts, & + nf_init_intracom !----------------------------------------------------------------------- ! @@ -133,6 +134,10 @@ module piolib_mod module procedure setframe end interface PIO_setframe + interface nf_init_intracom + module procedure nf_init_intracom + end interface nf_init_intracom + !> !! Increment the record number for a future read/write of distributed !! arrays (see @ref PIO_write_darray, @ref PIO_read_darray). @@ -989,6 +994,57 @@ end function PIOc_Init_Intracomm_from_F90 #endif end subroutine init_intracom + !> + !! @public + !! @ingroup PIO_init + !! Initialize the pio subsystem. This is a collective call. Input + !! parameters are read on comp_rank=0 values on other tasks are + !! ignored. This variation of PIO_init locates the IO tasks on a + !! subset of the compute tasks. + !! + !! @param comp_rank mpi rank of each participating task, + !! @param comp_comm the mpi communicator which defines the + !! collective. + !! @param num_iotasks the number of iotasks to define. + !! @param num_aggregator the mpi aggregator count + !! @param stride the stride in the mpi rank between io tasks. + !! @param rearr @copydoc PIO_rearr_method + !! @param iosystem a derived type which can be used in subsequent + !! pio operations (defined in PIO_types). + !! @param base @em optional argument can be used to offset the first + !! io task - default base is task 1. + !! @param rearr_opts the rearranger options. + !! @author Jim Edwards + !< + subroutine nf_init_intracom(comp_rank, comp_comm, num_iotasks, num_aggregator, stride, rearr, iosystem,base, rearr_opts) + use pio_types, only : pio_internal_error, pio_rearr_opt_t + use iso_c_binding + + integer(i4), intent(in) :: comp_rank + integer(i4), intent(in) :: comp_comm + integer(i4), intent(in) :: num_iotasks + integer(i4), intent(in) :: num_aggregator + integer(i4), intent(in) :: stride + integer(i4), intent(in) :: rearr + type (iosystem_desc_t), intent(out) :: iosystem ! io descriptor to initalize + integer(i4), intent(in),optional :: base + type (pio_rearr_opt_t), intent(in), optional :: rearr_opts + integer :: ierr + + interface + integer(C_INT) function nc_set_iosystem(iosystemid) & + bind(C,name="nc_set_iosystem") + use iso_c_binding + integer(C_INT), intent(in), value :: iosystemid + end function nc_set_iosystem + end interface + + call init_intracom(comp_rank, comp_comm, num_iotasks, num_aggregator, stride, rearr, iosystem,base, rearr_opts) + + ierr = nc_set_iosystem(iosystem%iosysid) + + end subroutine nf_init_intracom + !! @public !! @ingroup PIO_init !! Initialize the pio subsystem. This is a collective call. Input diff --git a/src/ncint/ncint_pio.c b/src/ncint/ncint_pio.c index f750e0f79e8..0c9b3a16c4a 100644 --- a/src/ncint/ncint_pio.c +++ b/src/ncint/ncint_pio.c @@ -27,10 +27,6 @@ nc_init_intracomm(MPI_Comm comp_comm, int num_iotasks, int stride, int base, int { int ret; - /* Initialize if we need to. */ - if (!ncint_initialized) - PIO_NCINT_initialize(); - /* Call the PIOc_ function to initialize the intracomm. */ if ((ret = PIOc_Init_Intracomm(comp_comm, num_iotasks, stride, base, rearr, iosysidp))) @@ -42,6 +38,20 @@ nc_init_intracomm(MPI_Comm comp_comm, int num_iotasks, int stride, int base, int return PIO_NOERR; } +/** + * Set the default iosystemID. + * + * @author Ed Hartnett + */ +int +nc_set_iosystem(int iosysid) +{ + /* Remember the io system id. */ + diosysid = iosysid; + + return PIO_NOERR; +} + /** * Same as PIOc_free_iosystem(). * diff --git a/src/ncint/ncintdispatch.c b/src/ncint/ncintdispatch.c index b4d7d4a4026..e5075b61e2e 100644 --- a/src/ncint/ncintdispatch.c +++ b/src/ncint/ncintdispatch.c @@ -128,6 +128,8 @@ PIO_NCINT_initialize(void) NCINT_dispatch_table = &NCINT_dispatcher; + PLOG((1, "Adding user-defined format for netCDF PIO integration")); + /* Add our user defined format. */ if ((ret = nc_def_user_format(NC_UDF0, &NCINT_dispatcher, NULL))) return ret; @@ -148,8 +150,13 @@ PIO_NCINT_finalize(void) return NC_NOERR; } +/** + * Create a file using PIO via netCDF's nc_create(). + * + * @author Ed Hartnett + */ int -PIO_NCINT_create(const char* path, int cmode, size_t initialsz, int basepe, +PIO_NCINT_create(const char *path, int cmode, size_t initialsz, int basepe, size_t *chunksizehintp, void *parameters, const NC_Dispatch *dispatch, NC *nc_file) { @@ -157,7 +164,7 @@ PIO_NCINT_create(const char* path, int cmode, size_t initialsz, int basepe, iosystem_desc_t *ios; /* Pointer to io system information. */ int ret; - LOG((1, "PIO_NCINT_create path = %s mode = %x", path, mode)); + PLOG((1, "PIO_NCINT_create path = %s mode = %x", path, cmode)); /* Get the IO system info from the id. */ if (!(ios = pio_get_iosystem_from_id(diosysid))) @@ -191,7 +198,7 @@ PIO_NCINT_open(const char *path, int mode, int basepe, size_t *chunksizehintp, iosystem_desc_t *ios; /* Pointer to io system information. */ int ret; - LOG((1, "PIO_NCINT_open path = %s mode = %x", path, mode)); + PLOG((1, "PIO_NCINT_open path = %s mode = %x", path, mode)); /* Get the IO system info from the id. */ if (!(ios = pio_get_iosystem_from_id(diosysid))) diff --git a/tests/fncint/ftst_pio.f90 b/tests/fncint/ftst_pio.f90 index 0283ed1673b..1172cd65534 100644 --- a/tests/fncint/ftst_pio.f90 +++ b/tests/fncint/ftst_pio.f90 @@ -11,17 +11,20 @@ program ftst_pio type(iosystem_desc_t) :: ioSystem integer :: niotasks = 1, numAggregator = 0, stride = 1, base = 0 integer :: ncid + character*(*) FILE_NAME + parameter (FILE_NAME='ftst_pio.nc') integer :: ierr call MPI_Init(ierr) call MPI_Comm_rank(MPI_COMM_WORLD, myRank, ierr) call MPI_Comm_size(MPI_COMM_WORLD, ntasks, ierr) - ierr = pio_set_log_level(1) - call PIO_init(myRank, MPI_COMM_WORLD, niotasks, numAggregator, & + ierr = pio_set_log_level(2) + ierr = nf_set_log_level(2) + call nf_init_intracom(myRank, MPI_COMM_WORLD, niotasks, numAggregator, & stride, PIO_rearr_subset, ioSystem, base) - ierr = nf_create('ftst_pio.nc', nf_clobber, ncid) + ierr = nf_create(FILE_NAME, 64, ncid) ierr = nf_close(ncid) call PIO_finalize(ioSystem, ierr)