Building NetCDF-Fortran using Intel compiler on Ubuntu 18.04 on WSL

Table of Content

Prerequisites

It is assumed that Ubuntu 18.04LTS is installed on WSL on Windows 10 Pro; Intel Parallel Studio XE 2020 Composer Edition is installed. Referring to this article, libraries other than NetCDF-Fortran are easily installed with apt (compiled with GNU).

Install GNU libraries with apt

HDF5 (referenced here) and GNU version of NetCDF-4 (libnetcdf-dev) and NetCDF-Fortran (libnetcdff-dev, refer to here) are installed as follows. libnetcdff-dev should not be installed as building Intel version failed.

$ sudo apt update
$ sudo apt install hdf5-tools hdf5-helpers libhdf5-dev libhdf5-doc libhdf5-serial-dev
$ sudo apt install libnetcdf-dev

Check whether the installation was successful.

$  nc-config --all

This netCDF 4.6.0 has been built with the following features:
...

The version is as of May 26, 2020. If it looks like this, it is successful.

Building NetCDF-Fortran with Intel compiler

Download the source code of NetCDF-Fortran from here. As of May 26, 2020, it is netcdf-fortran-4.5.2.tar.gz. By default on Windows, it will be downloaded to /mnt/c/Users/username/Downloads/ with replacing "username" with your own.

$ cd /mnt/c/Users/username/Downloads/
$ tar xf netcdf-fortran-4.5.2.tar.gz
$ cd netcdf-fortran-4.5.2/

Create a text file config-intel.sh with the following contents in the same directory using an editor. The version on the bottom line should match that of the downloaded source code.

export CDFROOT="/usr"
export LD_LIBRARY_PATH="${CDFROOT}/lib:${LD_LIBRARY_PATH}"
export LDFLAGS="-L${CDFROOT}/lib -I${CDFROOT}/include":
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}"
#
export CFLAGS=" ${OPTIM}"
export CXXFLAGS=" ${OPTIM}"
export FCFLAGS=" ${OPTIM}"
export F77FLAGS=" ${OPTIM}"
export F90FLAGS=" ${OPTIM}"
#
./configure --prefix=/usr/local/netcdf-ifort/4.5.2 --enable-large-file-tests --with-pic

Append the execution attribute to config-intel.sh and execute as follows:

$ chmod a+x config-intel.sh
$ ./config-intel.sh
$ make
$ make check
$ sudo make install

Add PATH to ~/.bashrc as shown below:

export PATH="/usr/local/netcdf-ifort/4.5.2/bin:$PATH"

Check whether the installation was successful.

$ nf-config --all

This netCDF-Fortran 4.5.2 has been built with the following features:

  --cc        -> icc
  --cflags    ->  -I/usr/local/netcdf-ifort/4.5.2/include -DNDEBUG -DpgiFortran -L/usr/lib -I/usr/include

  --fc        -> ifort
  --fflags    -> -I/usr/local/netcdf-ifort/4.5.2/include
  --flibs     -> -L/usr/local/netcdf-ifort/4.5.2/lib -lnetcdff -L/usr/lib -I/usr/include -lnetcdf -lnetcdf -lm
  --has-f90   ->
  --has-f03   -> yes

  --has-nc2   -> yes
  --has-nc4   -> yes

  --prefix    -> /usr/local/netcdf-ifort/4.5.2
  --includedir-> /usr/local/netcdf-ifort/4.5.2/include
  --version   -> netCDF-Fortran 4.5.2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.