Compilatore gcc e gfortran: differenze tra le versioni

Da MeteOceanWiki.
Riga 55: Riga 55:
  
  
"
 
  
  
#! /bin/bash
+
 
 +
  "#! /bin/bash
  
 
#-------------------------------------------------------------------------------
 
#-------------------------------------------------------------------------------

Versione delle 12:04, 10 mar 2017

How to install Delft3D with gfortran

1) Install all pre-requisites required (read Delft3D website)


2) compile mpich

./configure --prefix=/opt/mpich_gfor/ --enable-shared --enable-sharedlibs=gcc --enable-lib-depend F77=gfortran FC=gfortran CC=gcc CXX=g++ FCFLAGS=-fPIC CFLAGS=-fPIC CCFLAGS=-fPIC CXXFLAGS=-fPIC 2>&1 | tee c.txt make 2>&1 | tee m.txt make install 2>&1 | tee mi.txt


3) compile hdf5

LDFLAGS="-L/opt/mpich_gfor/lib64 -L/usr/local/lib" CPPFLAGS="-I/opt/mpich_gfor/include -I/usr/local/include" ./configure --prefix=/opt/hdf5_gfor --enable-shared --enable-hl --enable-fortran --enable-parallel

make make check make install

update PATH update LD_LIBRARY_PATH


4) compile netcdf

LDFLAGS="-L/opt/mpich_gfor/lib64 -L/opt/hdf5_gfor/lib64 -L/usr/local/lib" CPPFLAGS="-I/opt/mpich_gfor/include -I/opt/hdf5_gfor/include/ -I/usr/local/include" ./configure --enable-netcdf-4 --enable-dap --enable-shared --prefix=/opt/netcdf_4411_gfor

make make check make install

update PATH update LD_LIBRARY_PATH


5) compile netcdf fortran

LDFLAGS="-L/opt/mpich_gfor/lib64 -L/opt/hdf5_gfor/lib64 -L/usr/local/lib -L/opt/netcdf_4411_gfor/lib64" CPPFLAGS="-I/opt/mpich_gfor/include -I/opt/hdf5_gfor/include/ -I/usr/local/include -I/opt/netcdf_4411_gfor/include" ./configure --enable-shared --prefix=/opt/netcdf_444_fortran_gfor/

make make check make install

update PATH update LD_LIBRARY_PATH


6) compile Delft3D:

./build.sh .-gnu


This is my build.sh:



 "#! /bin/bash
  1. -------------------------------------------------------------------------------
  2. Top-Level Build Script for Delft3D Open Source Code
  3. There are command-line options to select Fortran compiler and debug or not.
  4. ToDo: Remove stripping of executables when the debug flag is set.
  5. It's even debatable whether stripping belongs in the build. I think not.
  6. ToDo: Don't preintialize the compiler, the user should do this himself
  7. so that he's aware exactly which version he's using. Besides, we can't
  8. keep up with every new compiler update. This script should be ultra-low
  9. maintanence.
  10. irv.elshoff@deltares.nl
  11. adri.mourits@deltares.nl
  12. 04 Feb 2015
  13. Copyright (C) Stichting Deltares, 2011-2013.
  14. -------------------------------------------------------------------------------
  15. WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  16. This script contains references to Deltares specific systems.
  17. Use this script as an example and modify it to fit to your system.
  18. See file README for compiling without using this script.
  19. -------------------------------------------------------------------------------
  1. This script must be executed in the directory where it resides

orgdir=`pwd` scriptdirname=`readlink \-f \$0` maindir=`dirname $scriptdirname` cd $maindir


  1. Default values

compiler= configureArgs= debug=0 noMake=0 platform='ia32' useSp=0

  1. -------------------------------------------------------------------------------

