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:


$ h5dump test2.h5
HDF5 "test2.h5"{
GROUP "/" {
    DATASET "v1" {
        DATASPACE SIMPLE { ( 4,6 ) / ( 4,6 ) }
        DATA {
        (0,0): 10, 10, 10, 10, 10, 10,
        (1,0): 11, 11, 11, 11, 11, 11, 
        (2,0): 12, 12, 12, 12, 12, 12, 
        (3,0): 13, 13, 13, 13, 13, 13
        }
    }
}
}
Command and example output: all six values are equal to 10 in the first row of the 4x6 dataset, 11 in the second row, 12 in the third row, 13 in the fourth row.
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:

$ h5dump test2.h5
HDF5 "test2.h5"{
GROUP "/" {
    DATASET "v1" {
        DATASPACE SIMPLE { ( 4,6 ) / ( 4,6 ) }
        DATA {
        (0,0): 10, 10, 10, 11, 11, 11,
        (1,0): 10, 10, 10, 11, 11, 11, 
        (2,0): 12, 12, 12, 13, 13, 13, 
        (3,0): 12, 12, 12, 13, 13, 13
        }
    }
}
}
Command and example output: all values are equal to 10 in top left 2x3 submatrix, 11 in the top right 2x3 submatrix, 12 in the bottom left 2x3 submatrix, 13 in the bottom right 2x3 submatrix

In each case, does the output of h5dump match your expectations?

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