From a75effa9489e41915b624084c61fba144003b448 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Tue, 24 Jun 2014 18:10:45 -0500 Subject: [PATCH] Add a simple test of one's h5py installation. --- utils/test_h5py.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 utils/test_h5py.py diff --git a/utils/test_h5py.py b/utils/test_h5py.py new file mode 100644 index 00000000..f2949560 --- /dev/null +++ b/utils/test_h5py.py @@ -0,0 +1,37 @@ +""" +Simple test of a parallel build of h5py (from h5py's documentation). + +http://h5py.readthedocs.org/en/latest/mpi.html#using-parallel-hdf5-from-h5py + +If you've built h5py properly against a parallel build of hdf5, you should be +able to run this code with:: + + $ mpiexec -n 4 python test_h5py.py + +and then check the output with `h5dump`:: + + $ h5dump parallel_test.hdf5 + HDF5 "parallel_test.hdf5" { + GROUP "/" { + DATASET "test" { + DATATYPE H5T_STD_I32LE + DATASPACE SIMPLE { ( 4 ) / ( 4 ) } + DATA { + (0): 0, 1, 2, 3 + } + } + } + } +""" + +from mpi4py import MPI +import h5py + +rank = MPI.COMM_WORLD.rank # The process ID (integer 0-3 for 4-process run) + +f = h5py.File('parallel_test.hdf5', 'w', driver='mpio', comm=MPI.COMM_WORLD) + +dset = f.create_dataset('test', (4,), dtype='i') +dset[rank] = rank + +f.close()