function usage {

   echo "Usage: `basename $0` <compiler> [-debug] [-make] [-64bit] [-sp] [-configure <args>] [-?]"
   echo "Compiler is one of:"
   echo "    -gnu"
   echo "    -intel10"
   echo "    -intel11.0 (-intel11)"
   echo "    -intel11.1"
   echo "    -intel12"
   echo "    -intel14 (-intel14.0.3)"
   }


  1. -------------------------------------------------------------------------------
  2. Add date time to logging info

function log {

   echo "`date +%Y%m%d.%H%M%S` :: $*"
   }


  1. -------------------------------------------------------------------------------
  2. Add a directory to an environment parameter

function addpath {

   path="$1"
   shift
   for dir in $*; do
       if [ -d $dir ]; then
           eval "export $path=\"$dir:\$$path\""
       fi
   done
   }


  1. -------------------------------------------------------------------------------
  2. Identify which program is used

function witch {

   w=`which $1`
   (
       cd `dirname $w`
       /bin/pwd
   )
   }


  1. ===============================================================================
  2. Process command-line arguments

while [ $# -gt 0 ]; do

   case $1 in
       -64bit)
           platform='intel64'
           ;;
       -c|-configure)
           shift
           configureArgs="$1"
           ;;
       -d|-debug)
           debug=1
           ;;
       -gnu)
           compiler='gnu'
           ;;
       -intel10)
           compiler='intel10'
           ;;
       -intel11.0|-intel11)
           compiler='intel11.0'
           ;;
       -intel11.1)
           compiler='intel11.1'
           ;;
       -intel12)
           compiler='intel12'
           ;;
       -intel14|-intel14.0.3)
           compiler='intel14'
           ;;
       -m|-make)
           noMake=1
           ;;
       -sp)
           useSp=1
           ;;
       -?)
           usage
           cd $orgdir
           exit 0
           ;;
       *)
           usage
           cd $orgdir
           exit 1
           ;;
   esac
   shift

done

if [ "$compiler" == ]; then

   echo "You must specify a compiler"
   usage
   cd $orgdir
   exit 1

fi

mkdir -p logs

if [ "$BASH_ENV" != ]; then

   echo 'Warning: Unsetting BASH_ENV'
   unset BASH_ENV

fi


  1. ===============================================================================
  2. Initialize Fortran compiler

case $compiler in

   gnu)
       ifortInit=""
       iccInit=""
  1. addpath PATH /opt/gcc/bin

addpath PATH /usr/bin

  1. addpath LD_LIBRARY_PATH /opt/gcc/lib /opt/gcc/lib64

addpath LD_LIBRARY_PATH /usr/lib64

       echo "Using GNU compilers in `witch gfortran`"
       ;;
   intel14)
       ifortInit=". /opt/intel/composer_xe_2013_sp1.3.174/bin/compilervars.sh $platform"
       iccInit=""
       echo "Using Intel 14.0.3 Fortran ($platform) compiler"
       ;;
   intel12)
       ifortInit=". /opt/intel/bin/ifortvars.sh $platform"
       iccInit=""
       echo "Using Intel 12 Fortran ($platform) compiler"
       ;;
   intel11.1)
       if [ "$platform" == 'intel64' ]; then
           if [ -d /opt/intel/Compiler/11.1/072/bin/intel64 ]; then
               ifortInit=". /opt/intel/Compiler/11.1/072/bin/intel64/ifortvars_intel64.sh $platform"
               iccInit=""
               idbInit=". /opt/intel/Compiler/11.1/072/bin/intel64/idbvars.sh"
               echo "Using Intel 11.1 Fortran ($platform) compiler"
           fi
       else
           if [ -d /opt/intel/Compiler/11.1/072 ]; then
               ifortInit=". /opt/intel/Compiler/11.1/072/bin/ifortvars.sh $platform"
               iccInit=""
               idbInit=". /opt/intel/Compiler/11.1/072/bin/$platform/idbvars.sh"
               echo "Using Intel 11.1 Fortran ($platform) compiler"
           fi
       fi
       ;;
   intel11.0)
       if [ -d /opt/intel/Compiler/11.0/081 ]; then
           ifortInit=". /opt/intel/Compiler/11.0/081/bin/ifortvars.sh $platform"
           idbInit=". /opt/intel/Compiler/11.0/081/bin/$platform/idbvars.sh"
           echo "Using Intel 11.0 Fortran ($platform) compiler"
           iccInit=". /opt/intel/Compiler/11.0/081/bin/iccvars.sh $platform"
           echo "Using Intel 11.0 C ($platform) compiler"
       fi
       ;;
   intel10)
       ifortInit='. /opt/intel/fc/10/bin/ifortvars.sh'
       iccInit=""
       idbInit='. /opt/intel/idb/10/bin/idbvars.sh'
       echo "Using Intel 10 Fortran compiler (DEPRECATED!)"
       ;;
   *)
       ifortInit='/bin/true'
       echo "Using default Linux Fortran compiler"
       iccInit=""
       ;;

