How to build NetCDF and NetCDF for Fortran with Arm Compiler for HPC.

NetCDF is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. For more information on NetCDF, see the NetCDF website.

For the purposes of this build, the following components are used:

 Component Form
 NetCDF  Version 4.7.0
 NetCDF for Fortran  Version 4.4.5
 HDF5  Version 1.10.5
 Arm Compiler for HPC
 Version 19.2
 Open MPI  Version 4.0.1
 (Optional) Parallel NetCDF  Version 1.9.0
 Operating system  RHEL 7.5
 Cavium ThunderX2

Recipes for other versions of the application are available in the GitLab Packages Wiki.

Before you begin

Procedure to build NetCDF

  1. Create build and install locations, and set them using the environment variables build_dir and install_dir, for example:

    mkdir netcdf_build
    mkdir netcdf_install
    export build_dir=/path/to/netcdf_build
    export install_dir=/path/to/netcdf_install

    replacing /path/to/ with the path to the new directories.

  2. Specify the location of HDF5 and (optionally) Parallel NetCDF installations by setting hdf_dir, and (optionally) pnetcdf_dir, such as:

    export hdf_dir=/path/to/hdf5_install
    export pnetcdf_dir=/path/to/pnetcdf_install

    replacing /path/to/hdf_install and /path/to/pnetcdf_install  with the paths to your HDF5 and (optionally) Parallel NetCDF installations, respectively.

  3. Download and unpack NetCDF:

    cd $build_dir
    wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.7.0.tar.gz
    tar -zxvf netcdf-4.7.0.tar.gz
    cd netcdf-4.7.0
  4. To build for Arm AArch64, you require up-to-date versions of config.guess and config.sub.

    To obtain up-to-date versions, use:

    wget 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' -O bin/config.guess
    wget 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' -O bin/config.sub
  5. Set the compiler environment variables:

    export CC=mpicc
    export CXX=mpicxx
    export F77=mpif77
    export FC=mpif90
    export MPICC=mpicc
    export MPIFC=mpifc
    export MPICXX=mpicxx
  6. Configure the build by passing the location of the HDF5 and (optionally) Parallel NetCDF include and lib directories through CPPFLAGS and LDFLAGS, respectively:

     ./configure --prefix=$install_dir CPPFLAGS="-I$hdf5_dir/include -I$pnetcdf_dir/include -I$zlib_dir/include" CFLAGS="-DHAVE_STRDUP -O3 -mcpu=native" LDFLAGS="-L$hdf5_dir/lib -L$pnetcdf_dir/lib -L$zlib_dir/lib" --enable-pnetcdf  --enable-parallel-tests --enable-shared --enable-netcdf-4  --with-pic --disable-doxygen  

    Note: The Parallel NetCDF library and the --enable-pnetcdf flag are optional and are only required for parallel access to older NetCDF data files (pre-version 4).

  7. Make some minor changes to the default flags in libtool:

    sed -i -e 's#wl=""#wl="-Wl,"#g' libtool
    sed -i -e 's#pic_flag=""#pic_flag=" -fPIC -DPIC"#g' libtool
  8. Build and install NetCDF, using:

    make -j
    make check
    make install

Procedure to build NetCDF for Fortran

  1. Set the location of the the NetCDF C library installation directory as NCDIR, for example:

    export NCDIR=/path/to/netcdf_install

    replacing /path/to/netcdf_install with the path to your NetCDF C installation.

    Note: This should be the directory used for the NetCDF installation completed in the Procedure to build NetCDF section.

  2. Create a build directory for NetCDF Fortran library, for example, called fnetcdf_build. Then set the install location for the NetCDF Fortran library to that of the NetCDF C library directory, using the environment variable NFDIR, for example:

    mkdir fnetcdf_build
    export build_dir=/path/to/fnetcdf_build
    export NFDIR=NCDIR
  3. Download and unpack NetCDF for Fortran:

    cd $build_dir
    wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-fortran-4.4.5.tar.gz
    tar -zxvf netcdf-fortran-4.4.5.tar.gz
  4. Set the compiler environment variables:

    export CC=armclang
    export CXX=armclang++
    export F77=armflang
    export FC=armflang
    export MPICC=mpicc
    export MPIFC=mpifort
    export MPICXX=mpicxx
  5. Change to the source directory and configure the build by passing the location of the HDF5 and NetCDF C library include and lib directories, using:

    export NFDIR=$NCDIR
    export CFLAGS="-L$hdf5_dir/lib -I$hdf5_dir/include -L$NCDIR/lib -I$NCDIR/include"
    export CXXFLAGS="-L$hdf5_dir/lib -I$hdf5_dir/include -L$NCDIR/lib -I$NCDIR/include"
    export FCFLAGS="-L$hdf5_dir/lib -I$hdf5_dir/include -L$NCDIR/lib -I$NCDIR/include"
    export CPPFLAGS="-I${hdf5_dir}/include -I${NCDIR}/include"
    export LDFLAGS="-L${hdf5_dir}/lib -L${NCDIR}/lib"
    export LIBS="-lnetcdf -lhdf5_hl -lhdf5 -lz -lcurl"
    # Need netcdf and hdf5 libs in library path to allow configure tests to succeed
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NCDIR/lib:$hdf5_dir/lib
    cd $build_dir/netcdf-fortran-4.4.5
    ./configure  --prefix=${NFDIR} --enable-shared --with-pic --disable-doxygen  
  6. Modify libtool to work with Arm Compiler, using:

    sed -i -e 's#wl=""#wl="-Wl,"#g' libtool
    sed -i -e 's#pic_flag=""#pic_flag=" -fPIC -DPIC"#g' libtool
  7. Build and install NetCDF for Fortran, using:

    make -j
    make check
    make install