Commit 6d3014ba authored by gsell's avatar gsell

Fortran examples:

- adapted for serial compilation, closing #8
parent 20424235
......@@ -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 $<
......@@ -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
!
! 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
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......
......@@ -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)
......
#
# 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 =
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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 ()