Fortran H5Part examples:

- read_canonicalviewf.f90 read_setnparticlesf.f90, read_setviewf.f90, read_stridedf.f90 implemented
This commit is contained in:
2015-09-03 17:26:54 +02:00
parent d5fce5b2a0
commit 5a588415d0
4 changed files with 110 additions and 82 deletions
+6 -18
View File
@@ -14,13 +14,10 @@ program read_canonicalview
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_setnparticles.h5"
integer*8, parameter :: NPOINTS = 99
character (len=*), parameter :: FNAME = "example_setview.h5"
integer :: comm, rank, ierr
integer*8 :: file, status
integer*4 :: i
integer*4, allocatable :: data(:)
integer*8 :: file, status, num_particles
! init MPI & H5hut
comm = MPI_COMM_WORLD
@@ -28,25 +25,16 @@ program read_canonicalview
call mpi_comm_rank(comm, rank, ierr)
call h5_abort_on_error ()
! create fake data
allocate (data (NPOINTS))
do i = 1, NPOINTS
data (i) = i + int(NPOINTS)*rank
enddo
! open the a file for parallel writing and ceate step #0
file = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
status = h5_setstep(file, 0_8)
status = h5_setstep(file, 1_8)
! set the size of the 1D array
status = h5pt_setnpoints (file, npoints)
! write the particles
status = h5pt_readdata_i4 (file, "data", data)
status = h5pt_setcanonicalview (file)
num_particles = h5pt_getnpoints (file)
write (*, "('[proc ', i4, '] particles in view: ', i8)") rank, num_particles
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
end program read_canonicalview
+23 -19
View File
@@ -8,45 +8,49 @@
!
include 'H5hut.f90'
program write_setnparticles
program read_setnparticles
use H5hut
implicit none
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_setnparticles.h5"
integer*8, parameter :: NPOINTS = 99
integer :: comm, rank, ierr
integer :: comm, comm_rank, comm_size, ierr
integer*8 :: file, status
integer*4 :: i
integer*8 :: nparticels, nparticels_total
integer*4, allocatable :: data(:)
! init MPI & H5hut
! initialize MPI & H5hut
comm = MPI_COMM_WORLD
call mpi_init(ierr)
call mpi_comm_rank(comm, rank, ierr)
call mpi_comm_rank (comm, comm_rank, ierr)
call mpi_comm_size (comm, comm_size, ierr)
call h5_abort_on_error ()
! create fake data
allocate (data (NPOINTS))
do i = 1, NPOINTS
data (i) = i + int(NPOINTS)*rank
enddo
! open file and go to first step
file = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
status = h5_setstep(file, 1_8)
! open the a file for parallel writing and ceate step #0
file = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)
status = h5_setstep(file, 0_8)
! compute number of particles this process has to read
nparticels_total = h5pt_getnpoints (file)
nparticels = nparticels_total / comm_size
! set the size of the 1D array
status = h5pt_setnpoints (file, npoints)
if (comm_rank+1 == comm_size) then
nparticels = nparticels + mod (nparticels_total, comm_size)
end if
! write the particles
status = h5pt_writedata_i4 (file, "data", data)
write (*, "('Total number of particles: ', i8)") nparticels_total
write (*, "('Number of particles on this core: ', i8)") nparticels
! read data
status = h5pt_setnpoints (file, nparticels)
allocate (data (nparticels))
status = h5pt_readdata_i4 (file, "data", data)
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
end program write_setnparticles
end program read_setnparticles
+51 -21
View File
@@ -8,45 +8,75 @@
!
include 'H5hut.f90'
program write_setnparticles
program read_setviewf
use H5hut
implicit none
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_setnparticles.h5"
integer*8, parameter :: NPOINTS = 99
character (len=*), parameter :: FNAME = "example_setview.h5"
integer*8, parameter :: DEFAULT_VERBOSITY = H5_VERBOSE_DEFAULT
integer :: comm, rank, ierr
integer*8 :: verbosity = DEFAULT_VERBOSITY
integer :: comm, comm_rank, comm_size, ierr
integer*8 :: file, status
integer*4 :: i
integer*8 :: i
integer*4, allocatable :: data(:)
integer*8 :: total_particles, nparticles, remainder
integer*8 :: start, end
! init MPI & H5hut
! initialize MPI & H5hut
comm = MPI_COMM_WORLD
call mpi_init(ierr)
call mpi_comm_rank(comm, rank, ierr)
call mpi_init (ierr)
call mpi_comm_rank (comm, comm_rank, ierr)
call mpi_comm_size (comm, comm_size, ierr)
call h5_abort_on_error ()
call h5_set_verbosity_level (verbosity)
! create fake data
allocate (data (NPOINTS))
do i = 1, NPOINTS
data (i) = i + int(NPOINTS)*rank
enddo
! open file and go to first step
file = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
status = h5_setstep (file, 1_8)
! open the a file for parallel writing and ceate step #0
file = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)
status = h5_setstep(file, 0_8)
! compute a "canonical" view: all cores get almost the same number of
! particles
total_particles = h5pt_getnpoints (file);
nparticles = total_particles / comm_size;
remainder = mod (total_particles, comm_size);
start = comm_rank * nparticles;
! set the size of the 1D array
status = h5pt_setnpoints (file, npoints)
! adjust number of local particles
if (comm_rank < remainder) then
nparticles = nparticles + 1
end if
! write the particles
status = h5pt_writedata_i4 (file, "data", data)
! adjust start
if (comm_rank < remainder) then
start = start + comm_rank
else
start = start + remainder
end if
! Note: setting end = start - 1 forces the
! selection of zero particles!
end = start + nparticles - 1;
! in Fortran we start at 1 not 0
start = start + 1
end = end + 1
write (*, "('[proc ', i4, ']: set view to [', i4, '..', i4, ']')") comm_rank, start, end
status = h5pt_setview (file, start, end);
allocate (data (nparticles))
status = h5pt_readdata_i4 (file, "data", data);
do i = 1, nparticles
write (*, "('[proc ', i4, ']: global index = ', i4, '; local index = ', i4, ', value = ', i4)") &
comm_rank, start+i-1, i, data(i)
end do
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
end program write_setnparticles
end program read_setviewf
+30 -24
View File
@@ -8,45 +8,51 @@
!
include 'H5hut.f90'
program write_setnparticles
program read_stridedf
use H5hut
implicit none
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_setnparticles.h5"
integer*8, parameter :: NPOINTS = 99
character (len=*), parameter :: FNAME = "example_strided.h5"
integer*8, parameter :: DEFAULT_VERBOSITY = H5_VERBOSE_DEFAULT
integer :: comm, rank, ierr
integer*8 :: verbosity = DEFAULT_VERBOSITY
integer :: comm, comm_rank, comm_size, ierr
integer*8 :: file, status
integer*4 :: i
integer*4, allocatable :: data(:)
real*8, allocatable :: data(:)
integer*8 :: nparticles
! init MPI & H5hut
! initialize MPI & H5hut
comm = MPI_COMM_WORLD
call mpi_init(ierr)
call mpi_comm_rank(comm, rank, ierr)
call mpi_init (ierr)
call mpi_comm_rank (comm, comm_rank, ierr)
call mpi_comm_size (comm, comm_size, ierr)
call h5_abort_on_error ()
call h5_set_verbosity_level (verbosity)
! create fake data
allocate (data (NPOINTS))
do i = 1, NPOINTS
data (i) = i + int(NPOINTS)*rank
enddo
! open file and go to first step
file = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
status = h5_setstep (file, 1_8)
! open the a file for parallel writing and ceate step #0
file = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)
status = h5_setstep(file, 0_8)
! set the size of the 1D array
status = h5pt_setnpoints (file, npoints)
! write the particles
status = h5pt_writedata_i4 (file, "data", data)
! Get number of particles in datasets and allocate memory
nparticles = h5pt_getnpoints (file)
allocate (data (6*nparticles))
! set number of particles and memory stride
status = h5pt_setnpoints_strided (file, nparticles, 6_8)
! read data
status = h5pt_readdata_r8 (file, "x", data(1:))
status = h5pt_readdata_r8 (file, "y", data(2:))
status = h5pt_readdata_r8 (file, "z", data(3:))
status = h5pt_readdata_r8 (file, "px", data(4:))
status = h5pt_readdata_r8 (file, "py", data(5:))
status = h5pt_readdata_r8 (file, "pz", data(6:))
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
end program write_setnparticles
end program read_stridedf