read_core_vfd.c 1.89 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
  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"

gsell's avatar
gsell committed
18 19
#include <stdlib.h>

gsell's avatar
gsell committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33
// 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);
gsell's avatar
gsell committed
34
	MPI_Comm comm = MPI_COMM_WORLD;
gsell's avatar
gsell committed
35 36 37 38 39 40 41 42 43
        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 ();
44
        H5SetPropFileCoreVFD (prop, 0);
gsell's avatar
gsell committed
45 46 47 48 49
        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);
gsell's avatar
gsell committed
50
        printf ("[proc %d]: particles in view: %lld\n", comm_rank, (long long)num_particles);
gsell's avatar
gsell committed
51 52 53 54 55 56 57 58 59 60 61 62

	// 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);
gsell's avatar
gsell committed
63 64
	MPI_Finalize ();
        return H5_SUCCESS;
gsell's avatar
gsell committed
65 66
}