Netcdf4 with Intel oneAPI

22 May 2024, Han Soo Lee

Netcdf4 C and Fortran compilation with Intel oneAPI DCP++/C++ on Rocky Linux 8.7

We have tested and built the Netcdf4 with Intel oneAPI on HPC with Rocky Linux 8.7 from scratch. You must have the Intel oneAPI installed on your system beforehand.

Environmental variables in ~/.bashrc


# Intel oneAPI 
export OPTIM="-O3"
export CC=icc
export CXX=icpc
export CFLAGS=${OPTIM}
export CXXFLAGS=${OPTIM}
export F77=ifort
export FC=ifort
export F90=ifort
export FFLAGS=${OPTIM}
export CPP="icc -E"
export CXXCPP="icpc -E"

1. Install necessary library

We installed the necessary libraries under ~/Downloads/, such as CUnit, UDUNITS, SZIP for HDF5, zlib for HDF5, HDF5, Curl for OPeNDAP.

In the following build_scripts, you have to modify HOME variable according to your HPC system environment. Check out the versions of the library carefully as well.

We used the Downloads in home directory for the process below.

CUnit

make a script, build_cunit.sh, in ~/Downloads/ as below, and run the code after changing the mode, chmod a+x build_cunit.sh


#!/bin/bash
HOME="/home/hslee/Downloads/wrf_libs_intel"

# build_cunit.sh
version_cunit="2.1-2"

wget http://downloads.sourceforge.net/project/cunit/CUnit/${version_cunit}/CUnit-${version_cunit}-src.tar.bz2
tar xf CUnit-${version_cunit}-src.tar.bz2
cd CUnit-${version_cunit}
./configure --prefix=${HOME}/CUnit/${version_cunit}
make
make install

then


./build_cunit.sh

add the following in ~/.bashrc, then log-in again. You have to change “/home/hslee/Downloads/wrf_libs_intel” to your environment.


# CUnit
export LD_LIBRARY_PATH="/home/hslee/Downloads/wrf_libs_intel/CUnit/2.1-2/lib:$LD_LIBRARY_PATH"

UDUNITS

make a script, build_udunits.sh, and run the script in the same way as above.


#!/bin/bash
HOME="/home/hslee/Downloads/wrf_libs_intel"

# build_udunits.sh
version_udunits="2.2.28"
#wget https://artifacts.unidata.ucar.edu/repository/downloads-udunits/udunits-${version_udunits}.tar.gz
wget https://downloads.unidata.ucar.edu/udunits/${version_udunits}/udunits-${version_udunits}.tar.gz
tar xf udunits-${version_udunits}.tar.gz
cd udunits-${version_udunits}
./configure --prefix="${HOME}/udunits/${version_udunits}"
make
make check
make install
make clean

add the following in ~/.bashrc, then log-in again. You have to change “/home/hslee/Downloads/wrf_libs_intel” to your environment.


# UDUNITS
export UDUNITS2_XML_PATH="/home/hslee/Downloads/wrf_libs_intel/udunits/2.2.28/share/udunits/udunits2.xml"
export PATH="/home/hslee/Downloads/wrf_libs_intel/udunits/2.2.28/bin:$PATH"

SZIP

make a script, build_szip.sh, and run the script in the same way as above.


#!/bin/bash
HOME="/home/hslee/Downloads/wrf_libs_intel"

# build_szip.sh
version_szip="2.1.1"
wget https://support.hdfgroup.org/ftp/lib-external/szip/${version_szip}/src/szip-${version_szip}.tar.gz
tar xf szip-${version_szip}.tar.gz
cd szip-${version_szip}
./configure --prefix=${HOME}/szip/${version_szip}
make
make check
make install

zlib

make a script, build_zlib.sh, and run the script in the same way as above.


#!/bin/bash
HOME="/home/hslee/Downloads/wrf_libs_intel"

# build_zlib.sh for building zlib using Intel compiler
version_zlib="1.3.1"
wget https://zlib.net/zlib-${version_zlib}.tar.gz
tar xf zlib-${version_zlib}.tar.gz
cd zlib-${version_zlib}
./configure --prefix=${HOME}/zlib/${version_zlib}
make
make install

HDF5

make a script, build_hdf5.sh, and run the script in the same way as above.


#!/bin/bash
HOME="/home/hslee/Downloads/wrf_libs_intel"

# build_hdf5.sh
version_hdf5="1.12.0"
version_zlib="1.3.1"
version_szip="2.1.1"
tar xf hdf5-${version_hdf5}.tar.gz
cd hdf5-${version_hdf5}
./configure --prefix=${HOME}/hdf5/${version_hdf5} --with-zlib=${HOME}/zlib/${version_zlib}/include,${HOME}/zlib/${version_zlib}/lib --with-szlib=${HOME}/szip/${version_szip}/lib --enable-hl --enable-fortran --with-default-api-version=v18

