examples/H5Part/read_strided{.c,f.f90}

- compute and set a canonical view
This commit is contained in:
2015-10-16 16:02:17 +02:00
parent 6efdfce033
commit ca7dd3b99c
2 changed files with 25 additions and 11 deletions
+13 -6
View File
@@ -13,8 +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_DEBUG_ALL;
const h5_int64_t h5_verbosity = H5_VERBOSE_DEFAULT;
//const h5_int64_t h5_verbosity = H5_DEBUG_ALL;
int
main (
@@ -35,11 +35,18 @@ main (
h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, H5_PROP_DEFAULT);
H5SetStep (file, 0);
// Get number of particles in datasets
h5_int64_t num_particles = H5PartGetNumParticles (file);
// compute 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)
num_particles += num_particles_total % comm_size;
printf ("[proc %d]: particles in view: %lld\n", comm_rank, (long long)num_particles);
printf ("[proc %d]: total number of particles: %lld\n",
comm_rank, (long long unsigned)num_particles_total);
// set number of particles and memory stride
H5PartSetNumParticlesStrided (file, 98, 6);
H5PartSetNumParticlesStrided (file, num_particles, 6);
// read data
h5_float64_t* data = calloc (6*num_particles, sizeof (*data));
@@ -51,7 +58,7 @@ main (
H5PartReadDataFloat64 (file, "pz", data+5);
// print dataset "x"
for (int i = 0; i < num_particles*6-6; i+=6) {
for (int i = 0; i < num_particles*6; i+=6) {
printf ("[proc %d]: local index = %d, value = %6.3f\n",
comm_rank, i, data[i]);
}
+12 -5
View File
@@ -20,7 +20,7 @@ program read_stridedf
integer :: comm, comm_size, comm_rank, mpi_ierror
integer*8 :: file, h5_ierror
integer*8 :: num_particles
integer*8 :: num_particles, num_particles_total
real*8, allocatable :: data(:)
integer*8 :: i, start
@@ -36,10 +36,17 @@ program read_stridedf
file = h5_openfile (fname, H5_O_RDONLY, H5_PROP_DEFAULT)
h5_ierror = h5_setstep(file, 1_8)
! Get number of particles in datasets
num_particles = h5pt_getnpoints (file)
! set number of particles and memory stride
! compute 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
num_particles = num_particles + mod (num_particles_total, comm_size)
end if
write (*, "('Total number of particles: ', i8)") num_particles_total
write (*, "('Number of particles on this core: ', i8)") num_particles
! set number of particeles and memory stride
h5_ierror = h5pt_setnpoints_strided (file, num_particles, 6_8)
! read data