From 6d3014bad5a1874bb9e82e80492e25f675854005 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 23 Jun 2017 15:27:19 +0200 Subject: [PATCH] Fortran examples: - adapted for serial compilation, closing #8 --- examples/H5/Makefile.am | 7 +++++-- examples/H5/openclosef.f90 | 21 ++++++++++++++----- examples/H5/queryf.f90 | 15 ++++++++----- examples/H5/read_file_attribsf.f90 | 13 ++++++++---- examples/H5/read_step_attribsf.f90 | 18 ++++++++++------ examples/H5/write_file_attribsf.f90 | 15 +++++++++---- examples/H5/write_step_attribsf.f90 | 15 +++++++++---- examples/H5Block/Makefile.am | 3 +-- examples/H5Block/read_write_scalar_fieldf.f90 | 17 +++++++++++++-- examples/H5Part/Makefile.am | 5 ++--- examples/H5Part/read_canonicalviewf.f90 | 12 +++++++++-- examples/H5Part/read_core_vfdf.f90 | 13 +++++++++--- examples/H5Part/read_setnparticlesf.f90 | 12 ++++++++++- examples/H5Part/read_setviewf.f90 | 16 +++++++++++--- examples/H5Part/read_stridedf.f90 | 15 +++++++++++-- examples/H5Part/write_core_vfdf.f90 | 17 +++++++++++---- examples/H5Part/write_setnparticlesf.f90 | 16 ++++++++++---- examples/H5Part/write_setviewf.f90 | 17 +++++++++++---- examples/H5Part/write_stridedf.f90 | 13 ++++++++++-- examples/include/examples.f90 | 3 +++ 20 files changed, 201 insertions(+), 62 deletions(-) create mode 100644 examples/include/examples.f90 diff --git a/examples/H5/Makefile.am b/examples/H5/Makefile.am index fa8ad1d..0cb3425 100644 --- a/examples/H5/Makefile.am +++ b/examples/H5/Makefile.am @@ -8,6 +8,7 @@ # AM_CPPFLAGS += -I${abs_top_srcdir}/src/include +AM_CPPFLAGS += -I${abs_top_srcdir}/examples/include FFLAGS += -cpp $(AM_CPPFLAGS) AM_LDFLAGS += -L${abs_top_builddir}/src/h5core/.libs @@ -39,7 +40,7 @@ noinst_PROGRAMS += \ endif if ENABLE_FORTRAN -if ENABLE_PARALLEL +#if ENABLE_PARALLEL noinst_PROGRAMS += \ openclosef \ queryf \ @@ -54,9 +55,11 @@ read_file_attribsf_SOURCES = read_file_attribsf.f90 read_step_attribsf_SOURCES = read_step_attribsf.f90 write_file_attribsf_SOURCES = write_file_attribsf.f90 write_step_attribsf_SOURCES = write_step_attribsf.f90 -endif +#endif endif endif +all: ${noinst_PROGRAMS} + %.o : %.f90 $(FC) $(FFLAGS) -c $< diff --git a/examples/H5/openclosef.f90 b/examples/H5/openclosef.f90 index 9475ba3..fa128c8 100644 --- a/examples/H5/openclosef.f90 +++ b/examples/H5/openclosef.f90 @@ -14,22 +14,33 @@ program openclose implicit none +#if defined(PARALLEL_IO) include 'mpif.h' - - integer :: comm, rank, ierr +#endif + integer :: comm, rank integer*8 :: file_id, status integer*8 :: props - + +#if defined(PARALLEL_IO) + integer :: ierr comm = MPI_COMM_WORLD call mpi_init(ierr) call mpi_comm_rank(comm, rank, ierr) - +#else + comm = 0 + rank = 1 +#endif + props = h5_createprop_file () +#if defined(PARALLEL_IO) status = h5_setprop_file_mpio_collective (props, comm) +#endif file_id = h5_openfile ("testfile.h5", H5_O_WRONLY, props) status = h5_closeprop (props) status = h5_closefile (file_id); +#if defined(PARALLEL_IO) call mpi_finalize(ierr) - +#endif + end program openclose diff --git a/examples/H5/queryf.f90 b/examples/H5/queryf.f90 index 45d27b4..e9ac0c3 100644 --- a/examples/H5/queryf.f90 +++ b/examples/H5/queryf.f90 @@ -1,5 +1,5 @@ ! - ! Copyright (c) 2006-2013, The Regents of the University of California, + ! Copyright (c) 2006-2017, The Regents of the University of California, ! through Lawrence Berkeley National Laboratory (subject to receipt of any ! required approvals from the U.S. Dept. of Energy) and the Paul Scherrer ! Institut (Switzerland). All rights reserved.! @@ -7,15 +7,17 @@ ! License: see file COPYING in top level of source distribution. ! include 'H5hut.f90' - + program query use H5hut implicit none +#if defined(PARALLEL_IO) include 'mpif.h' +#endif ! the file name we want to read - character (len=*), parameter :: FNAME1 = "example_file_attribs.h5" - character (len=*), parameter :: FNAME2 = "example_step_attribs.h5" + character (len=*), parameter :: FNAME1 = "example_file_attribs.h5" + character (len=*), parameter :: FNAME2 = "example_step_attribs.h5" ! verbosity level: set it to a power of 2 minus one or zero integer*8, parameter :: verbosity_level = 1 @@ -23,7 +25,9 @@ ! used for mpi error return integer :: ierr +#if defined(PARALLEL_IO) call mpi_init (ierr) +#endif ! abort program on any H5hut error call h5_abort_on_error () @@ -33,8 +37,9 @@ call query_file (FNAME1); call query_file (FNAME2); +#if defined(PARALLEL_IO) call mpi_finalize(ierr) - +#endif call exit (ierr) contains diff --git a/examples/H5/read_file_attribsf.f90 b/examples/H5/read_file_attribsf.f90 index 640558a..95c8ae8 100644 --- a/examples/H5/read_file_attribsf.f90 +++ b/examples/H5/read_file_attribsf.f90 @@ -11,7 +11,9 @@ program read_file_attribs use H5hut implicit none +#if defined(PARALLEL_IO) include 'mpif.h' +#endif ! the file name we want to read character (len=*), parameter :: FNAME = "example_file_attribs.h5" @@ -40,9 +42,6 @@ real*4, allocatable :: r4_value (:) real*8, allocatable :: r8_value (:) - ! used for mpi error return - integer :: ierr - ! H5hut file id integer*8 :: file_id @@ -58,7 +57,12 @@ ! loop index integer*8 i +#if defined(PARALLEL_IO) + ! used for mpi error return + integer :: ierr + call mpi_init (ierr) +#endif ! abort program on any H5hut error call h5_abort_on_error () @@ -109,6 +113,7 @@ ! cleanup status = h5_closefile (file_id) +#if defined(PARALLEL_IO) call mpi_finalize(ierr) - +#endif end program read_file_attribs diff --git a/examples/H5/read_step_attribsf.f90 b/examples/H5/read_step_attribsf.f90 index f5455ef..601a786 100644 --- a/examples/H5/read_step_attribsf.f90 +++ b/examples/H5/read_step_attribsf.f90 @@ -11,8 +11,11 @@ program read_step_attribs use H5hut implicit none - include 'mpif.h' +#if defined(PARALLEL_IO) + include 'mpif.h' +#endif + ! the file name we want to read character (len=*), parameter :: FNAME = "example_file_attribs.h5" @@ -36,9 +39,6 @@ real*4, allocatable :: r4_value (:) real*8, allocatable :: r8_value (:) - ! used for mpi error return - integer :: ierr - ! H5hut file id integer*8 :: file_id @@ -54,8 +54,13 @@ ! loop index integer*8 i - call mpi_init (ierr) +#if defined(PARALLEL_IO) + ! used for mpi error return + integer :: ierr + call mpi_init (ierr) +#endif + ! abort program on any H5hut error call h5_abort_on_error () @@ -108,6 +113,7 @@ ! cleanup status = h5_closefile (file_id) +#if defined(PARALLEL_IO) call mpi_finalize(ierr) - +#endif end program read_step_attribs diff --git a/examples/H5/write_file_attribsf.f90 b/examples/H5/write_file_attribsf.f90 index 085fc83..7f7d518 100644 --- a/examples/H5/write_file_attribsf.f90 +++ b/examples/H5/write_file_attribsf.f90 @@ -11,8 +11,11 @@ program write_file_attribs use H5hut implicit none - include 'mpif.h' +#if defined(PARALLEL_IO) + include 'mpif.h' +#endif + integer*8, parameter :: verbosity_level = 1 character (len=*), parameter :: FNAME = "example_file_attribs.h5" @@ -29,11 +32,13 @@ real*4, parameter, dimension(*) :: r4_value = (/2.71828/) real*8, parameter, dimension(*) :: r8_value = (/3.141592653589793238462643383279502884197169/) - integer :: ierr integer*8 :: file_id, status +#if defined(PARALLEL_IO) + integer :: ierr call mpi_init(ierr) - +#endif + ! abort program on any H5hut error call h5_abort_on_error() @@ -51,6 +56,8 @@ ! cleanup status = h5_closefile (file_id) - call mpi_finalize(ierr) +#if defined(PARALLEL_IO) + call mpi_finalize(ierr) +#endif end program write_file_attribs diff --git a/examples/H5/write_step_attribsf.f90 b/examples/H5/write_step_attribsf.f90 index 239df17..f3a23f2 100644 --- a/examples/H5/write_step_attribsf.f90 +++ b/examples/H5/write_step_attribsf.f90 @@ -11,8 +11,11 @@ program write_step_attribs use H5hut implicit none - include 'mpif.h' +#if defined(PARALLEL_IO) + include 'mpif.h' +#endif + integer*8, parameter :: verbosity_level = 1 character (len=*), parameter :: FNAME = "example_step_attribs.h5" @@ -29,11 +32,13 @@ real*4, parameter, dimension(*) :: r4_value = (/2.71828/) real*8, parameter, dimension(*) :: r8_value = (/3.141592653589793238462643383279502884197169/) - integer :: ierr integer*8 :: file_id, status +#if defined(PARALLEL_IO) + integer :: ierr call mpi_init(ierr) - +#endif + ! abort program on any H5hut error call h5_abort_on_error() @@ -54,6 +59,8 @@ ! cleanup status = h5_closefile (file_id) - call mpi_finalize(ierr) +#if defined(PARALLEL_IO) + call mpi_finalize(ierr) +#endif end program write_step_attribs diff --git a/examples/H5Block/Makefile.am b/examples/H5Block/Makefile.am index 47f5be2..93af4bb 100644 --- a/examples/H5Block/Makefile.am +++ b/examples/H5Block/Makefile.am @@ -8,6 +8,7 @@ # AM_CPPFLAGS += -I${abs_top_srcdir}/src/include +AM_CPPFLAGS += -I${abs_top_srcdir}/examples/include FFLAGS += -cpp $(AM_CPPFLAGS) AM_LDFLAGS += -L${abs_top_builddir}/src/h5core/.libs @@ -34,10 +35,8 @@ noinst_PROGRAMS += \ endif if ENABLE_FORTRAN -if ENABLE_PARALLEL noinst_PROGRAMS += read_write_scalar_fieldf endif -endif attach_field_attributes_SOURCES = attach_field_attributes.c dump_field_attributes_SOURCES = dump_field_attributes.c diff --git a/examples/H5Block/read_write_scalar_fieldf.f90 b/examples/H5Block/read_write_scalar_fieldf.f90 index 60f239f..4adc8ce 100644 --- a/examples/H5Block/read_write_scalar_fieldf.f90 +++ b/examples/H5Block/read_write_scalar_fieldf.f90 @@ -11,13 +11,17 @@ include 'H5hut.f90' program read_write_scalar_field use H5hut implicit none + +#if defined(PARALLEL_IO) include 'mpif.h' + integer :: comm = 0 + integer :: mpi_err +#endif + integer :: nargs = 0 integer :: comm_rank = 0 integer :: comm_size = 1 - integer :: comm = 0 - integer :: mpi_err integer*8 :: h5_err integer :: i character(len=32) :: arg_str @@ -174,10 +178,15 @@ program read_write_scalar_field end do ! init MPI & H5hut +#if defined(PARALLEL_IO) comm = MPI_COMM_WORLD call mpi_init(mpi_err) call mpi_comm_rank(comm, comm_rank, mpi_err) call mpi_comm_size (comm, comm_size, mpi_err) +#else + comm_size = 1 + comm_rank = 0 +#endif call h5_abort_on_error () call h5_set_verbosity_level (511_8) @@ -215,7 +224,9 @@ program read_write_scalar_field case default print *, "Run this test on 1, 8, 16 or 32 cores!" +#if defined(PARALLEL_IO) call mpi_finalize +#endif call exit (1) end select @@ -233,7 +244,9 @@ program read_write_scalar_field endif print "('[proc ', I3, ']: Cleanup.')", comm_rank +#if defined(PARALLEL_IO) call mpi_finalize +#endif print "('[proc ', I3, ']: Done.')", comm_rank call exit (0) diff --git a/examples/H5Part/Makefile.am b/examples/H5Part/Makefile.am index f86f0f2..0564599 100644 --- a/examples/H5Part/Makefile.am +++ b/examples/H5Part/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright (c) 2006-2015, The Regents of the University of California, +# Copyright (c) 2006-2017, The Regents of the University of California, # through Lawrence Berkeley National Laboratory (subject to receipt of any # required approvals from the U.S. Dept. of Energy) and the Paul Scherrer # Institut (Switzerland). All rights reserved.! @@ -8,6 +8,7 @@ # AM_CPPFLAGS += -I${abs_top_srcdir}/src/include +AM_CPPFLAGS += -I${abs_top_srcdir}/examples/include FFLAGS += -cpp $(AM_CPPFLAGS) AM_LDFLAGS += -L${abs_top_builddir}/src/h5core/.libs @@ -42,7 +43,6 @@ noinst_PROGRAMS += \ endif if ENABLE_FORTRAN -if ENABLE_PARALLEL noinst_PROGRAMS += \ read_core_vfdf \ read_canonicalviewf \ @@ -54,7 +54,6 @@ noinst_PROGRAMS += \ write_setviewf \ write_stridedf endif -endif EXTRA_PROGRAMS = diff --git a/examples/H5Part/read_canonicalviewf.f90 b/examples/H5Part/read_canonicalviewf.f90 index f91bc14..757e8b8 100644 --- a/examples/H5Part/read_canonicalviewf.f90 +++ b/examples/H5Part/read_canonicalviewf.f90 @@ -11,7 +11,10 @@ include 'H5hut.f90' program read_canonicalview use H5hut implicit none + +#if defined(PARALLEL_IO) include 'mpif.h' +#endif ! name of input file character (len=*), parameter :: fname = "example_setview.h5" @@ -19,17 +22,19 @@ program read_canonicalview ! H5hut verbosity level integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT - integer :: comm, comm_size, comm_rank, mpi_ierror + integer :: comm_rank = 0 integer*8 :: file, h5_ierror integer*8 :: num_particles integer*8 :: i integer*4, allocatable :: data(:) ! initialize MPI & H5hut +#if defined(PARALLEL_IO) + integer :: comm, mpi_ierror comm = MPI_COMM_WORLD call mpi_init (mpi_ierror) - call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) +#endif call h5_abort_on_error () call h5_set_verbosity_level (h5_verbosity) @@ -53,6 +58,9 @@ program read_canonicalview ! cleanup deallocate (data) h5_ierror = h5_closefile (file) + +#if defined(PARALLEL_IO) call mpi_finalize (mpi_ierror) +#endif end program read_canonicalview diff --git a/examples/H5Part/read_core_vfdf.f90 b/examples/H5Part/read_core_vfdf.f90 index f3ea575..39855cd 100644 --- a/examples/H5Part/read_core_vfdf.f90 +++ b/examples/H5Part/read_core_vfdf.f90 @@ -11,7 +11,10 @@ include 'H5hut.f90' program read_core_vfd use H5hut implicit none + +#if defined(PARALLEL_IO) include 'mpif.h' +#endif ! name of input file character (len=*), parameter :: fname = "example_core_vfd.h5" @@ -19,8 +22,6 @@ program read_core_vfd ! H5hut verbosity level integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT - - integer :: comm, comm_size, comm_rank, mpi_ierror integer*8 :: file, h5_ierror integer*8 :: prop integer*8 :: num_particles @@ -28,10 +29,13 @@ program read_core_vfd integer*4, allocatable :: data(:) ! initialize MPI & H5hut + integer :: comm_rank = 0 +#if defined(PARALLEL_IO) + integer :: comm, mpi_ierror comm = MPI_COMM_WORLD call mpi_init (mpi_ierror) - call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) +#endif call h5_abort_on_error () call h5_set_verbosity_level (h5_verbosity) @@ -57,6 +61,9 @@ program read_core_vfd ! cleanup deallocate (data) h5_ierror = h5_closefile (file) + +#if defined(PARALLEL_IO) call mpi_finalize (mpi_ierror) +#endif end program read_core_vfd diff --git a/examples/H5Part/read_setnparticlesf.f90 b/examples/H5Part/read_setnparticlesf.f90 index d4582ef..647dd91 100644 --- a/examples/H5Part/read_setnparticlesf.f90 +++ b/examples/H5Part/read_setnparticlesf.f90 @@ -11,7 +11,10 @@ include 'H5hut.f90' program read_setnparticles use H5hut implicit none + +#if defined(PARALLEL_IO) include 'mpif.h' +#endif ! name of input file character (len=*), parameter :: fname = "example_setnparticles.h5" @@ -19,17 +22,21 @@ program read_setnparticles ! H5hut verbosity level integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT - integer :: comm, comm_size, comm_rank, mpi_ierror + integer :: comm_size = 1 + integer :: comm_rank = 0 integer*8 :: file, h5_ierror integer*8 :: num_particles, num_particles_total integer*8 :: i integer*4, allocatable :: data(:) ! initialize MPI & H5hut +#if defined(PARALLEL_IO) + integer :: comm, mpi_ierror comm = MPI_COMM_WORLD call mpi_init (mpi_ierror) call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) +#endif call h5_abort_on_error () call h5_set_verbosity_level (h5_verbosity) @@ -61,6 +68,9 @@ program read_setnparticles ! cleanup deallocate (data) h5_ierror = h5_closefile (file) + +#if defined(PARALLEL_IO) call mpi_finalize (mpi_ierror) +#endif end program read_setnparticles diff --git a/examples/H5Part/read_setviewf.f90 b/examples/H5Part/read_setviewf.f90 index c7ead42..1236c3a 100644 --- a/examples/H5Part/read_setviewf.f90 +++ b/examples/H5Part/read_setviewf.f90 @@ -11,25 +11,32 @@ include 'H5hut.f90' program read_setviewf use H5hut implicit none +#if defined(PARALLEL_IO) include 'mpif.h' - +#endif + ! name of input file character (len=*), parameter :: fname = "example_setview.h5" ! H5hut verbosity level integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT - integer :: comm, comm_size, comm_rank, mpi_ierror + integer :: comm_size = 1 + integer :: comm_rank = 0 integer*8 :: file, h5_ierror integer*8 :: num_particles, num_particles_total integer*8 :: i, start, end, remainder integer*4, allocatable :: data(:) ! initialize MPI & H5hut +#if defined(PARALLEL_IO) + integer :: comm, mpi_ierror comm = MPI_COMM_WORLD call mpi_init (mpi_ierror) call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) +#endif + call h5_abort_on_error () call h5_set_verbosity_level (h5_verbosity) @@ -78,6 +85,9 @@ program read_setviewf ! cleanup deallocate (data) h5_ierror = h5_closefile (file) - call mpi_finalize (mpi_ierror) +#if defined(PARALLEL_IO) + call mpi_finalize (mpi_ierror) +#endif + end program read_setviewf diff --git a/examples/H5Part/read_stridedf.f90 b/examples/H5Part/read_stridedf.f90 index 9b3f8df..87345bf 100644 --- a/examples/H5Part/read_stridedf.f90 +++ b/examples/H5Part/read_stridedf.f90 @@ -11,24 +11,32 @@ include 'H5hut.f90' program read_stridedf use H5hut implicit none +#if defined(PARALLEL_IO) include 'mpif.h' +#endif + ! name of input file character (len=*), parameter :: fname = "example_strided.h5" ! H5hut verbosity level integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT - integer :: comm, comm_size, comm_rank, mpi_ierror + integer :: comm_size = 1 + integer :: comm_rank = 0 integer*8 :: file, h5_ierror integer*8 :: num_particles, num_particles_total real*8, allocatable :: data(:) integer*8 :: i, start ! initialize MPI & H5hut +#if defined(PARALLEL_IO) + integer :: comm, comm_size, comm_rank, mpi_ierror comm = MPI_COMM_WORLD call mpi_init (mpi_error) call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) +#endif + call h5_abort_on_error () call h5_set_verbosity_level (h5_verbosity) @@ -68,6 +76,9 @@ program read_stridedf ! cleanup deallocate (data) h5_ierror = h5_closefile (file) - call mpi_finalize (mpi_ierror) +#if defined(PARALLEL_IO) + call mpi_finalize (mpi_ierror) +#endif + end program read_stridedf diff --git a/examples/H5Part/write_core_vfdf.f90 b/examples/H5Part/write_core_vfdf.f90 index 9c678aa..1e59802 100644 --- a/examples/H5Part/write_core_vfdf.f90 +++ b/examples/H5Part/write_core_vfdf.f90 @@ -11,8 +11,11 @@ include 'H5hut.f90' program write_core_vfd use H5hut implicit none - include 'mpif.h' +#if defined(PARALLEL_IO) + include 'mpif.h' +#endif + ! name of output file character (len=*), parameter :: fname = "example_core_vfd.h5" @@ -22,17 +25,20 @@ program write_core_vfd ! number of particles we are going to write per core integer*4, parameter :: num_particles = 32 - integer :: comm, comm_size, comm_rank, mpi_ierror + integer :: comm_rank = 0 integer*8 :: file, h5_ierror integer*8 :: prop integer*4 :: i integer*4, allocatable :: data(:) ! initialize MPI & H5hut +#if defined(PARALLEL_IO) + integer :: comm, mpi_ierror comm = MPI_COMM_WORLD call mpi_init (mpi_ierror) - call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) +#endif + call h5_abort_on_error () call h5_set_verbosity_level (h5_verbosity) @@ -57,6 +63,9 @@ program write_core_vfd ! cleanup deallocate (data) h5_ierror = h5_closefile (file) - call mpi_finalize (mpi_ierror) +#if defined(PARALLEL_IO) + call mpi_finalize (mpi_ierror) +#endif + end program write_core_vfd diff --git a/examples/H5Part/write_setnparticlesf.f90 b/examples/H5Part/write_setnparticlesf.f90 index d1fa0a6..f2cbefc 100644 --- a/examples/H5Part/write_setnparticlesf.f90 +++ b/examples/H5Part/write_setnparticlesf.f90 @@ -11,8 +11,10 @@ include 'H5hut.f90' program write_setnparticles use H5hut implicit none - include 'mpif.h' +#if defined(PARALLEL_IO) + include 'mpif.h' +#endif ! name of output file character (len=*), parameter :: fname = "example_setnparticles.h5" @@ -23,16 +25,19 @@ program write_setnparticles ! number of particles we are going to write per core integer*8, parameter :: num_particles = 32 - integer :: comm, comm_size, comm_rank, mpi_ierror + integer :: comm_rank = 0 integer*8 :: file, h5_ierror integer*4 :: i integer*4, allocatable :: data(:) ! initialize MPI & H5hut +#if defined(PARALLEL_IO) + integer :: comm, mpi_ierror comm = MPI_COMM_WORLD call mpi_init (mpi_ierror) - call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) +#endif + call h5_abort_on_error () call h5_set_verbosity_level (h5_verbosity) @@ -55,6 +60,9 @@ program write_setnparticles ! cleanup deallocate (data) h5_ierror = h5_closefile (file) - call mpi_finalize (mpi_ierror) +#if defined(PARALLEL_IO) + call mpi_finalize (mpi_ierror) +#endif + end program write_setnparticles diff --git a/examples/H5Part/write_setviewf.f90 b/examples/H5Part/write_setviewf.f90 index 71bb8dd..cdab1bf 100644 --- a/examples/H5Part/write_setviewf.f90 +++ b/examples/H5Part/write_setviewf.f90 @@ -11,8 +11,11 @@ include 'H5hut.f90' program write_setview use H5hut implicit none - include 'mpif.h' +#if defined(PARALLEL_IO) + include 'mpif.h' +#endif + ! name of output file character (len=*), parameter :: fname = "example_setview.h5" @@ -23,16 +26,19 @@ program write_setview integer*8, parameter :: num_blocks = 4; integer*8, parameter :: num_particles_per_block = 32 - integer :: comm, comm_size, comm_rank, mpi_ierror + integer :: comm_rank = 0 integer*8 :: file, h5_ierror integer*8 :: i, j, offset integer*4, allocatable :: data(:) ! initialize MPI & H5hut +#if defined(PARALLEL_IO) + integer :: comm, mpi_ierror comm = MPI_COMM_WORLD call mpi_init (mpi_ierror) - call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) +#endif + call h5_abort_on_error () call h5_set_verbosity_level (h5_verbosity) @@ -61,6 +67,9 @@ program write_setview ! cleanup deallocate (data) h5_ierror = h5_closefile (file) - call mpi_finalize (mpi_ierror) +#if defined(PARALLEL_IO) + call mpi_finalize (mpi_ierror) +#endif + end program write_setview diff --git a/examples/H5Part/write_stridedf.f90 b/examples/H5Part/write_stridedf.f90 index 51e354a..55e6fe3 100644 --- a/examples/H5Part/write_stridedf.f90 +++ b/examples/H5Part/write_stridedf.f90 @@ -11,22 +11,29 @@ include 'H5hut.f90' program write_stridedf use H5hut implicit none - include 'mpif.h' +#if defined(PARALLEL_IO) + include 'mpif.h' +#endif + ! the file name we want to read character (len=*), parameter :: FNAME = "example_strided.h5" integer*8, parameter :: NPOINTS = 99 - integer :: comm, rank, ierr + integer :: rank = 0 integer*8 :: file, status integer*4 :: i real*8, allocatable :: particles(:) integer*8, allocatable :: id(:) ! init MPI & H5hut +#if defined(PARALLEL_IO) + integer :: comm, ierr comm = MPI_COMM_WORLD call mpi_init(ierr) call mpi_comm_rank(comm, rank, ierr) +#endif + call h5_abort_on_error () ! create fake data @@ -66,6 +73,8 @@ program write_stridedf deallocate(particles, id) +#if defined(PARALLEL_IO) call mpi_finalize(ierr) +#endif end program write_stridedf diff --git a/examples/include/examples.f90 b/examples/include/examples.f90 new file mode 100644 index 0000000..4f088f8 --- /dev/null +++ b/examples/include/examples.f90 @@ -0,0 +1,3 @@ +#ifndef PARALLEL_IO + +#endif