esac

if [ "$ifortInit" != ]; then

   eval $ifortInit
   if [ $? -ne 0 ]; then
       echo 'Initialization of the Fortran compiler fails!'
       cd $orgdir
       exit 1
   fi

fi

if [ "$iccInit" != ]; then

   eval $iccInit
   if [ $? -ne 0 ]; then
       echo 'Initialization of the C compiler fails!'
       cd $orgdir
       exit 1
   fi

fi


  1. ===============================================================================
  2. Use the correct Autotools
  1. When the autotools are not installed in the default location,
  2. point to them explicitly
  1. addpath PATH \
  2. /opt/automake/bin \
  3. /opt/autoconf/bin \
  4. /opt/libtool/bin


  1. ===============================================================================
  2. Additional library settings
  1. ---------------------
  2. mpich2

if [ "$compiler" = 'gnu' ]; then

  1. addpath PATH /opt/mpich2-1.4.1-gcc-4.6.2/bin
   addpath PATH /opt/mpich_gfor/bin
  1. export MPI_INCLUDE=/opt/mpich2-1.4.1-gcc-4.6.2/include
   export MPI_INCLUDE=/opt/mpich_gfor/include
  1. export MPILIBS_ADDITIONAL="-L/opt/mpich2-1.4.1-gcc-4.6.2/lib -lfmpich -lmpich -lmpl"
   export MPILIBS_ADDITIONAL="-L/opt/mpich_gfor/lib64 -lfmpich -lmpich -lmpl"
   # export MPILIBS_ADDITIONAL=" "
  1. export MPIFC=/opt/mpich2-1.4.1-gcc-4.6.2/bin/mpif90
   export MPIFC=/opt/mpich_gfor/bin/mpif90  

else

   # Intel compilers
   addpath PATH /opt/mpich2-1.0.8-intel64/bin
   export MPI_INCLUDE=/opt/mpich2-1.0.8-intel64-PIC/include
   export MPILIBS_ADDITIONAL="-L/opt/mpich2-1.0.8-intel64-PIC/lib -lfmpich -lmpich"
   if [ "$platform" = 'intel64' ]; then
       export MPIFC=/opt/mpich2-1.0.8-intel64-PIC/bin/mpif90  
   fi

fi


  1. ---------------------
  2. Additional compile flags

if [ "$compiler" = 'gnu' ]; then

   fflags=

else

   # Intel compilers
   fflags='-threads'

fi


  1. ---------------------
  2. Additional link flags/libraries

if [ "$compiler" = 'gnu' ]; then

   export LDFLAGSMT_ADDITIONAL=" "

else

   # Intel compilers
   export LDFLAGSMT_ADDITIONAL="-lifcoremt"

fi

  1. ---------------------
  2. netcdf
  3. export NETCDFROOT=/p/delft3d/opt/netcdf-4.1.3mt/intel11.1
