Example 1: Parallel write
To view and/or download the first example code, click on this file name: parallel_write.c
In this example, each MPI process (up to 4 processes) writes a different dataset into an HDF5 file. If the number of processes is less than four, some datasets will be empty (zeros). The instructions are written to work properly on TACC Frontera, but with appropriate modifications, they ought to work on other systems as well.
To begin, load the PHDF5 module and view its "help" information, which offers guidance on compiling:
$ module load phdf5
$ module help phdf5
Compile the example code, parallel_write.c
:
$ mpicc -o parallel_write.exe -I$TACC_HDF5_INC -L$TACC_HDF5_LIB -lhdf5 -lz parallel_write.c
Run the executable according to the following template (note that on TACC systems, ibrun
normally replaces mpirun
):
$ mpirun -np <procs> ./parallel_write.exe <filename> <dataset_dimx> <dataset_dimy>
For example, to have two processes write two (nonzero) 4x4 datasets into the output file, run the following command:
$ mpirun -np 2 ./parallel_write.exe test1.h5 4 4
Check the output using h5dump
:
$ h5dump test1.h5
Sample Output from h5dump:
Then try varying the number of processes:
$ mpirun -np 4 ./parallel_write.exe test2.h5 4 4
$ h5dump test2.h5
Based on how the source code is written, do you understand the differences in the output from h5dump
?