Example 3: Hyperslabs
The next pair of examples demonstrates the use of hyperslabs while writing an HDF5 file in parallel. Note that, unlike the previous examples, one can use hyperslabs to write partial data into the same dataset in parallel. Click on the links below to get source codes for the examples.
Contiguous example: parallel_write_hslab_contiguous.c
Chunked example: parallel_write_hslab_chunk.c
Contiguous writes
Compile the example:
$ mpicc -o parallel_write_hslab_contiguous.exe /
-I$TACC_HDF5_INC -L$TACC_HDF5_LIB /
-lhdf5 -lz parallel_write_hslab_contiguous.c
Run the executable according to the following template (note that on TACC systems, ibrun
normally replaces mpirun
):
$ mpirun -np <procs> ./parallel_write_hslab_contiguous.exe <filename> <dataset_dimx> <dataset_dimy>
For example, to have each process write a different row of the 4x6 dataset into the output file, run the following command:
$ mpirun -np 4 ./parallel_write_hslab_contiguous.exe test2.h5 4 6
Check the output using h5dump test2.h5
:
Chunked writes
This example illustrates chunked writes in parallel using hyperslabs.
Compile the example:
$ mpicc -o parallel_write_hslab_chunk.exe /
-I$TACC_HDF5_INC -L$TACC_HDF5_LIB /
-lhdf5 -lz parallel_write_hslab_chunk.c
Run the executable according to the following template (note that on TACC systems, ibrun
normally replaces mpirun
):
$ mpirun -np <procs> ./parallel_write_hslab_chunk.exe /
<filename> <dataset_dimx> <dataset_dimy> /
<nprocX> <nprocY>
For example, to have each process write a different 2x3 submatrix of the 4x6 dataset into the output file, run the following command:
$ mpirun -np 4 ./parallel_write_hslab_chunk.exe test2.h5 4 6 2 2
Check the output using h5dump test2.h5
:
In each case, does the output of h5dump
match your expectations?