H5Part examples reviewed
This commit is contained in:
@@ -9,21 +9,22 @@
|
||||
|
||||
#include "H5hut.h"
|
||||
|
||||
#define FNAME "example_particles.h5"
|
||||
|
||||
#define FNAME "example_setview.h5"
|
||||
#define VERBOSITY H5_VERBOSE_DEFAULT
|
||||
int
|
||||
main (
|
||||
int argc, char* argv[]
|
||||
){
|
||||
H5AbortOnError ();
|
||||
H5SetVerbosityLevel (VERBOSITY);
|
||||
|
||||
int myproc;
|
||||
// initialize MPI & H5hut
|
||||
int mpi_rank = 0;
|
||||
int mpi_size = 1;
|
||||
MPI_Init (&argc, &argv);
|
||||
MPI_Comm_rank (MPI_COMM_WORLD, &myproc);
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
MPI_Comm_rank (comm, &mpi_rank);
|
||||
MPI_Comm_size (comm, &mpi_size);
|
||||
|
||||
// open file and go to step#0
|
||||
h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
|
||||
|
||||
H5SetStep (file, 0);
|
||||
|
||||
H5PartSetCanonicalView (file);
|
||||
|
||||
@@ -10,25 +10,54 @@
|
||||
#include "H5hut.h"
|
||||
#include "examples.h"
|
||||
|
||||
#define FNAME "example_particles.h5"
|
||||
#define FNAME "example_setview.h5"
|
||||
|
||||
int
|
||||
main (
|
||||
int argc, char* argv[]
|
||||
){
|
||||
H5AbortOnError ();
|
||||
H5SetVerbosityLevel (VERBOSITY);
|
||||
|
||||
int myproc;
|
||||
// initialize MPI & H5hut
|
||||
int mpi_rank = 0;
|
||||
int mpi_size = 1;
|
||||
MPI_Init (&argc, &argv);
|
||||
MPI_Comm_rank (MPI_COMM_WORLD, &myproc);
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
MPI_Comm_rank (comm, &mpi_rank);
|
||||
MPI_Comm_size (comm, &mpi_size);
|
||||
|
||||
// open file and go to step#0
|
||||
h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
|
||||
|
||||
H5SetStep (file, 0);
|
||||
|
||||
// TODO
|
||||
|
||||
// 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 / mpi_size;
|
||||
h5_int64_t remainder = total_particles % mpi_size;
|
||||
h5_int64_t start = mpi_rank * nparticles;
|
||||
|
||||
// adjust number of local particles
|
||||
if (mpi_rank < remainder)
|
||||
nparticles++;
|
||||
|
||||
// adjust start
|
||||
if (mpi_rank < remainder)
|
||||
start += mpi_rank;
|
||||
else
|
||||
start += remainder;
|
||||
|
||||
// Note: if npartices is 0 end = start - 1
|
||||
// this forces the selection of zero particles!
|
||||
h5_int64_t end = start + nparticles - 1;
|
||||
|
||||
printf ("[proc %d]: set view to [%lld..%lld]\n", mpi_rank, start, end);
|
||||
H5PartSetView (file, start, end);
|
||||
h5_int32_t* data = calloc (nparticles, sizeof (*data));
|
||||
|
||||
H5PartReadDataInt32 (file, "data", data);
|
||||
for (int i = 0; i < nparticles; i++) {
|
||||
printf ("[proc %d]: global index = %lld; local index = %d, value = %d\n",
|
||||
mpi_rank, start+i, i, data[i]);
|
||||
}
|
||||
H5CloseFile (file);
|
||||
return MPI_Finalize ();
|
||||
}
|
||||
|
||||
@@ -14,23 +14,24 @@
|
||||
#define DATASIZE 32
|
||||
#define ITERS 4
|
||||
|
||||
int main (
|
||||
int
|
||||
main (
|
||||
int argc, char** argv
|
||||
) {
|
||||
h5_int64_t npoints = ITERS*DATASIZE
|
||||
|
||||
// initialize MPI & H5hut
|
||||
MPI_Init (&argc, &argv);
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
int rank = 0;
|
||||
MPI_Comm_rank (comm, &rank);
|
||||
int mpi_rank = 0;
|
||||
MPI_Comm_rank (comm, &mpi_rank);
|
||||
|
||||
H5AbortOnError ();
|
||||
|
||||
// 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 + rank*npoints;
|
||||
data[i] = i + mpi_rank*npoints;
|
||||
}
|
||||
|
||||
// open file and create step #0
|
||||
@@ -42,7 +43,7 @@ int main (
|
||||
H5PartSetNumParticles(file, npoints);
|
||||
|
||||
// write ITER consecutive blocks of size DATASIZE
|
||||
h5_int64_t offset = rank * npoints;
|
||||
h5_int64_t offset = mpi_rank * npoints;
|
||||
for (int i = 0; i < ITERS; i++) {
|
||||
// set the "view" to select a subset of the dataset
|
||||
H5PartSetView (
|
||||
|
||||
Reference in New Issue
Block a user