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:

HDF5 "test1.h5" {
GROUP "/" {
    DATASET "v1" {
        DATATYPE H5T_STD_132LE
        DATASPACE SIMPLE { (4, 4) / (4, 4) }
        DATA {
        (0,0): 10, 10, 10, 10,
        (1,0): 10, 10, 10, 10,
        (2,0): 10, 10, 10, 10,
        (3,0): 10, 10, 10, 10
        }
    }
    DATASET "v2" {
        DATATYPE H5T_STD_132LE
        DATASPACE SIMPLE { (4, 4) / (4, 4) }
        DATA {
        (0,0): 11, 11, 11, 11,
        (1,0): 11, 11, 11, 11,
        (2,0): 11, 11, 11, 11,
        (3,0): 11, 11, 11, 11
        }
    }
    DATASET "v3" {
        DATATYPE H5T_STD_132LE
        DATASPACE SIMPLE { (4, 4) / (4, 4) }
        DATA {
        (0,0): 0, 0, 0, 0,
        (1,0): 0, 0, 0, 0,
        (2,0): 0, 0, 0, 0,
        (3,0): 0, 0, 0, 0
        }
    }
    DATASET "v4" {
        DATATYPE H5T_STD_132LE
        DATASPACE SIMPLE { (4, 4) / (4, 4) }
        DATA {
        (0,0): 0, 0, 0, 0,
        (1,0): 0, 0, 0, 0,
        (2,0): 0, 0, 0, 0,
        (3,0): 0, 0, 0, 0
        }
    }
}
}
Output results: all values equal 10 in dataset 1, 11 in dataset 2, and 0 in datasets 3 and 4.

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?

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement