examples/H5Part

- reviewed
This commit is contained in:
2015-09-08 20:53:07 +02:00
parent ec3a29d7e4
commit 106be817d9
15 changed files with 461 additions and 335 deletions
+22 -11
View File
@@ -9,35 +9,46 @@
#include "H5hut.h"
#define DEFAULT_VERBOSITY H5_VERBOSE_DEFAULT
// name of input file
const char* fname = "example_setview.h5";
#define FNAME "example_setview.h5"
// H5hut verbosity level
const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT;
int
main (
int argc, char* argv[]
){
h5_int64_t verbosity = DEFAULT_VERBOSITY;
// initialize MPI & H5hut
int comm_rank = 0;
int comm_size = 1;
MPI_Init (&argc, &argv);
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank (comm, &comm_rank);
int comm_size = 1;
MPI_Comm_size (comm, &comm_size);
int comm_rank = 0;
MPI_Comm_rank (comm, &comm_rank);
H5AbortOnError ();
H5SetVerbosityLevel (verbosity);
H5SetVerbosityLevel (h5_verbosity);
// open file and go to step#0
h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
// open file and go to first step
h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// set canonical view
H5PartSetCanonicalView (file);
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 ();
}
+32 -14
View File
@@ -13,28 +13,46 @@ program read_canonicalview
implicit none
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_setview.h5"
! name of input file
character (len=*), parameter :: fname = "example_setview.h5"
integer :: comm, rank, ierr
integer*8 :: file, status, num_particles
! 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 :: num_particles
integer*8 :: i
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_init (mpi_error)
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 the a file for parallel writing and ceate step #0
file = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
status = h5_setstep(file, 1_8)
! open file and go to first step
file = h5_openfile (fname, H5_O_RDONLY, H5_PROP_DEFAULT)
h5_ierror = h5_setstep(file, 1_8)
status = h5pt_setcanonicalview (file)
! set canonical view
h5_ierror = h5pt_setcanonicalview (file)
num_particles = h5pt_getnpoints (file)
write (*, "('[proc ', i4, '] particles in view: ', i8)") rank, num_particles
write (*, "('[proc ', i4, '] particles in view: ', i8)") comm_rank, num_particles
! read and print data
allocate (data (num_particles))
h5_ierror = h5pt_readdata_i4 (file, "data", data);
do i = 1, num_particles
write (*, "('[proc ', i4, ']: local index = ', i4, ', value = ', i4)") &
comm_rank, i, data(i)
end do
! cleanup
status = h5_closefile (file)
call mpi_finalize (ierr)
deallocate (data)
h5_ierror = h5_closefile (file)
call mpi_finalize (mpi_ierror)
end program read_canonicalview
+25 -15
View File
@@ -9,42 +9,52 @@
#include "H5hut.h"
#define FNAME "example_setnparticles.h5"
// name of input file
const char* fname = "example_setnparticles.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);
int comm_size = 0;
MPI_Comm_size (comm, &comm_size);
H5AbortOnError ();
H5SetVerbosityLevel (H5_VERBOSE_INFO);
H5SetVerbosityLevel (h5_verbosity);
// open file and go to first step
h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
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;
// compute and set number of particles this process has to read
h5_ssize_t num_particles_total = H5PartGetNumParticles (file);
h5_ssize_t num_particles = num_particles_total / comm_size;
if (comm_rank+1 == comm_size)
nparticels += nparticels_total % comm_size;
num_particles += num_particles_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);
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);
// read data
H5PartSetNumParticles (file, nparticels);
h5_int32_t* data = calloc (nparticels, sizeof (*data));
H5PartSetNumParticles (file, 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 ();
}
+32 -23
View File
@@ -13,44 +13,53 @@ program read_setnparticles
implicit none
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_setnparticles.h5"
! name of input file
character (len=*), parameter :: fname = "example_setnparticles.h5"
integer :: comm, comm_rank, comm_size, ierr
integer*8 :: file, status
integer*8 :: nparticels, nparticels_total
! 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 :: num_particles, num_particles_total
integer*8 :: i
integer*4, allocatable :: data(:)
! initialize MPI & H5hut
comm = MPI_COMM_WORLD
call mpi_init(ierr)
call mpi_comm_rank (comm, comm_rank, ierr)
call mpi_comm_size (comm, comm_size, ierr)
call mpi_init (mpi_error)
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 go to first step
file = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
status = h5_setstep(file, 1_8)
! compute number of particles this process has to read
nparticels_total = h5pt_getnpoints (file)
nparticels = nparticels_total / comm_size
file = h5_openfile (fname, H5_O_RDONLY, H5_PROP_DEFAULT)
h5_ierror = h5_setstep(file, 1_8)
! compute and set number of particles this process has to read
num_particles_total = h5pt_getnpoints (file)
num_particles = num_particles_total / comm_size
if (comm_rank+1 == comm_size) then
nparticels = nparticels + mod (nparticels_total, comm_size)
num_particles = num_particles + mod (num_particles_total, comm_size)
end if
write (*, "('Total number of particles: ', i8)") nparticels_total
write (*, "('Number of particles on this core: ', i8)") nparticels
write (*, "('Total number of particles: ', i8)") num_particles_total
write (*, "('Number of particles on this core: ', i8)") num_particles
! read data
status = h5pt_setnpoints (file, nparticels)
allocate (data (nparticels))
status = h5pt_readdata_i4 (file, "data", data)
h5_ierror = h5pt_setnpoints (file, num_particles)
! read and print data
allocate (data (num_particles))
h5_ierror = h5pt_readdata_i4 (file, "data", data)
do i = 1, num_particles
write (*, "('[proc ', i4, ']: local index = ', i4, ', value = ', i4)") &
comm_rank, i, data(i)
end do
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
h5_ierror = h5_closefile (file)
call mpi_finalize (mpi_ierror)
end program read_setnparticles
+26 -22
View File
@@ -9,41 +9,41 @@
#include "H5hut.h"
#define DEFAULT_VERBOSITY H5_VERBOSE_DEFAULT
// name of input file
const char* fname = "example_setview.h5";
#define FNAME "example_setview.h5"
// H5hut verbosity level
const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT;
int
main (
int argc, char* argv[]
){
h5_int64_t verbosity = DEFAULT_VERBOSITY;
// initialize MPI & H5hut
int comm_rank = 0;
int comm_size = 1;
MPI_Init (&argc, &argv);
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank (comm, &comm_rank);
int comm_size = 1;
MPI_Comm_size (comm, &comm_size);
int comm_rank = 0;
MPI_Comm_rank (comm, &comm_rank);
H5AbortOnError ();
H5SetVerbosityLevel (verbosity);
H5SetVerbosityLevel (h5_verbosity);
// open file and go to first step
h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// compute a "canonical" view: all cores get almost the same number of
// particles
h5_int64_t total_particles = H5PartGetNumParticles (file);
h5_int64_t nparticles = total_particles / comm_size;
h5_int64_t remainder = total_particles % comm_size;
h5_int64_t start = comm_rank * nparticles;
// compute and set a "canonical" view:
// all cores get almost the same number of particles
h5_int64_t num_particles_total = H5PartGetNumParticles (file);
h5_int64_t num_particles = num_particles_total / comm_size;
h5_int64_t remainder = num_particles_total % comm_size;
h5_int64_t start = comm_rank * num_particles;
// adjust number of local particles
if (comm_rank < remainder)
nparticles++;
num_particles++;
// adjust start
if (comm_rank < remainder)
@@ -51,19 +51,23 @@ main (
else
start += remainder;
// Note: setting end = start - 1 forces the
// selection of zero particles!
h5_int64_t end = start + nparticles - 1;
// Note:
// setting end = start - 1 forces the selection of zero particles!
h5_int64_t end = start + num_particles - 1;
printf ("[proc %d]: set view to [%lld..%lld]\n", comm_rank, start, end);
H5PartSetView (file, start, end);
h5_int32_t* data = calloc (nparticles, sizeof (*data));
// read and print data
h5_int32_t* data = calloc (num_particles, sizeof (*data));
H5PartReadDataInt32 (file, "data", data);
for (int i = 0; i < nparticles; i++) {
for (int i = 0; i < num_particles; i++) {
printf ("[proc %d]: global index = %lld; local index = %d, value = %d\n",
comm_rank, start+i, i, data[i]);
}
// cleanup
free (data);
H5CloseFile (file);
return MPI_Finalize ();
}
+34 -33
View File
@@ -13,40 +13,40 @@ program read_setviewf
implicit none
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_setview.h5"
integer*8, parameter :: DEFAULT_VERBOSITY = H5_VERBOSE_DEFAULT
! name of input file
character (len=*), parameter :: fname = "example_setview.h5"
integer*8 :: verbosity = DEFAULT_VERBOSITY
integer :: comm, comm_rank, comm_size, ierr
integer*8 :: file, status
integer*8 :: i
! 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 :: num_particles, num_particles_total
integer*8 :: i, start, end, remainder
integer*4, allocatable :: data(:)
integer*8 :: total_particles, nparticles, remainder
integer*8 :: start, end
! initialize MPI & H5hut
comm = MPI_COMM_WORLD
call mpi_init (ierr)
call mpi_comm_rank (comm, comm_rank, ierr)
call mpi_comm_size (comm, comm_size, ierr)
call mpi_init (mpi_error)
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 (verbosity)
call h5_set_verbosity_level (h5_verbosity)
! open file and go to first step
file = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
status = h5_setstep (file, 1_8)
file = h5_openfile (fname, H5_O_RDONLY, H5_PROP_DEFAULT)
h5_ierror = h5_setstep(file, 1_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;
! compute a "canonical" view:
! all cores get almost the same number of particles
num_particles_total = h5pt_getnpoints (file);
num_particles = num_particles_total / comm_size;
remainder = mod (num_particles_total, comm_size);
start = comm_rank * num_particles;
! adjust number of local particles
if (comm_rank < remainder) then
nparticles = nparticles + 1
num_particles = num_particles + 1
end if
! adjust start
@@ -56,27 +56,28 @@ program read_setviewf
start = start + remainder
end if
! Note: setting end = start - 1 forces the
! selection of zero particles!
end = start + nparticles - 1;
! Note:
! setting end = start - 1 forces the selection of zero particles!
end = start + num_particles - 1;
! in Fortran we start at 1 not 0
! adjust Fortran indices: 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))
h5_ierror = h5pt_setview (file, start, end);
status = h5pt_readdata_i4 (file, "data", data);
do i = 1, nparticles
! read and print data
allocate (data (num_particles))
h5_ierror = h5pt_readdata_i4 (file, "data", data);
do i = 1, num_particles
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)
h5_ierror = h5_closefile (file)
call mpi_finalize (mpi_ierror)
end program read_setviewf
+22 -12
View File
@@ -9,37 +9,39 @@
#include "H5hut.h"
#define DEFAULT_VERBOSITY H5_VERBOSE_DEFAULT
// name of input file
const char* fname = "example_strided.h5";
#define FNAME "example_strided.h5"
// H5hut verbosity level
const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT;
int
main (
int argc, char* argv[]
){
h5_int64_t verbosity = DEFAULT_VERBOSITY;
// initialize MPI & H5hut
MPI_Init (&argc, &argv);
MPI_Comm comm = MPI_COMM_WORLD;
int rank = 0;
MPI_Comm_rank (comm, &rank);
int comm_size = 1;
MPI_Comm_size (comm, &comm_size);
int comm_rank = 0;
MPI_Comm_rank (comm, &comm_rank);
H5AbortOnError ();
H5SetVerbosityLevel (verbosity);
H5SetVerbosityLevel (h5_verbosity);
// open file and go to first step
h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
// open file and go to first step
h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// Get number of particles in datasets and allocate memory
// Get number of particles in datasets
h5_int64_t num_particles = H5PartGetNumParticles (file);
h5_float64_t* data = calloc (6*num_particles, sizeof (*data));
// set number of particles and memory stride
H5PartSetNumParticlesStrided (file, num_particles, 6);
// read data
h5_float64_t* data = calloc (6*num_particles, sizeof (*data));
H5PartReadDataFloat64 (file, "x", data+0);
H5PartReadDataFloat64 (file, "y", data+1);
H5PartReadDataFloat64 (file, "z", data+2);
@@ -47,6 +49,14 @@ main (
H5PartReadDataFloat64 (file, "py", data+4);
H5PartReadDataFloat64 (file, "pz", data+5);
// print dataset "x"
for (int i = 0; i < num_particles; i+=6) {
printf ("[proc %d]: local index = %d, value = %6.3f\n",
comm_rank, i, data[i]);
}
// cleanup
free (data);
H5CloseFile (file);
return MPI_Finalize ();
}
+35 -27
View File
@@ -12,47 +12,55 @@ program read_stridedf
use H5hut
implicit none
include 'mpif.h'
! name of input file
character (len=*), parameter :: fname = "example_strided.h5"
! the file name we want to read
character (len=*), parameter :: FNAME = "example_strided.h5"
integer*8, parameter :: DEFAULT_VERBOSITY = H5_VERBOSE_DEFAULT
integer*8 :: verbosity = DEFAULT_VERBOSITY
integer :: comm, comm_rank, comm_size, ierr
integer*8 :: file, status
! 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 :: num_particles
real*8, allocatable :: data(:)
integer*8 :: nparticles
integer*8 :: i, start
! initialize MPI & H5hut
comm = MPI_COMM_WORLD
call mpi_init (ierr)
call mpi_comm_rank (comm, comm_rank, ierr)
call mpi_comm_size (comm, comm_size, ierr)
call mpi_init (mpi_error)
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 (verbosity)
call h5_set_verbosity_level (h5_verbosity)
! open file and go to first step
file = h5_openfile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT)
status = h5_setstep (file, 1_8)
file = h5_openfile (fname, H5_O_RDONLY, H5_PROP_DEFAULT)
h5_ierror = h5_setstep(file, 1_8)
! Get number of particles in datasets and allocate memory
nparticles = h5pt_getnpoints (file)
allocate (data (6*nparticles))
! Get number of particles in datasets
num_particles = h5pt_getnpoints (file)
! set number of particles and memory stride
status = h5pt_setnpoints_strided (file, nparticles, 6_8)
h5_ierror = h5pt_setnpoints_strided (file, num_particles, 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:))
allocate (data (6*num_particles))
h5_ierror = h5pt_readdata_r8 (file, "x", data(1:))
h5_ierror = h5pt_readdata_r8 (file, "y", data(2:))
h5_ierror = h5pt_readdata_r8 (file, "z", data(3:))
h5_ierror = h5pt_readdata_r8 (file, "px", data(4:))
h5_ierror = h5pt_readdata_r8 (file, "py", data(5:))
h5_ierror = h5pt_readdata_r8 (file, "pz", data(6:))
! print dataset "x"
start = 1
do i = start, num_particles*6, 6
write (*, "('[proc ', i4, ']: global index = ', i4, '; local index = ', i4, ', value = ', f10.2)") &
comm_rank, start+i-2, i, data(i)
end do
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
h5_ierror = h5_closefile (file)
call mpi_finalize (mpi_ierror)
end program read_stridedf
+30 -24
View File
@@ -7,53 +7,59 @@
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"
#define DEFAULT_VERBOSITY H5_VERBOSE_DEFAULT
// name of output file
const char* fname = "example_core_vfd.h5";
#define FNAME "example_core_vfd"
#define DATASIZE 32
// H5hut verbosity level
const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT;
// number of particles we are going to write per core
const h5_int64_t num_particles = 32;
int
main (
int argc, char* argv[]
int argc,
char* argv[]
){
h5_int64_t verbosity = DEFAULT_VERBOSITY;
// initialize MPI & H5hut
int comm_rank = 0;
int comm_size = 1;
MPI_Init (&argc, &argv);
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank (comm, &comm_rank);
int comm_size = 1;
MPI_Comm_size (comm, &comm_size);
int comm_rank = 0;
MPI_Comm_rank (comm, &comm_rank);
H5AbortOnError ();
H5SetVerbosityLevel (verbosity);
H5SetVerbosityLevel (h5_verbosity);
// open file and go to step#0
char fname[64];
sprintf (fname, "%s.%d.h5", FNAME, comm_rank);
// open file and create first step
h5_prop_t prop = H5CreateFileProp ();
H5SetPropFileCoreVFD (prop);
h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, prop);
h5_file_t file = H5OpenFile (fname, H5_O_WRONLY, prop);
H5SetStep (file, 0);
h5_int32_t data[DATASIZE];
H5PartSetNumParticles(file, DATASIZE);
// set number of particles this process is going to write
H5PartSetNumParticles(file, num_particles);
// create fake data
for (int i = 0; i < DATASIZE; i++) {
data[i] = i + comm_rank * DATASIZE;
h5_int32_t data[num_particles];
for (int i = 0; i < num_particles; i++) {
data[i] = i + comm_rank * num_particles;
}
// write the data
H5PartWriteDataInt32 (file, "data", data);
H5CloseFile (file);
MPI_Finalize ();
return H5_SUCCESS;
// cleanup
H5CloseFile (file);
return MPI_Finalize ();
}
+36 -10
View File
@@ -13,24 +13,50 @@ program write_core_vfd
implicit none
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_core_vfd"
integer*8, parameter :: DIM = 99
! name of output file
character (len=*), parameter :: fname = "example_core_vfd.h5"
integer :: comm, rank, ierr
integer*8 :: file, status
! H5hut verbosity level
integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT
! 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*8 :: file, h5_ierror
integer*8 :: prop
integer*4 :: i
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_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_WRONLY, prop)
h5_ierror = h5_setstep(file, 1_8)
! set number of particles this process is going to write
h5_ierror = h5pt_setnpoints (file, int8 (num_particles))
! create fake data
allocate (data (num_particles))
do i = 1, num_particles
data (i) = (i-1) + comm_rank * num_particles
end do
! write the data
h5_ierror = h5pt_writedata_i4 (file, "data", data);
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
h5_ierror = h5_closefile (file)
call mpi_finalize (mpi_ierror)
end program write_core_vfd
+21 -19
View File
@@ -7,44 +7,46 @@
License: see file COPYING in top level of source distribution.
*/
#include <stdlib.h>
#include "H5hut.h"
#define DEFAULT_VERBOSITY H5_VERBOSE_DEFAULT
// name of output file
const char* fname = "example_setnparticles.h5";
#define FNAME "example_setnparticles.h5"
#define NUM_PARTICLES 3
// H5hut verbosity level
const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT;
// number of particles we are going to write per core
const h5_int64_t num_particles = 99;
int
main (
int argc,
char* argv[]
){
h5_int64_t verbosity = DEFAULT_VERBOSITY;
// initialize MPI & H5hut
MPI_Init (&argc, &argv);
MPI_Comm comm = MPI_COMM_WORLD;
int rank = 0;
MPI_Comm_rank (comm, &rank);
int comm_size = 1;
MPI_Comm_size (comm, &comm_size);
int comm_rank = 0;
MPI_Comm_rank (comm, &comm_rank);
H5AbortOnError ();
H5SetVerbosityLevel (verbosity);
H5SetVerbosityLevel (h5_verbosity);
// create fake data
h5_int32_t data[NUM_PARTICLES];
h5_int64_t num_particles = NUM_PARTICLES;
for (int i = 0; i < num_particles; i++) {
data[i] = i + num_particles * rank;
}
// open file and create step #0
h5_file_t file = H5OpenFile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT);
// open file and create first step
h5_file_t file = H5OpenFile (fname, H5_O_WRONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// define number of items this process will write
// define number of particles this process will write
H5PartSetNumParticles (file, num_particles);
// create fake data
h5_int32_t data[num_particles];
for (int i = 0; i < num_particles; i++) {
data[i] = i + num_particles * comm_rank;
}
// write data
H5PartWriteDataInt32 (file, "data", data);
+30 -22
View File
@@ -13,40 +13,48 @@ program write_setnparticles
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*8 :: file, status
! name of output file
character (len=*), parameter :: fname = "example_setnparticles.h5"
! H5hut verbosity level
integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT
! 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*8 :: file, h5_ierror
integer*4 :: i
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_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
file = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)
h5_ierror = h5_setstep(file, 0_8)
! define number of particles this process will write
h5_ierror = h5pt_setnpoints (file, num_particles)
! create fake data
allocate (data (NPOINTS))
do i = 1, NPOINTS
data (i) = i + int(NPOINTS)*rank
allocate (data (num_particles))
do i = 1, num_particles
data (i) = i + int(num_particles)*comm_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, npoints)
! write the particles
status = h5pt_writedata_i4 (file, "data", data)
! write data
h5_ierror = h5pt_writedata_i4 (file, "data", data)
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
h5_ierror = h5_closefile (file)
call mpi_finalize (mpi_ierror)
end program write_setnparticles
+40 -32
View File
@@ -7,60 +7,68 @@
License: see file COPYING in top level of source distribution.
*/
#include <stdlib.h>
#include "H5hut.h"
#define DEFAULT_VERBOSITY H5_VERBOSE_DEFAULT
// name of output file
const char* fname = "example_setview.h5";
#define FNAME "example_setview.h5"
#define DATASIZE 32
#define ITERS 4
// H5hut verbosity level
const h5_int64_t h5_verbosity = H5_DEBUG_ALL;
// we are going to write multiple consecutive blocks
const h5_int64_t num_blocks = 4;
const h5_int64_t num_particles_per_block = 32;
int
main (
int argc, char** argv
) {
h5_int64_t verbosity = DEFAULT_VERBOSITY;
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 (verbosity);
H5SetVerbosityLevel (h5_verbosity);
// create fake data
h5_int64_t npoints = ITERS*DATASIZE;
h5_int32_t data[ITERS*DATASIZE];
for (int i = 0; i < npoints; i++) {
data[i] = i + comm_rank*npoints;
}
// open file and create first step
h5_file_t file = H5OpenFile (fname, H5_O_WRONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// open file and create step #0
h5_file_t file = H5OpenFile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT);
H5SetStep(file, 0);
/*
If we want to write consecutive blocks, the 'view' can be defined
with H5PartSetview(). Otherwise we have to define the total number
of particles with H5PartSetNumParticles().
*/
const h5_int64_t offset = comm_rank * num_blocks * num_particles_per_block;
H5PartSetView (
file,
offset,
offset + num_blocks*num_particles_per_block -1);
// before we can start writing, we have to define the number of
// items this processor will write
H5PartSetNumParticles(file, npoints);
// write ITER consecutive blocks of size DATASIZE
h5_int64_t offset = comm_rank * npoints;
for (int i = 0; i < ITERS; i++) {
// write multiple consecutive blocks
for (int i = 0; i < num_blocks; i++) {
// create fake data
h5_int32_t data[num_particles_per_block];
for (int j = 0; j < num_particles_per_block; j++) {
data[j] = j + i*num_particles_per_block + offset;
}
// set the "view" to select a subset of the dataset
H5PartSetView (
file,
offset + i * DATASIZE,
offset + (i+1) * DATASIZE - 1);
// write the data
H5PartWriteDataInt32 (file, "data", data + i*DATASIZE);
offset + i*num_particles_per_block,
offset + (i+1)*num_particles_per_block - 1);
// write data
H5PartWriteDataInt32 (file, "data", data);
}
// done
H5CloseFile(file);
MPI_Finalize();
return H5_SUCCESS;
return MPI_Finalize();
}
+35 -33
View File
@@ -13,52 +13,54 @@ program write_setview
implicit none
include 'mpif.h'
! the file name we want to read
character (len=*), parameter :: FNAME = "example_setview.h5"
integer*8, parameter :: DATASIZE = 32
integer*8, parameter :: ITERS = 4
! name of output file
character (len=*), parameter :: fname = "example_setview.h5"
integer*4, parameter :: npoints = ITERS*DATASIZE
! H5hut verbosity level
integer*8, parameter :: h5_verbosity = H5_VERBOSE_DEFAULT
integer :: comm, rank, ierr
integer*8 :: file, status
integer*4 :: i
! we are going to write multiple consecutive blocks
integer*8, parameter :: num_blocks = 4;
integer*8, parameter :: num_particles_per_block = 32
integer :: comm, comm_size, comm_rank, mpi_ierror
integer*8 :: file, h5_ierror
integer*8 :: i, j, offset
integer*4, allocatable :: data(:)
integer*8 start, end, offset
! init MPI & H5hut
! initialize MPI & H5hut
comm = MPI_COMM_WORLD
call mpi_init(ierr)
call mpi_comm_rank(comm, rank, ierr)
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 (-1_8)
call h5_set_verbosity_level (h5_verbosity)
! create fake data
allocate (data (npoints))
do i = 1, npoints
data (i) = (i-1) + rank*npoints
enddo
! open the a file for parallel writing and ceate step #0
! open file and create first step
file = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)
status = h5_setstep(file, 1_8)
h5_ierror = h5_setstep(file, 1_8)
! set the size of the 1D array
status = h5pt_setnpoints (file, int8(npoints))
! If we want to write consecutive blocks, the 'view' can be defined
! with H5PartSetview(). Otherwise we have to define the total number
! of particles with H5PartSetNumParticles().
offset = comm_rank * num_blocks * num_particles_per_block+1
h5_ierror = h5pt_setview (file, offset, offset + num_blocks*num_particles_per_block)
offset = rank*npoints
do i = 1, ITERS
start = offset + 1 + (i-1)*DATASIZE
end = offset + i*DATASIZE
status = h5pt_setview (file, start, end)
! write the particles
status = h5pt_writedata_i4 (file, "data", data ((i-1)*DATASIZE+1))
! write multiple consecutive blocks
allocate (data (num_particles_per_block))
do i = 1, num_blocks
! create fake data
do j = 1, num_particles_per_block
data (i) = int((j-1) + i*num_particles_per_block + offset)
end do
h5_ierror = h5pt_setview (file, offset + i*num_particles_per_block, (i+1)*num_particles_per_block)
! write data
h5_ierror = h5pt_writedata_i4 (file, "data", data)
end do
! cleanup
status = h5_closefile (file)
deallocate (data)
call mpi_finalize (ierr)
h5_ierror = h5_closefile (file)
call mpi_finalize (mpi_ierror)
end program write_setview
+41 -38
View File
@@ -9,62 +9,65 @@
#include "H5hut.h"
#define DEFAULT_VERBOSITY H5_VERBOSE_DEFAULT
// name of output file
const char* fname = "example_strided.h5";
#define FNAME "example_strided.h5"
#define NPOINTS 99
// H5hut verbosity level
const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT;
// number of particles we are going to write per core
const h5_int64_t num_particles = 99;
int
main (
int argc,
char** argv
) {
h5_int64_t verbosity = DEFAULT_VERBOSITY;
// MPI & H5hut init
MPI_Init (&argc, &argv);
int rank;
int argc,
char* argv[]
){
// initialize MPI & H5hut
MPI_Init (&argc, &argv);
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank (comm, &rank);
int comm_size = 1;
MPI_Comm_size (comm, &comm_size);
int comm_rank = 0;
MPI_Comm_rank (comm, &comm_rank);
H5AbortOnError ();
H5SetVerbosityLevel (verbosity);
H5SetVerbosityLevel (h5_verbosity);
// open file and create first step
h5_file_t file = H5OpenFile (fname, H5_O_WRONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// create fake data
h5_float64_t particles[6*NPOINTS];
h5_int64_t id[NPOINTS];
for (int i = 0; i < NPOINTS; i++) {
particles [6*i + 0] = 0.0 + i + NPOINTS * rank;
particles [6*i + 1] = 0.1 + i + NPOINTS * rank;
particles [6*i + 2] = 0.2 + i + NPOINTS * rank;
particles [6*i + 3] = 0.3 + i + NPOINTS * rank;
particles [6*i + 4] = 0.4 + i + NPOINTS * rank;
particles [6*i + 5] = 0.5 + i + NPOINTS * rank;
id [i] = i + NPOINTS * rank;
h5_float64_t data[6*num_particles];
h5_int64_t id[num_particles];
for (int i = 0; i < num_particles; i++) {
data [6*i + 0] = 0.0 + i + num_particles * comm_rank;
data [6*i + 1] = 0.1 + i + num_particles * comm_rank;
data [6*i + 2] = 0.2 + i + num_particles * comm_rank;
data [6*i + 3] = 0.3 + i + num_particles * comm_rank;
data [6*i + 4] = 0.4 + i + num_particles * comm_rank;
data [6*i + 5] = 0.5 + i + num_particles * comm_rank;
id [i] = i + num_particles * comm_rank;
}
// open file with MPI_COMM_WORLD and create step #0
h5_file_t file = H5OpenFile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// define number of items this processor will write and set the
// in-memory striding
H5PartSetNumParticlesStrided (file, NPOINTS, 6);
H5PartSetNumParticlesStrided (file, num_particles, 6);
// write strided data
H5PartWriteDataFloat64 (file, "x", particles+0);
H5PartWriteDataFloat64 (file, "y", particles+1);
H5PartWriteDataFloat64 (file, "z", particles+2);
H5PartWriteDataFloat64 (file, "px", particles+3);
H5PartWriteDataFloat64 (file, "py", particles+4);
H5PartWriteDataFloat64 (file, "pz", particles+5);
H5PartWriteDataFloat64 (file, "x", data+0);
H5PartWriteDataFloat64 (file, "y", data+1);
H5PartWriteDataFloat64 (file, "z", data+2);
H5PartWriteDataFloat64 (file, "px", data+3);
H5PartWriteDataFloat64 (file, "py", data+4);
H5PartWriteDataFloat64 (file, "pz", data+5);
// disable striding to write the ID's
H5PartSetNumParticles (file, NPOINTS);
H5PartSetNumParticles (file, num_particles);
H5PartWriteDataInt64 (file, "id", id);
// cleanup
H5CloseFile (file);
MPI_Finalize ();
return 0;
return MPI_Finalize ();
}