make
## make check takes such a long time for completion. It sometime looks like freezing
make check
make install
make check-install

Curl

make a script, build_curl.sh, and run the script in the same way as above.


#!/bin/bash
HOME="/home/hslee/Downloads/wrf_libs_intel"

# build_curl.sh for building Curl using Intel compiler for OPeNDAP
version_curl="7.76.1"
wget https://curl.se/download/curl-${version_curl}.tar.gz
tar xf curl-${version_curl}.tar.gz
cd curl-${version_curl}/

export OPTIM="-O3 -mcmodel=large -fPIC"
# "-mcmodel=large" option is necessary
export CC=icc
export CXX=icpc
export CPP="icc -E -mcmodel=large"
export CXXCPP="icpc -E -mcmodel=large"
export CFLAGS="${OPTIM}"
export CXXFLAGS="${OPTIM}"

./configure --prefix=${HOME}/curl/${version_curl}
make
# You may ignore the "make test"
# make test
make install

2. Install Netcdf4 C (v.4.8.1) and Fortran (v.4.6.1)

Netcdf4 C (v.4.8.1)

make a script, build_netcdf-c.sh, and run the script in the same way as above.


#!/bin/bash
HOME="/home/hslee/Downloads/wrf_libs_intel"

# build_netcdf-c.sh
version_netcdf4="4.8.1"
version_hdf5="1.12.0"
version_zlib="1.3.1"
version_curl="7.76.1"
#wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-${version_netcdf4}.tar.gz
wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v${version_netcdf4}.tar.gz
#tar xf netcdf-c-${version_netcdf4}.tar.gz
tar xf v${version_netcdf4}.tar.gz
cd netcdf-c-${version_netcdf4}/
#
export LDFLAGS="-L${HOME}/hdf5/${version_hdf5}/lib -L${HOME}/zlib/${version_zlib}/lib -L${HOME}/curl/${version_curl}/lib"
export CPPFLAGS="-I${HOME}/hdf5/${version_hdf5}/include -I${HOME}/zlib/${version_zlib}/include ${LDFLAGS} -I${HOME}/curl/${version_curl}/include"
export OPTIM="-O3 -mcmodel=large -fPIC ${LDFLAGS}"
#
export CC=icc
export CXX=icpc
export CPP="icc -E -mcmodel=large"
export CXXCPP="icpc -E -mcmodel=large"
#
export CFLAGS="${OPTIM}"
export CXXFLAGS="${OPTIM}"
#
./configure --prefix=${HOME}/netcdf4-intel --enable-large-file-tests --with-pic
make
make check
make install

Netcdf4 Fortran (v.4.6.1)

make a script, build_netcdf-fortran.sh, and run the script in the same way as above.


#!/bin/bash
HOME="/home/hslee/Downloads/wrf_libs_intel"

# build_netcdf-fortran.sh
version_netcdf4_fortran="4.6.1"
version_netcdf4="4.8.1"
#wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-${version_netcdf4_fortran}.tar.gz
wget https://downloads.unidata.ucar.edu/netcdf-fortran/${version_netcdf4_fortran}/netcdf-fortran-${version_netcdf4_fortran}.tar.gz
tar xf netcdf-fortran-${version_netcdf4_fortran}.tar.gz
cd netcdf-fortran-${version_netcdf4_fortran}
export NCDIR="${HOME}/netcdf4-intel"
export LD_LIBRARY_PATH="${NCDIR}/lib:${LD_LIBRARY_PATH}"
export NFDIR="${HOME}/netcdf4-intel"
export CPPFLAGS="-I${NCDIR}/include"
export LDFLAGS="-L${NCDIR}/lib"
export OPTIM="-O3 -mcmodel=large -fPIC ${LDFLAGS}"
export CC=icc
#export CXX=icpc
export FC=ifort
export F77=ifort
export F90=ifort
export CPP="icc -E -mcmodel=large"
export CXXCPP="icpc -E -mcmodel=large"
export CPPFLAGS="-DNDEBUG -DpgiFortran ${LDFLAGS} $CPPFLAGS"
export CFLAGS="${OPTIM}"
#export CXXFLAGS="${OPTIM}"
export FCFLAGS="${OPTIM}"
export F77FLAGS="${OPTIM}"
export F90FLAGS="${OPTIM}"
#
./configure --prefix=${NFDIR} --enable-large-file-tests --with-pic
make
make check
make install

add the following in ~/.bashrc, then log in again. You must change “/home/hslee/Downloads/wrf_libs_intel” to your environment.


export PATH="/home/hslee/Downloads/wrf_libs_intel/netcdf4-intel/bin:$PATH"
export LD_LIBRARY_PATH="/home/hslee/Downloads/wrf_libs_intel/netcdf4-intel/lib:$LD_LIBRARY_PATH"

If you want to compile the WRF with Intel oneAPI, continue this instruction, WRF compilation with Intel oneAPI.