Chip Freitag

9/16/2009

 

A very common question we receive through the ACML support channels is how to use ACML with different versions of GCC/GFORTRAN. Since the ACML team does not have the resources to provide a current version of ACML built with every possible GCC version, we have to choose which GCC version to build with. In general the choices are driven by which GCC is available through the common distributions, but it can also be driven by features provided by those compilers.

Many systems have GCC 4.1.2 as the default. Recent ACML versions are built with newer compilers, since 4.1.2 did not support OpenMP.

A primary incompatibility is the version of libgfortran required by the ACML library. Newer versions require libgfortran.so.3.   GCC4.1.2 included libgfortran.so.1. It might be possible to copy a recent libgfortran.so.3 from another machine, but this is not a recommended solution. A better solution is to install or build a new GCC/GFORTRAN.

Not every user has the luxury of being able to install a new compiler on the computer being used. But there is a relatively simple way to build a private copy of a GCC version when it is needed to resolve compatibility issues for ACML and other applications. These private c90opies can be built and installed in a user directory, and kept isolated from the system libraries.

Here are the steps for building GCC versions in ways that are known to work properly for ACML. These steps are for a 64-bit build.

  1. Download (mirrors listed at gcc.gnu.org) the new gcc package and extract to a local directory. For instance if the home directory is /home/acmluser, it will extract to
    /home/acmluser/gcc-4.4.1
  2. build/install mpfr
    GFORTRAN requires mpfr. You can skip this step and try to just build the compiler. If libmpfr is not there, the compiler configure step will fail. In that case, come back to this step.

    The mpfr source package can be downloaded from www.mpfr.org. The build steps that worked for me were

    ./configure
    make
    make install

    Of course the install step requires root privilege if installing into the default locations. the –prefix options can specify different install locations.

    On some REDHAT systems, I ran into a compatibility issue with the default libmpfr.a.

    I had to remove the existing file from /usr/lib/libmpfr.a and then ensure LD_LIBRARY_PATH and LD_RUN_PATH included paths to the location of the new mpfr, usually /usr/local/lib.

  3. Create build and install directories for the new compiler. These choices are arbitrary and can be anything you want. Examples would be something like:
    /home/acmluser/build441 and /home/acmluser/gcc441
  4. cd to /home/acmluser/build441
    There is nothing in this directory yet. There soon will be.
  5. Build GCC with gfortran options. You can add other options if needed, but I never found the need to test ACML with ada,
    1. configure with
      /home/acmluser/gcc-4.4.1/configure –prefix=/home/acmluser/gcc441 –enable-shared –enable-languages=c,c++,fortran
      The –prefix option is telling the configure step that the final destination will be in your gcc441 directory. You execute this command in the build directory, and that will cause all the temporary files to be placed in the build directory.
      After this step, the gcc441 directory will still be empty.
    2. make
      It’s that simple. This will take a while, 20 minutes to an hour.
      After this step, the gcc441 directory will still be empty.
    3. make install
      Now the gcc441 directory will have files in it.
  6. Create a set environment script file (with +x permissions) in /home/acmluser/gcc441. This file could be anywhere, but that’s convenient location.
    Here is an example of the contents.

    --------
    #!/bin/bash
    #
    # Set GCC environment variables.
    
    GCCPATH=/home/acmluser/gcc441
    GCCVER=4.4.1
    GCCARCH=x86_64-unknown-linux-gnu
    if [ -z "${PATH}" ]
    then
    export PATH=$GCCPATH/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin
    else
    export PATH=$GCCPATH/bin:${PATH}
    fi
    if [ -z "${LIBRARY_PATH}" ]
    then
    export LIBRARY_PATH=$GCCPATH/lib64:$GCCPATH/lib/gcc/x86_64-unknown-linux-gnu           /$GCCVER
    else
    export LIBRARY_PATH=$GCCPATH/lib64:$GCCPATH/lib/gcc/x86_64-unknown-linux-gnu           /$GCCVER:${LIBRARY_PATH}
    fi
    if [ -z "${LD_LIBRARY_PATH}" ]
    then
    export LD_LIBRARY_PATH=$GCCPATH/lib64:/usr/local/lib64
    else
    export LD_LIBRARY_PATH=$GCCPATH/lib64:${LD_LIBRARY_PATH}
    fi
    if [ -z "${LD_RUN_PATH}" ]
    then
    export LD_RUN_PATH=$LIBRARY_PATH
    else
    export LD_RUN_PATH=$LIBRARY_PATH:${LD_RUN_PATH}
    fi
    if [ -z "${MANPATH}" ]
    then
    export MANPATH=$GCCPATH/man
    else
    export MANPATH=$GCCPATH/man:$MANPATH
    fi
    if [ -z "${INFOPATH}" ]
    then
    export INFOPATH=$GCCPATH/info
    else
    export INFOPATH=$GCCPATH/info:$INFOPATH
    fi
    export CPATH=$GCCPATH/include:$GCCPATH/lib/gcc/$GCCARCH/$GCCVER/include
    export CPLUS_INCLUDE_PATH=$GCCPATH/include/c++/$GCCVER:$GCCPATH/lib/gcc/$GCCARCH/$GCCVER/include
    --------
  7. As a user, source the setenv file. Which gcc and gcc -v can be used to verify the correct compiler is being used.
  8. Now you are ready to use the new compiler. Let us know if you find this useful in your work.