Announcement

Collapse
No announcement yet.

NetCDF library with Intel Compiler Suite

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    NetCDF library with Intel Compiler Suite

    Hi All,
    this is maybe a bit specific, but I spent some time figuring this out and I want to spare others the effort.
    So for everyone who is using the NetCDF data format and would like to take advantage of the optimized Intel compilers (C/C++ and Fortran), which are free for personal use on Linux, here is how I did it.

    These instructions are for NetCDF 4.1.3 with HDF-5 1.8.6 and zlib 1.2.5, which we will also install here. I used the Intel Compiler Suite version Composer XE 2011.4.191.

    I basically followed the quick build instructions here: http://mailman.unidata.ucar.edu/soft...k-Instructions and here: http://software.intel.com/en-us/arti...l-compilers/#6. The former does not include instructions for Intel compilers; the latter is for Intel compilers, but unfortunately already outdated. Hence this post.

    First install zlib with the following compiler settings (very fast). For some strange reason the Intel compiler only builds the static library, so I built the shared lib first using GCC (default settings) and then built (and overwrote) the static lib with the script below.
    Code:
    #!/bin/bash
    # script to building zlib-1.2.5 with the Intel Compiler Suite
    
    ## load compiler settings
    # Intel(R) Composer XE 2011 Update 4 for Linux
    source /opt/intel/composerxe-2011.4.191/bin/compilervars.sh intel64 # compiler suite
    source /opt/intel/mkl/bin/mklvars.sh intel64 # math kernel library
    
    # set environment variables
    export CC=icc
    export CPP=icpc
    export CFLAGS='-O3 -xHost -fPIC'
    # Note: the Intel compiler can for unknown reasons only build the
    # static library (libz.a). I built and installed the shared 
    # library with GCC first.
    #export SFLAGS='-O3 -xHost -fPIC -DPIC -shared'
    #export LDSHARED='-lpthread'
    
    ## build static library
    # configure
    ./configure
    # build and test build
    make
    
    # install library if test successful
    make check && make install
    Then you have to install the HDF-5 library, which takes quite long but is pretty straight forward.
    The following script has all the flags and configure options I used:
    Code:
    #!/bin/bash
    # script to building HDF-1.8.6 with the Intel Compiler Suite
    
    ## load compiler settings
    # Intel(R) Composer XE 2011 Update 4 for Linux
    source /opt/intel/composerxe-2011.4.191/bin/compilervars.sh intel64 # compiler suite
    source /opt/intel/mkl/bin/mklvars.sh intel64 # math kernel library
    
    # set environment variables
    export CC=icc
    export F9X=ifort
    export CXX=icpc 
    export CFLAGS='-O3 -xHost'
    export FCFLAGS='-O3 -xHost'
    export CXXFLAGS='-O3 -xHost'
    
    ## build static library
    # configure (with Fortran and C++ libraries)
    ./configure --prefix=/usr/local --enable-fortran --enable-cxx 
    # build
    make
    
    # install library if test successful
    make check && make install
    After zlib and HDF-5 are installed you can proceed with the NetCDF library. If you want OPeNDAP support, make sure some version of libcurl is installed on your system (package libcurl3 on ubuntu; you can use the package manager to install it).
    I used the script below to build and install NetCDF. There is again a catch with the shared libraries: you need to build the shared libraries first with
    Code:
    FLAGS='-O3 -xHost'
    and then the static libraries with
    Code:
    FLAGS='-O3 -xHost -no-prec-div -static'
    . Adapt the configure-options to you needs (I chose /usr/local/ as the installation directory; the default is where you built it...).
    Code:
    #!/bin/bash
    # script to building netcdf-4.1.3 with the Intel Compiler Suite
    # (requires zlib-1.2.5 and hdf-1.8.6 and some version of libcurl)
    
    ## load compiler settings
    # Intel(R) Composer XE 2011 Update 4 for Linux
    source /opt/intel/composerxe-2011.4.191/bin/compilervars.sh intel64 # compiler suite
    source /opt/intel/mkl/bin/mklvars.sh intel64 # math kernel library
    
    # set environment variables
    FLAGS='-O3 -xHost -no-prec-div -static' # -ipo
    # Note: I believe the shared libraries have to be built with '-O3 -xHost' only
    # while the static libs can be built with '-O3 -xHost -no-prec-div -static'
    # Use two iterations to install shared and static libraries separately
    # C/C++
    export CC=icc
    export CXX=icpc
    export CFLAGS=$FLAGS
    export CXXFLAGS=$FLAGS
    # Fortran
    export F9X=ifort 
    export F77=ifort
    export FC=ifort
    export F90=ifort
    export FFLAGS=$FLAGS
    export FCFLAGS=$FLAGS
    # Pre-Processor
    export CPP='icc -E'
    export CXXCPP='icpc -E'
    
    # zlib and hdf5 libraries
    export CPPFLAGS=-I/usr/local/include 
    export LDFLAGS=-L/usr/local/lib
    export LD_LIBRARY_PATH=/usr/local:$LD_LIBRARY_PATH
    
    ## build static library
    # configure
    ./configure --prefix=/usr/local --enable-fortran --enable-cxx --enable-shared --enable-static --enable-dap --with-udunits --with-libcf
    # build
    make
    
    # install library if test successful
    make check && make install
    With this you should be able to install and use the NetCDF library. Theoretically you can just run these scripts as root and it should work; you only have to edit the settings for static and shared libs (and hence run the netcdf script twice). I hope this saves someone a bit of work... if anyone has comments or has a better way of dealing with these static/shared lib issue, please post a comment.
    I'm not an expert with Intel compilers and would like to learn more myself.
    (Btw. I tried to post on the Intel forums but the registration did not work.)

    Chopstick
Working...
X