diff --git a/examples/H5/openclosef.f90 b/examples/H5/openclosef.f90 index 965dbf1..f8f1ea8 100644 --- a/examples/H5/openclosef.f90 +++ b/examples/H5/openclosef.f90 @@ -25,7 +25,7 @@ program openclose call mpi_comm_rank(comm, rank, ierr) props = h5_createprop_file () - status = h5_setprop_filempio (props, comm) + status = h5_setprop_file_mpio_collective (props, comm) file_id = h5_openfile ("testfile.h5", H5_O_WRONLY, props) status = h5_closeprop (props) status = h5_closefile (file_id); diff --git a/examples/H5/read_file_attribs.c b/examples/H5/read_file_attribs.c index 505d853..fa60d7e 100644 --- a/examples/H5/read_file_attribs.c +++ b/examples/H5/read_file_attribs.c @@ -10,6 +10,7 @@ #include "H5hut.h" #define FNAME "example_file_attribs.h5" +#define VERBOSITY H5_VERBOSE_ERROR #define ATTR_STRING "FileAttrString" #define ATTR_INT32 "FileAttrInt32" @@ -22,8 +23,11 @@ main ( int argc, char** argv ) { - MPI_Init (&argc, &argv); H5AbortOnError (); + H5SetVerbosityLevel (VERBOSITY); + + MPI_Init (&argc, &argv); + // if file properties is set to default, MPI_COMM_WORLD will be used h5_file_t f = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT); h5_size_t len; @@ -74,7 +78,7 @@ main ( printf ("\n"); free (attr_float64); - + // cleanup H5CloseFile (f); MPI_Finalize (); return 0; diff --git a/examples/H5/read_file_attribsf.f90 b/examples/H5/read_file_attribsf.f90 index 356204d..9dd66d7 100644 --- a/examples/H5/read_file_attribsf.f90 +++ b/examples/H5/read_file_attribsf.f90 @@ -16,7 +16,11 @@ ! the file name we want to read character (len=*), parameter :: FNAME = "example_file_attribs.h5" - ! verbosity level: set it to a power of 2 minus one or zero + ! verbosity level: set it to + ! - 1 to see error messages, if something goes wrong + ! - 0 to get no output + ! - a power of 2 minus one to get lot of output + ! zeror zero integer*8, parameter :: verbosity_level = 1 ! we know the attribute names! diff --git a/examples/H5Part/Makefile.am b/examples/H5Part/Makefile.am index 9db0b0b..1749bad 100644 --- a/examples/H5Part/Makefile.am +++ b/examples/H5Part/Makefile.am @@ -19,32 +19,37 @@ noinst_PROGRAMS = if ENABLE_C noinst_PROGRAMS += \ - Bench \ - H5test \ - core_vfd \ - particles \ read_canonicalview \ - write_setnumparticles \ - write_setview + read_setnparticles \ + read_setview \ + read_strided \ + use_core_vfd \ + write_setnparticles \ + write_setview \ + write_strided endif if ENABLE_FORTRAN -noinst_PROGRAMS += H5testF +noinst_PROGRAMS += \ + read_canonicalviewf \ + read_setnparticlesf \ + read_setviewf \ + read_stridedf \ + use_core_vfd \ + write_setnparticlesf \ + write_setviewf \ + write_stridedf endif -EXTRA_PROGRAMS = Bench H5test H5testF +EXTRA_PROGRAMS = -Bench_SOURCES = Bench.c -H5test_SOURCES = H5test.c -core_vfd_SOURCES = core_vfd.c -particles_SOURCES = particles.c -read_canonicalview_SOURCES = read_canonicalview.c -write_setnumparticles_SOURCES = write_setnumparticles.c -write_setview_SOURCES = write_setview.c -H5testF_SOURCES = H5testF.f90 +write_setviewf_SOURCES = write_setviewf.f90 +write_stridedf_SOURCES = write_stridedf.f90 %.o : %.f90 $(FC) $(FFLAGS) -c $< clean-local: $(RM) *~ + + diff --git a/examples/H5Part/read_canonicalview.c b/examples/H5Part/read_canonicalview.c index bb142a3..1d8ee2e 100644 --- a/examples/H5Part/read_canonicalview.c +++ b/examples/H5Part/read_canonicalview.c @@ -1,20 +1,28 @@ +/* + Copyright (c) 2006-2013, 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 #include "H5hut.h" +#define FNAME "example_particles.h5" + int main ( int argc, char* argv[] ){ - h5_file_t file; - int nprocs, myproc; - MPI_Comm comm = MPI_COMM_WORLD; + H5AbortOnError (); + H5SetVerbosityLevel (VERBOSITY); + int myproc; MPI_Init (&argc, &argv); - MPI_Comm_size (comm, &nprocs); - MPI_Comm_rank (comm, &myproc); - H5SetVerbosityLevel (4); - file = H5OpenFile ("parttest.h5", H5_O_RDONLY, comm); + MPI_Comm_rank (MPI_COMM_WORLD, &myproc); + + h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT); H5SetStep (file, 0); @@ -22,6 +30,6 @@ main ( h5_int64_t num_particles = H5PartGetNumParticles (file); printf ("[proc %d]: particles in view: %lld\n", myproc, num_particles); - H5CloseFile(file); - return MPI_Finalize(); + H5CloseFile (file); + return MPI_Finalize (); } diff --git a/examples/H5Part/read_setnparticles.c b/examples/H5Part/read_setnparticles.c new file mode 100644 index 0000000..22ae0ac --- /dev/null +++ b/examples/H5Part/read_setnparticles.c @@ -0,0 +1,50 @@ +/* + Copyright (c) 2006-2013, 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.h" + +#define FNAME "example_setnparticles.h5" + +int +main ( + int argc, char* argv[] + ){ + // initialize MPI & H5hut + MPI_Init (&argc, &argv); + MPI_Comm comm = MPI_COMM_WORLD; + int comm_rank = 0; + MPI_Comm_rank (comm, &comm_rank); + int comm_size = 0; + MPI_Comm_size (comm, &comm_size); + H5AbortOnError (); + H5SetVerbosityLevel (H5_VERBOSE_INFO); + + // open file and open step #0 + h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT); + H5SetStep (file, 0); + + // compute number of particles this process has to read + h5_ssize_t nparticels_total = H5PartGetNumParticles (file); + + h5_ssize_t nparticels = nparticels_total / comm_size; + if (comm_rank+1 == comm_size) + nparticels += nparticels_total % comm_size; + + h5_info ("Total number of particles: %lld", (long long unsigned)nparticels_total); + h5_info ("Number of particles on this core: %lld", (long long unsigned)nparticels); + + // read data + H5PartSetNumParticles (file, nparticels); + h5_int32_t* data = calloc (nparticels, sizeof (*data)); + H5PartReadDataInt32 (file, "data", data); + + // cleanup + H5CloseFile (file); + return MPI_Finalize (); +} diff --git a/examples/H5Part/read_setview.c b/examples/H5Part/read_setview.c new file mode 100644 index 0000000..18e2859 --- /dev/null +++ b/examples/H5Part/read_setview.c @@ -0,0 +1,34 @@ +/* + Copyright (c) 2006-2013, 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.h" +#include "examples.h" + +#define FNAME "example_particles.h5" + +int +main ( + int argc, char* argv[] + ){ + H5AbortOnError (); + H5SetVerbosityLevel (VERBOSITY); + + int myproc; + MPI_Init (&argc, &argv); + MPI_Comm_rank (MPI_COMM_WORLD, &myproc); + + h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT); + + H5SetStep (file, 0); + + // TODO + + H5CloseFile (file); + return MPI_Finalize (); +} diff --git a/examples/H5Part/read_strided.c b/examples/H5Part/read_strided.c new file mode 100644 index 0000000..18e2859 --- /dev/null +++ b/examples/H5Part/read_strided.c @@ -0,0 +1,34 @@ +/* + Copyright (c) 2006-2013, 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.h" +#include "examples.h" + +#define FNAME "example_particles.h5" + +int +main ( + int argc, char* argv[] + ){ + H5AbortOnError (); + H5SetVerbosityLevel (VERBOSITY); + + int myproc; + MPI_Init (&argc, &argv); + MPI_Comm_rank (MPI_COMM_WORLD, &myproc); + + h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT); + + H5SetStep (file, 0); + + // TODO + + H5CloseFile (file); + return MPI_Finalize (); +} diff --git a/examples/H5Part/use_core_cfd.c b/examples/H5Part/use_core_cfd.c index b6cf914..bf81ede 100644 --- a/examples/H5Part/use_core_cfd.c +++ b/examples/H5Part/use_core_cfd.c @@ -1,14 +1,28 @@ +/* + Copyright (c) 2006-2013, 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.h" +#include "examples.h" + #include #include -#include -#include +#define FNAME "example_core_vfd" #define DATASIZE 32 -int main( - int argc, char** argv - ) { - int i, rank, nprocs; +int +main ( + int argc, char* argv[] + ){ + H5AbortOnError (); + H5SetVerbosityLevel (VERBOSITY); + h5_int32_t data[DATASIZE]; h5_int64_t stat; h5_file_t file; @@ -18,31 +32,25 @@ int main( MPI_Comm_rank (MPI_COMM_WORLD, &rank); MPI_Comm_size (MPI_COMM_WORLD, &nprocs); - H5SetVerbosityLevel (1); - - char filename[8]; - sprintf (filename, "%d.h5", rank); + char filename[32]; + sprintf (filename, "%s.%d.h5", FNAME, rank); file = H5OpenFile (filename, H5_O_WRONLY|H5_VFD_CORE, MPI_COMM_SELF); - assert (file != H5_FAILURE); - stat = H5SetStep (file, 0); - assert (stat == H5_SUCCESS); + H5SetStep (file, 0); - stat = H5PartSetNumParticles(file, DATASIZE); - assert (stat == H5_SUCCESS); + H5PartSetNumParticles(file, DATASIZE); // create fake data - for (i=0; i #include "H5hut.h" -#define NUM_PARTICLES 3 +#define FNAME "example_setnparticles.h5" +#define NUM_PARTICLES 3 int main ( int argc, char* argv[] ){ - h5_file_t file; - int nprocs = 0; - int myproc = 0; - int step = 0; - + // initialize MPI & H5hut + MPI_Init (&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; + int rank = 0; + MPI_Comm_rank (comm, &rank); + H5AbortOnError (); + H5SetVerbosityLevel (-1); - MPI_Init (&argc,&argv); - MPI_Comm_size (comm,&nprocs); - MPI_Comm_rank (comm,&myproc); - - h5_int64_t id[NUM_PARTICLES]; + // create fake data + h5_int32_t data[NUM_PARTICLES]; h5_int64_t num_particles = NUM_PARTICLES; - for (int i = 0; i < num_particles; i++) { - id[i] = i + num_particles * myproc; + data[i] = i + num_particles * rank; } + // open file and create step #0 + h5_file_t file = H5OpenFile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT); + H5SetStep (file, 0); - file = H5OpenFile ("parttest.h5", H5_O_WRONLY, comm); - H5SetStep (file, step); - H5PartSetNumParticles (file,num_particles); - H5PartWriteDataInt64 (file, "id", id); + // define number of items this process will write + H5PartSetNumParticles (file, num_particles); + + // write data + H5PartWriteDataInt32 (file, "data", data); + + // done H5CloseFile(file); - - MPI_Finalize (); + return MPI_Finalize (); } diff --git a/examples/H5Part/write_setnparticlesf.f90 b/examples/H5Part/write_setnparticlesf.f90 index 7720dee..e4f4f96 100644 --- a/examples/H5Part/write_setnparticlesf.f90 +++ b/examples/H5Part/write_setnparticlesf.f90 @@ -1,56 +1,51 @@ -program H5PartTest - implicit none +! +! Copyright (c) 2006-2013, 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 write_setnparticles + use H5hut + implicit none include 'mpif.h' - include 'H5PartF.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*8 :: file_id, status, npoints, i - real*8, allocatable :: particles(:) - integer*8, allocatable :: id(:) - real*8 :: r8val - integer*8 :: i8val + integer*8 :: file, i, status + integer*4, allocatable :: data(:) + ! init MPI & H5hut comm = MPI_COMM_WORLD call mpi_init(ierr) call mpi_comm_rank(comm, rank, ierr) - - ! open the a file for parallel writing - file_id = h5pt_set_verbosity_level(5) - file_id = h5pt_openw_par('test.h5', comm) - - ! in the Fortran API, time steps start at 1 - status = h5pt_setstep(file_id, 1_8) - - ! write an attribute to the file - status = h5pt_writefileattrib_string(file_id, 'desc', 'This is a test.') - - r8val = 0.5 - i8val = 1 - status = h5pt_writefileattrib_r8(file_id, 'double', r8val, i8val) + call h5_abort_on_error () ! create fake data - npoints = 99 - allocate(particles(npoints), id(npoints)) - do i=1,npoints - particles(i) = real(i+npoints*rank) - id(i) = i+npoints*rank + allocate (data (NPOINTS)) + do i = 1, NPOINTS + data (i) = i + NPOINTS*rank enddo + ! 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_id, npoints) + status = h5pt_setnpoints (file, npoints) ! write the particles - status = h5pt_writedata_r8(file_id, "x", particles) + status = h5pt_writedata_i4 (file, "data", data) - ! write the ids - status = h5pt_writedata_i8(file_id, "id", id) + ! cleanup + status = h5_closefile (file) + deallocate (data) + call mpi_finalize (ierr) - ! close the file - status = h5pt_close(file_id) - - deallocate(particles, id) - - call mpi_finalize(ierr) - -end program H5PartTest +end program write_setnparticles diff --git a/examples/H5Part/write_setview.c b/examples/H5Part/write_setview.c index a3c8765..3dd34f4 100644 --- a/examples/H5Part/write_setview.c +++ b/examples/H5Part/write_setview.c @@ -1,57 +1,60 @@ -#include -#include -#include -#include +/* + Copyright (c) 2006-2013, 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. -#define DATASIZE 32 -#define ITERS 4 + License: see file COPYING in top level of source distribution. +*/ + +#include +#include "H5hut.h" + +#define FNAME "example_setview.h5" +#define DATASIZE 32 +#define ITERS 4 int main ( int argc, char** argv ) { - int i, rank, nprocs; - h5_int32_t data[ITERS*DATASIZE]; - h5_int64_t stat; - h5_int64_t offset; - h5_file_t file; - - // initialize MPI + h5_int64_t npoints = ITERS*DATASIZE + + // initialize MPI & H5hut MPI_Init (&argc, &argv); - MPI_Comm_rank (MPI_COMM_WORLD, &rank); - MPI_Comm_size (MPI_COMM_WORLD, &nprocs); + MPI_Comm comm = MPI_COMM_WORLD; + int rank = 0; + MPI_Comm_rank (comm, &rank); - H5SetVerbosityLevel(1); - - file = H5OpenFile ("test.h5", H5_O_WRONLY, MPI_COMM_WORLD); - assert (file != H5_FAILURE); - - stat = H5SetStep(file, 0); - assert (stat == H5_SUCCESS); - - stat = H5PartSetNumParticles(file, ITERS*DATASIZE); - assert (stat == H5_SUCCESS); + H5AbortOnError (); // create fake data - for (i=0; i