Skip to content

Data libraries - NetCDF and HDF5

Many scientific programs store their data in library formats, most common of which are NetCDF and HDF5. In this page we describe how to compile code based on the hdf5, netcdf-c, netcdf-fortran, netcdf-cxx libraries. Before going into the details we describe the global dependency structure of these libraries.

The basic building block for the netcdf libraries is the hdf5 library. The hdf5 library depends itself on compression libraries such as zlib and szip. The hdf5 library can be either built using the system version of zlib/szip or be based on a newer version of zlib/szip compiled by the CHPC.

The once monolithic netcdf library has been split into three parts: netcdf-c, netcdf-fortran, netcdf-cxx. The C-library netcdf-c is built on top of the hdf5 library. The netcdf-fortran (Fortran Library) & netcdf-cxx (C++ Library) libraries are built on top of the netcdf-c library. 

At the end we have the following dependency tree (going from top to bottom):

  1. netcdf-fortran, netcdf-cxx
  2. netcdf-c
  3. hdf5
  4. zlib, szip

All these libraries are built with certain version of a compiler, and as such that compiler needs to be used in order to build a program that depends on these libraries.

Finally, there are also parallel versions of NetCDF and HDF5. These depend on a compiler and a certain MPI version. The Parallel NetCDF is a separate defelopment and as such does not depend on the serial NetCDF and or HDF5.

Instructions how to use these data libraries in user codes are described below.

Serial HDF5 & NetCDF libraries

Serial data libraries ony have dependency on the compiler. We provide the HDF5 and NetCDF libraries with the gcc, Intel and NVHPC compilers. To set the environment, load the compiler module, followed by the HDF5 and/or NetCDF modules. For example, for the gcc compiler:

module load gcc/8.5.0
module load netcdf-c netcdf-fortran

The modules provide environment variables that specify the path to these libraries. These can then be used in the compile and link flags for user codes that require these libraries:

export CFLAGS="-I$NETCDF_C_ROOT/include"
export FFLAGS="-I$NETCDF_FORTRAN_ROOT/include"
export LDFLAGS="-Wl,-rpath=$NETCDF_FORTRAN_ROOT/lib -L$NETCDF_FORTRAN_ROOT/lib -Wl,-rpath=$NETCDF_C_ROOT/lib
-L$NETCDF_C_ROOT/lib -Wl,-rpath=$HDF5_ROOT/lib -L$HDF5_ROOT/lib -lnetcdff -lnetcdf -lhdf5"

Some programs, especially older atmospheric sciences codes, expect the separate netcdf-c, netcdf-fortran and hdf5 libraries to be present at the same location. For these we have created a single directory that combines these packages into one location. This combined library directory will be updated occasionally, less often than the separate libraries. We provide these directories for the following compilers:

gcc/8.5.0/uufs/chpc.utah.edu/sys/spack/linux-rocky8-nehalem/gcc-8.5.0/netcdf
intel-oneapi-compilers/2021.4.0 /uufs/chpc.utah.edu/sys/spack/linux-rocky8-nehalem/intel-2021.4.0/netcdf
nvhpc/21.5/uufs/chpc.utah.edu/sys/spack/linux-rocky8-nehalem/nvhpc-21.5/netcdf

The compiler flags using one of these directories would then be set as:

module load gcc/8.5.0
export NETCDF=/uufs/chpc.utah.edu/sys/spack/linux-rocky8-nehalem/gcc-8.5.0/netcdf
export CFLAGS="-I$NETCDF/include"
export FFLAGS="-I$NETCDF/include"
export LDFLAGS="-Wl,-rpath=$NETCDF/bin -L$NETCDF/bin -lnetcdff -lnetcdf -lhdf5"

If you need a different compiler/MPI combination, please, let us know.

Parallel NetCDF and HDF5

The HDF5 library built with MPI, and a separate Parallel NetCDF library are built for the gcc and Intel compilers with either Intel MPI or OpenMPI.

  compiler MPI module
HDF5 gcc/8.5.0, intel-oneapi-compiler/2021.4.0 openmpi/4.1.1, or intel-oneapi-mpi/2021.4.0 hdf5
Parallel NetCDF gcc/8.5.0, intel-oneapi-compiler/2021.4.0 openmpi/4.1.1, or intel-oneapi-mpi/2021.4.0 parallel-netcdf

 

For example, to use Parallel NetCDF with gcc and OpenMPI, we would use the following modules and compiler/linker flags:

module load gcc/8.5.0 openmpi/4.1.1 parallel-netcdf
export CFLAGS="-I$PARALLEL_NETCDF_ROOT/include"
export FFLAGS="-I$PARALLEL_NETCDF_ROOT/include"
export LDFLAGS="-Wl,-rpath=$PARALLEL_NETCDF_ROOT/bin -L$PARALLEL_NETCDF_ROOT/bin -lpnetcdf"

Similarly, for HDF5:

module load gcc/8.5.0 openmpi/4.1.1 hdf5
export CFLAGS="-I$HDF5_ROOT/include"
export FFLAGS="-I$HDF5_ROOT/include"
export LDFLAGS="-Wl,-rpath=$HDF5_ROOT/bin -L$HDF5_ROOT/bin -lpnetcdf"

For some parallel NetCDF/HDF5 libraries, we have also created a single directory that combines these packages into one location. These combined library directories will be updated occasionally, less often than the separate libraries. We provide these directories for the following compilers:

intel-oneapi-compilers/2021.4.0 intel-oneapi-mpi/2021.1.1/uufs/chpc.utah.edu/sys/spack/linux-rocky8-nehalem/intel-2021.4.0/netcdf-impi
intel-oneapi-compilers/2021.4.0 openmpi/4.1.1/uufs/chpc.utah.edu/sys/spack/linux-rocky8-nehalem/intel-2021.4.0/netcdf-ompi

If you need a different compiler/MPI combination, please, let us know.

Last Updated: 7/5/23