Skip to content

Commit

Permalink
finally got fortran working with netcdf integration!
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jul 10, 2019
1 parent c08f691 commit 3b08eb8
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 12 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions src/clib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/clib/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions src/clib/pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
#include <config.h>
#include <pio.h>
#include <pio_internal.h>
#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
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/flib/pio.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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,&
Expand Down
58 changes: 57 additions & 1 deletion src/flib/piolib_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

!-----------------------------------------------------------------------
!
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions src/ncint/ncint_pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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().
*
Expand Down
13 changes: 10 additions & 3 deletions src/ncint/ncintdispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -148,16 +150,21 @@ 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)
{
int iotype;
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)))
Expand Down Expand Up @@ -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)))
Expand Down
9 changes: 6 additions & 3 deletions tests/fncint/ftst_pio.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3b08eb8

Please sign in to comment.