export NETCDFROOT=/opt/netcdf_444_fortran_gfor #/opt/netcdf_4411_gfor
  1. export PKG_CONFIG_PATH=$NETCDFROOT/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=$NETCDFROOT/lib64/pkgconfig:$PKG_CONFIG_PATH
  1. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NETCDFROOT/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NETCDFROOT/lib64:/opt/netcdf_4411_gfor/lib64


  1. ===============================================================================

echo "Current settings:" echo "export ACLOCAL=\"$ACLOCAL\"" echo "export AUTOMAKE=\"$AUTOMAKE\"" echo "export AUTOHEADER=\"$AUTOHEADER\"" echo "export AUTOCONF=\"$AUTOCONF\"" echo "export AUTORECONF_FLAGS=\"$AUTORECONF_FLAGS\"" echo "export LIBTOOLIZE=\"$LIBTOOLIZE\"" echo "export LDFLAGS=\"$LDFLAGS\"" echo "export LDFLAGSMT_ADDITIONAL=\"$LDFLAGSMT_ADDITIONAL\"" echo "export LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH\"" echo "export MPIFC=\"$MPIFC\"" echo "export MPI_INCLUDE=\"$MPI_INCLUDE\"" echo "export MPILIBS_ADDITIONAL=\"$MPILIBS_ADDITIONAL\"" echo "export PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH\"" echo "export PATH=\"$PATH\"" echo


  1. ===============================================================================
  2. Single precision executables require preparation before hand

if [ $useSp -eq 1 ]; then

   (
       cd utils_lgpl/deltares_common
       command='scripts/changeprecision.tcl single'
       log "Executing \"$command\" in \"$PWD\" for single-precision executables"
       eval $command
       if [ $? -ne 0 ]; then
           log 'ABORT: Single-precision script failed'
           cd $orgdir
           exit 1
       fi
   )

fi


  1. ===============================================================================
  2. autogen: sanity checks, libtoolize and autoreconf

log='logs/autogen.log' command="./autogen.sh --verbose &> $log"

log "Running $command" eval $command

if [ $? -ne 0 ]; then

   log "Autogen fails!"
   cd $orgdir
   exit 1

fi


  1. ===============================================================================
  2. configure: Create makefiles

log='logs/configure.log'

if [ $debug -eq 1 ]; then

   flags='-g -O0'

else

   flags='-O2'

fi

  1. fPIC is the result of the mixing of static and libtool libraries.
  2. If you want to avoid this you can use convenience libraries.
  3. Don't do this for non AMD64 because it will lead to worse performance.
  4. More information here:
  5. http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?full=1#book_part1_chap3

command=" \

   CFLAGS='$flags $CFLAGS' \
   CXXFLAGS='$flags $CXXFLAGS' \
   AM_FFLAGS='$LDFLAGSMT_ADDITIONAL $AM_FFLAGS' \
   FFLAGS='$flags $fflags $FFLAGS' \
   AM_FCFLAGS='$LDFLAGSMT_ADDITIONAL $AM_FCFLAGS' \
   FCFLAGS='$flags $fflags $FCFLAGS' \
   AM_LDFLAGS='$LDFLAGSMT_ADDITIONAL $AM_LDFLAGS' \
       ./configure --prefix=`pwd` $configureArgs &> $log \
   "

log "Running `echo $command | sed 's/ +/ /g'`" eval $command

if [ $? -ne 0 ]; then

   log "Configure fails!"
   cd $orgdir
   exit 1

fi


  1. ===============================================================================
  2. make: Build and install everything

if [ $noMake -eq 1 ]; then

   log "Skipping make; execute the following command before doing manual makes:"
   echo $ifortInit
   cd $orgdir
   exit 0

fi

log='logs/make.log' command="make ds-install &> $log"

log "Running $command" eval $command

if [ $? -ne 0 ]; then

   log "Make fails!"
   cd $orgdir
   exit 1

fi

log "Build finished" cd $orgdir exit 0 "