From 937d3f9c0ec8d69b8b15e8d449e99f6e257ca5ef Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 11 Sep 2015 14:04:12 +0200 Subject: [PATCH] examples/H5Part/* - cleanup and fixes --- examples/H5Part/.gitignore | 2 + examples/H5Part/read_canonicalviewf.f90 | 2 +- examples/H5Part/read_core_vfd.c | 63 +++++++++++++++++++++++++ examples/H5Part/read_core_vfdf.f90 | 62 ++++++++++++++++++++++++ examples/H5Part/read_setnparticles.c | 5 +- examples/H5Part/read_setnparticlesf.f90 | 4 +- examples/H5Part/read_strided.c | 7 +-- examples/H5Part/write_setview.c | 2 +- examples/H5Part/write_setviewf.f90 | 2 +- 9 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 examples/H5Part/read_core_vfd.c create mode 100644 examples/H5Part/read_core_vfdf.f90 diff --git a/examples/H5Part/.gitignore b/examples/H5Part/.gitignore index c6691a6..3361c77 100644 --- a/examples/H5Part/.gitignore +++ b/examples/H5Part/.gitignore @@ -1,3 +1,5 @@ +read_core_vfd +read_core_vfdf read_canonicalviewf read_setnparticlesf read_setviewf diff --git a/examples/H5Part/read_canonicalviewf.f90 b/examples/H5Part/read_canonicalviewf.f90 index 317d380..f91bc14 100644 --- a/examples/H5Part/read_canonicalviewf.f90 +++ b/examples/H5Part/read_canonicalviewf.f90 @@ -27,7 +27,7 @@ program read_canonicalview ! initialize MPI & H5hut comm = MPI_COMM_WORLD - call mpi_init (mpi_error) + call mpi_init (mpi_ierror) call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) call h5_abort_on_error () diff --git a/examples/H5Part/read_core_vfd.c b/examples/H5Part/read_core_vfd.c new file mode 100644 index 0000000..5ded9e5 --- /dev/null +++ b/examples/H5Part/read_core_vfd.c @@ -0,0 +1,63 @@ +/* + Copyright (c) 2006-2015, 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. + + License: see file COPYING in top level of source distribution. +*/ + +/* + Note: + Running this example on more than one core is possible but the result + might not be what you expect. Please read the HDF5 documentation about + the VFD core driver. +*/ +#include "H5hut.h" + +// name of input file +const char* fname = "example_core_vfd.h5"; + +// H5hut verbosity level +const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT; + +int +main ( + int argc, + char* argv[] + ){ + + // initialize MPI & H5hut + MPI_Init (&argc, &argv); + MPI_Comm comm = MPI_COMM_WORLD; + int comm_size = 1; + MPI_Comm_size (comm, &comm_size); + int comm_rank = 0; + MPI_Comm_rank (comm, &comm_rank); + H5AbortOnError (); + H5SetVerbosityLevel (h5_verbosity); + + // open file and create first step + h5_prop_t prop = H5CreateFileProp (); + H5SetPropFileCoreVFD (prop); + h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, prop); + H5SetStep (file, 0); + + // with core cfd we read the hole file on all cores! + h5_int64_t num_particles = H5PartGetNumParticles (file); + printf ("[proc %d]: particles in view: %lld\n", comm_rank, num_particles); + + // read and print data + h5_int32_t* data = calloc (num_particles, sizeof (*data)); + H5PartReadDataInt32 (file, "data", data); + for (int i = 0; i < num_particles; i++) { + printf ("[proc %d]: local index = %d, value = %d\n", + comm_rank, i, data[i]); + } + + // cleanup + free (data); + H5CloseFile (file); + return MPI_Finalize (); +} + diff --git a/examples/H5Part/read_core_vfdf.f90 b/examples/H5Part/read_core_vfdf.f90 new file mode 100644 index 0000000..f3ea575 --- /dev/null +++ b/examples/H5Part/read_core_vfdf.f90 @@ -0,0 +1,62 @@ +! +! Copyright (c) 2006-2015, 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.! +! +! License: see file COPYING in top level of source distribution. +! +include 'H5hut.f90' + +program read_core_vfd + use H5hut + implicit none + include 'mpif.h' + + ! name of input file + character (len=*), parameter :: fname = "example_core_vfd.h5" + + ! 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 + integer*4 :: i + integer*4, allocatable :: data(:) + + ! initialize MPI & H5hut + 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) + call h5_abort_on_error () + call h5_set_verbosity_level (h5_verbosity) + + ! open file and create first step + prop = h5_createprop_file () + h5_ierror = h5_setprop_file_corevfd (prop); + file = h5_openfile (fname, H5_O_RDONLY, prop) + h5_ierror = h5_setstep(file, 1_8) + + ! with core cfd we read the hole file on all cores! + num_particles = h5pt_getnpoints (file) + write (*, "('[proc ', i4, ']: particles in view: ', i4)") & + comm_rank, num_particles + + ! read and print data + allocate (data (num_particles)) + h5_ierror = h5pt_readdata_i4 (file, "data", data) + do i = 1, int (num_particles) + write (*, "('[proc ', i4, ']: local index = ', i4, ', value = ', i4)") & + comm_rank, i, data(i) + end do + + ! cleanup + deallocate (data) + h5_ierror = h5_closefile (file) + call mpi_finalize (mpi_ierror) + +end program read_core_vfd diff --git a/examples/H5Part/read_setnparticles.c b/examples/H5Part/read_setnparticles.c index 06d7b4a..21ee677 100644 --- a/examples/H5Part/read_setnparticles.c +++ b/examples/H5Part/read_setnparticles.c @@ -40,8 +40,9 @@ main ( if (comm_rank+1 == comm_size) num_particles += num_particles_total % comm_size; - h5_info ("Total number of particles: %lld", (long long unsigned)num_particles_total); - h5_info ("Number of particles on this core: %lld", (long long unsigned)num_particles); + printf ("[proc %d]: particles in view: %lld\n", comm_rank, num_particles); + printf ("[proc %d]: total number of particles: %lld\n", + comm_rank, (long long unsigned)num_particles_total); H5PartSetNumParticles (file, num_particles); diff --git a/examples/H5Part/read_setnparticlesf.f90 b/examples/H5Part/read_setnparticlesf.f90 index b548098..045550c 100644 --- a/examples/H5Part/read_setnparticlesf.f90 +++ b/examples/H5Part/read_setnparticlesf.f90 @@ -27,7 +27,7 @@ program read_setnparticles ! initialize MPI & H5hut comm = MPI_COMM_WORLD - call mpi_init (mpi_error) + call mpi_init (mpi_ierror) call mpi_comm_size (comm, comm_size, mpi_ierror) call mpi_comm_rank (comm, comm_rank, mpi_ierror) call h5_abort_on_error () @@ -35,7 +35,7 @@ program read_setnparticles ! open file and go to first step file = h5_openfile (fname, H5_O_RDONLY, H5_PROP_DEFAULT) - h5_ierror = h5_setstep(file, 1_8) + h5_ierror = h5_setstep (file, 1_8) ! compute and set number of particles this process has to read num_particles_total = h5pt_getnpoints (file) diff --git a/examples/H5Part/read_strided.c b/examples/H5Part/read_strided.c index b75520d..3d1ba1a 100644 --- a/examples/H5Part/read_strided.c +++ b/examples/H5Part/read_strided.c @@ -13,7 +13,8 @@ const char* fname = "example_strided.h5"; // H5hut verbosity level -const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT; +//const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT; +const h5_int64_t h5_verbosity = H5_DEBUG_ALL; int main ( @@ -38,7 +39,7 @@ main ( h5_int64_t num_particles = H5PartGetNumParticles (file); // set number of particles and memory stride - H5PartSetNumParticlesStrided (file, num_particles, 6); + H5PartSetNumParticlesStrided (file, 98, 6); // read data h5_float64_t* data = calloc (6*num_particles, sizeof (*data)); @@ -50,7 +51,7 @@ main ( H5PartReadDataFloat64 (file, "pz", data+5); // print dataset "x" - for (int i = 0; i < num_particles; i+=6) { + for (int i = 0; i < num_particles*6; i+=1) { printf ("[proc %d]: local index = %d, value = %6.3f\n", comm_rank, i, data[i]); } diff --git a/examples/H5Part/write_setview.c b/examples/H5Part/write_setview.c index 911eb93..904a91f 100644 --- a/examples/H5Part/write_setview.c +++ b/examples/H5Part/write_setview.c @@ -13,7 +13,7 @@ const char* fname = "example_setview.h5"; // H5hut verbosity level -const h5_int64_t h5_verbosity = H5_DEBUG_ALL; +const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT; // we are going to write multiple consecutive blocks const h5_int64_t num_blocks = 4; diff --git a/examples/H5Part/write_setviewf.f90 b/examples/H5Part/write_setviewf.f90 index 5564521..71bb8dd 100644 --- a/examples/H5Part/write_setviewf.f90 +++ b/examples/H5Part/write_setviewf.f90 @@ -17,7 +17,7 @@ program write_setview character (len=*), parameter :: fname = "example_setview.h5" ! H5hut verbosity level - integer*8, parameter :: h5_verbosity = H5_DEBUG_ALL + integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT ! we are going to write multiple consecutive blocks integer*8, parameter :: num_blocks = 4;