HDF5

From SciNet Users Documentation
Jump to navigation Jump to search

To compile a serial program that uses HDF5, use the module command to set your paths correctly, then link the libraries at compile time.

In this example, the C-source code test.c uses both the base HDF5 libraries and the newer high-level routines (i.e. it has #include "hdf5.h" and #include "hdf5_hl.h"), so needs libhdf5 and libhdf5_hl:

C-version

 module purge
 module load intel/2018.2 hdf5/1.8.20 netcdf/4.6.1 
 icc -o test test.c -lhdf5_hl -lhdf5 -limf
 #or, if you prefer to be explicit,
 icc -o test test.c -L${SCINET_HDF5_ROOT}/lib -lhdf5_hl -lhdf5 -limf


The equivalent Fortran-version, would be:

 module purge
 module load intel/2018.2 hdf5/1.8.20 netcdf/4.6.1
 ifort -o test test.c  -lhdf5_fortran -lhdf5 -lsz -lz
 #or, if you prefer to be explicit,
 ifort -o test test.c  -L${SCINET_HDF5_ROOT}/lib -lhdf5_fortran -lhdf5 -L{$SCINET_SZIP_LIB} -lsz -lz


Remember when you run the program that you must have loaded the corresponding module, e.g. hdf5/187-v18-serial-intel in the case of the example.

In addition to the serial version, there are modules for parallel implemetations (e.g. with open/mpi) and Intel and GNU compilers.
You can use module avail hdf5, to check which modules are available and fit better your needs.


Further material about HDF5

HDF5-Tables: HDF5_table

Slides and examples from a parallel I/O course that may be useful:

https://support.scinet.utoronto.ca/wiki/index.php/Knowledge_Base:_Tutorials_and_Manuals#I.2FO

https://support.scinet.utoronto.ca/wiki/images/a/af/Netcdfhdf5.pdf