#!/bin/bash
#
# $Header: /u/gcmpack/MITgcm/tools/build_options/linux_ia64_cray_ollie,v 1.5 2016/06/06 19:31:12 mlosch Exp $
# $Name:  $

# Tested on cray CS400 ollie.awi.de 
# <https://swrepo1.awi.de/plugins/mediawiki/wiki/hpc/index.php/Main_Page>
# module load craype-broadwell
# module load PrgEnv-cray
# module swap mvapich2_cce cray-impi
# module load intel/impi-5.1.3

FC='ftn'
CC='cc'

FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  X ## _"
DEFINES='-DWORDLENGTH=4 '
CPP='cpp -traditional -P'
EXTENDED_SRC_FLAG='-Mextend'
OMPFLAG='-homp'
GET_FC_VERSION="-V"
RMFILES='*.lst'

NOOPTFLAGS="-O1"
NOOPTFILES=''

FFLAGS="$FFLAGS -h byteswapio" 
if test "$OMP" = true ; then 
  # for some reason this solves a problem with an unexpected 
  # "expectStatus=20" when using OpenMP with hyperthreads
  NOOPTFILES="${NOOPTFILES} diagnostics_switch_onoff.F mon_init.F mon_set_iounit.F"
else
  FFLAGS="$FFLAGS -hnoomp"
fi
# source file listing with compiler messages:
#FFLAGS="$FFLAGS -rm"
#FFLAGS="$FFLAGS -Wl,--whole-archive,-lhugetlbfs,--no-whole-archive -Wl,-Ttext-segment=0x20000000,-zmax-page-size=0x20000000 "

if test "x$IEEE" = x ; then     #- with optimisation:
# this is the default
#   FOPTIM='-O2'
# more aggressive
  FOPTIM="-O ipa3 -hfp3 -O3 "
else
  NOOPTFLAGS="-O0"
  if test "x$DEVEL" = x ; then  #- no optimisation + IEEE :
    FOPTIM="-O0 -hfp0"
   # -fltconsistency
  else                          #- development/check options:
    FOPTIM="-O0 -hfp0"
    FOPTIM="$FOPTIM -g -hfp0 -Rbc"
    # -r[list_ opt] produces a source listing file *.lst, -rm produces a 
    # listing with loopmark information and much more, not needed
    # for simple tests
    # -hmsgs -hnegmsgs writes a lot of optimisation messages to stderr
    #FOPTIM="$FOPTIM -rm -hmsgs -hnegmsgs"
  fi
fi

F90FLAGS=$FFLAGS
F90OPTIM=$FOPTIM
CFLAGS="-O0 $MCMODEL"

# after "module load intel/impi-5.1.3", I_MPI_ROOT should be available
#MPI_INC_DIR=" -I/opt/cray/mvapich2_cce/1.9/CRAY/83/include"
#MPI_INC_DIR="-I${INCLUDE_PATH_X86_64}"
MPI_INC_DIR=${I_MPI_ROOT}/include64
if test -n ${MPI_INC_DIR} ; then
    INCLUDES="$INCLUDES -I$MPI_INC_DIR"
    INCLUDEDIRS="$INCLUDEDIRS $MPI_INC_DIR"
    #- used for parallel (MPI) DIVA
    # MPIINCLUDEDIR="$MPI_INC_DIR"
    # MPI_HEADER_FILES='mpif.h mpiof.h'
fi

