Back to home page

MITgcm

 
 

    


Warning, /tools/build_options/linux_amd64_gfortran_avx2 is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit ae4c03af on 2026-10-03 15:35:21 UTC
ae4c03af78 Oliv*0001 #!/bin/bash
                0002 
                0003 # Build options for gfortran compiler (GNU) on Linux AMD64 platform
                0004 #
                0005 # Should work with both AMD and Intel processors that support AVX2 instructions.
                0006 #
                0007 # Tested with gfortran 12.2.0
                0008 #
                0009 # MPI : Tested on engaging on Rocky Linux 8.10 with
                0010 #       module load gcc/12.2.0
                0011 #       module load openmpi/4.1.4
                0012 #       module load netcdf-c/4.9.2
                0013 #       module load netcdf-fortran/4.6.1
                0014 # requires:
                0015 #       export MPI_INC_DIR=/orcd/software/core/001/spack/pkg/openmpi/4.1.4/zahpnmk/include
                0016 #       export LD_LIBRARY_PATH=/orcd/software/community/001/spack/pkg/netcdf-c/4.9.2/2uroesk/lib:/orcd/software/community/001/spack/pkg/netcdf-fortran/4.6.1/gxllmsl/lib:$LD_LIBRARY_PATH
                0017 
                0018 #-------
                0019 # run with OpenMP: needs to set environment var. OMP_NUM_THREADS
                0020 #    and generally, needs to increase the thread stack-size:
                0021 #   -  sh,bash:
                0022 #     > export OMP_NUM_THREADS=2
                0023 #     > export GOMP_STACKSIZE=400m
                0024 #   - csh,tcsh:
                0025 #     > setenv OMP_NUM_THREADS 2
                0026 #     > setenv GOMP_STACKSIZE 400m
                0027 #-------
                0028 
                0029 if test "x$MPI" = xtrue ; then
                0030   CC=${MPICC:=mpicc}
                0031   FC=${MPIFC:=mpif77}
                0032   F90C=${MPIF90C:=mpif90}
                0033 else
                0034   CC=gcc
                0035   FC=gfortran
                0036   F90C=gfortran
                0037 fi
                0038 
                0039 DEFINES='-DWORDLENGTH=4 -DNML_TERMINATOR'
                0040 EXTENDED_SRC_FLAG='-ffixed-line-length-132'
                0041 F90FIXEDFORMAT='-ffixed-form'
                0042 GET_FC_VERSION="--version"
                0043 OMPFLAG='-fopenmp'
                0044 
                0045 NOOPTFLAGS='-O0'
                0046 NOOPTFILES=''
                0047 
                0048 PROCF="-mavx2"
                0049 
                0050 CFLAGS="-O0 $PROCF"
                0051 
                0052 #- for setting specific options, check compiler version:
                0053 fcVers=`$CC -dumpversion | head -n 1 | sed 's/^[^0-9]* //;s/\..*$//'`
                0054 if ! [[ $fcVers =~ ^[0-9]+$ ]] ; then
                0055   echo "    un-recognized Compiler-version '$fcVers' ; ignored (-> set to 0)" ; fcVers=0 ;
                0056 else echo "    get Compiler-version: '$fcVers'" ; fi
                0057 
                0058 if [ $fcVers -ge 10 ] ; then
                0059   FFLAGS="$FFLAGS -fallow-argument-mismatch"
                0060 fi
                0061 #- Requires gfortran from 2006 onwards for -fconvert=big-endian
                0062 FFLAGS="$FFLAGS -fconvert=big-endian -fimplicit-none -frecursive"
                0063 #- for big setups, compile & link with "-fPIC" or set memory-model to "medium":
                0064 #CFLAGS="$CFLAGS -fPIC"
                0065 #FFLAGS="$FFLAGS -fPIC"
                0066 #-  with FC 19, need to use this without -fPIC (which cancels -mcmodel option):
                0067  CFLAGS="$CFLAGS -mcmodel=medium"
                0068  FFLAGS="$FFLAGS -mcmodel=medium"
                0069 #- might want to use '-fdefault-real-8' for fizhi pkg:
                0070 #FFLAGS="$FFLAGS -fdefault-real-8 -fdefault-double-8"
                0071 
                0072 if test "x$IEEE" = x ; then     #- with optimisation:
                0073    #- full optimisation
                0074     FOPTIM="-O3 -funroll-loops $PROCF"
                0075     NOOPTFILES="$NOOPTFILES ini_masks_etc.F"
                0076    #- can use -O2 (safe optimisation) to avoid Pb with some gcc version of -O3:
                0077    #FOPTIM='-O2 -funroll-loops'
                0078 else
                0079    # these may also be useful, but require specific gfortran versions:
                0080    # -Wnonstd-intrinsics        for gfortran <= 4.3
                0081    # -Wintrinsics-std           for gfortran >= 4.4
                0082    # -Wno-tabs                  for gfortran >= 4.3
                0083    # -Wno-unused-dummy-argument for gfortran >= 4.6
                0084    #FFLAGS="$FFLAGS -Waliasing -Wampersand -Wsurprising -Wline-truncation"
                0085    #- or simply:
                0086     FFLAGS="$FFLAGS -Wall"
                0087     if [ $fcVers -ge 10 ] ; then
                0088       FFLAGS="$FFLAGS -Wno-unused-dummy-argument"
                0089     fi
                0090    #- to get plenty of warnings: -Wall -Wextra (older form: -Wall -W) or:
                0091    #FFLAGS="$FFLAGS -Wconversion -Wimplicit-interface -Wunused-labels"
                0092   if test "x$DEVEL" = x ; then  #- no optimisation + IEEE :
                0093     FOPTIM="-O0 $PROCF"
                0094   else                          #- development/check options:
                0095     FOPTIM="-O0 -g -fbounds-check $PROCF"
                0096     FOPTIM="$FOPTIM -ffpe-trap=invalid,zero,overflow -finit-real=inf"
                0097   fi
                0098 fi
                0099 
                0100 F90FLAGS=$FFLAGS
                0101 F90OPTIM=$FOPTIM
                0102 
                0103 INCLUDEDIRS=''
                0104 INCLUDES=''
                0105 LIBS=''
                0106 
                0107 if [ "x$NETCDF_ROOT" != x ] ; then
                0108     INCLUDEDIR="${NETCDF_ROOT}/include"
                0109     INCLUDES="-I${NETCDF_ROOT}/include"
                0110     LIBDIR="${NETCDF_ROOT}/lib"
                0111     LIBS="-L${NETCDF_ROOT}/lib"
                0112 elif [ "x$NETCDF_HOME" != x ]; then
                0113     INCLUDEDIR="${NETCDF_HOME}/include"
                0114     INCLUDES="-I${NETCDF_HOME}/include"
                0115     LIBDIR="${NETCDF_HOME}/lib"
                0116     LIBS="-L${NETCDF_HOME}/lib"
                0117 elif [ "x$NETCDF_INC" != x -a "x$NETCDF_LIB" != x ]; then
                0118     NETCDF_INC=`echo $NETCDF_INC | sed 's/-I//g'`
                0119     NETCDF_LIB=`echo $NETCDF_LIB | sed 's/-L//g'`
                0120     INCLUDEDIR="${NETCDF_INC}"
                0121     INCLUDES="-I${NETCDF_INC}"
                0122     LIBDIR="${NETCDF_LIB}"
                0123     LIBS="-L${NETCDF_LIB}"
                0124 elif [ "x$NETCDF_INCDIR" != x -a "x$NETCDF_LIBDIR" != x ]; then
                0125     INCLUDEDIR="${NETCDF_INCDIR}"
                0126     INCLUDES="-I${NETCDF_INCDIR}"
                0127     LIBDIR="${NETCDF_LIBDIR}"
                0128     LIBS="-L${NETCDF_LIBDIR}"
                0129 elif [[ -n $( nc-config --flibs 2> /dev/null ) && ($? == 0) ]] ; then
                0130     # NETCDF env variables are not set; try nc-config
                0131     # with recent netcdf, can get both c and fortran bits from nc-config
                0132     INCLUDES="$(nc-config --fflags)"
                0133     # sometimes path to c library is not included in --flibs, include explicitly
                0134     LIBS="$(nc-config --libs) $(nc-config --flibs)"
                0135 elif [[ -n $( nf-config --includedir 2> /dev/null ) && ($? == 0) ]] ; then
                0136     # NETCDF env variables are not set, trying nf-config instead
                0137     INCLUDEDIR=$( nf-config --includedir )
                0138     INCLUDES="-I$INCLUDEDIR"
                0139     LIBS=$( nf-config --flibs )
                0140     # some broken installations (spack, homebrew) do not have the netcdf-c
                0141     # lib path in nf-config, so we'll add it here using nc-config
                0142     if [[ -n $( nc-config --libs 2> /dev/null ) && ($? == 0) ]] ; then
                0143         LIBS="$LIBS $( nc-config --libs )"
                0144     fi
                0145 elif test -d /usr/include/netcdf-3 ; then
                0146     INCLUDES='-I/usr/include/netcdf-3'
                0147     LIBS='-L/usr/lib/netcdf-3 -L/usr/lib64/netcdf-3'
                0148 elif test -d /usr/include/netcdf ; then
                0149     INCLUDES='-I/usr/include/netcdf'
                0150 elif test -d /usr/local/netcdf ; then
                0151     INCLUDES='-I/usr/local/netcdf/include'
                0152     LIBS='-L/usr/local/netcdf/lib'
                0153 elif test -d /usr/local/include/netcdf.inc ; then
                0154     INCLUDES='-I/usr/local/include'
                0155     LIBS='-L/usr/local/lib64'
                0156 elif test -d /usr/include/netcdf.inc ; then
                0157     INCLUDES='-I/usr/include'
                0158     LIBS='-L/usr/lib64'
                0159 fi
                0160 
                0161 if [ -n "$MPI_HOME" -a -z "$MPI_INC_DIR" ]; then
                0162     MPI_INC_DIR="$MPI_HOME/include"
                0163 fi
                0164 
                0165 if [ "x$MPI" = xtrue ] ; then
                0166    if [ -z "$MPI_INC_DIR" ] ; then
                0167       # MPI env variables are not set, trying pkg-config instead
                0168       if [[ -n $( pkg-config --cflags-only-I ompi ) && ($? == 0) ]] ; then
                0169          MPI_INC_DIR=$(pkg-config --cflags-only-I ompi | awk '{ print $1 }' | sed -e "s/-I//" )
                0170       else
                0171          echo MPI_HOME is not set and pkg-config not available, aborting
                0172          exit 1
                0173       fi
                0174    fi
                0175    if [ -n "$MPI_INC_DIR" ] ; then
                0176       # only fill this if we can find MPI, otherwise triggers netcdf error
                0177       INCLUDES+=" -I$MPI_INC_DIR"
                0178       INCLUDEDIRS+=" $MPI_INC_DIR"
                0179       #- used for parallel (MPI) DIVA
                0180       MPIINCLUDEDIR="$MPI_INC_DIR"
                0181    else
                0182       echo could not set MPI_INC_DIR, aborting
                0183       exit 1
                0184    fi
                0185 fi