#! /bin/csh -f

#===============================================================================
# Build time settings
#===============================================================================

if (-e /opt/modules/default/init/csh) then
  source /opt/modules/default/init/csh
  module rm PrgEnv-intel
  module rm PrgEnv-pgi
  module rm PrgEnv-cray 
  module rm PrgEnv-gnu
  module rm PrgEnv-pathscale
  module rm intel
  module rm pgi
  module rm cray
  module rm pathscale
  module rm netcdf
  module load subversion
else
  echo "ERROR: Failed to initialize modules"
  exit -1
endif

# invoking modules sets $MPICH_DIR and $CRAY_NETCDF_DIR

if ( $COMPILER == "pgi" ) then
    module load PrgEnv-pgi
    module switch pgi       pgi/11.10.0        
    module switch xt-mpt    xt-mpt/4.0.3     
    module switch xt-libsci xt-libsci/10.4.3 
    module load esmf/5.2.0rp1
    module load PGI/netcdf4/4.1.3_seq
endif

if ( $COMPILER == "intel" ) then
    module load PrgEnv-intel
    module switch intel     intel/12.1.0
    module switch xt-mpt    xt-mpt/5.1.4
    module switch xt-libsci xt-libsci/10.5.02
    module load esmf/5.2.0rp1
    module load netcdf
endif

if ( $COMPILER == "pathscale" ) then
    module load PrgEnv-pathscale
    module load pathscale
    module load torque
    module load netcdf
endif

if ( $COMPILER == "gnu" ) then
    module load PrgEnv-gnu
    module load torque
endif    

if ( $COMPILER == "cray" ) then
    module load PrgEnv-cray
    module load cce/7.2.8
    module load torque
    module load netcdf
endif


#-------------------------------------------------------------------------------
# Runtime environment variables
#-------------------------------------------------------------------------------

# fix for file system problem with empty namelists, june 2011
setenv DVS_MAXNODES 1

setenv MPICH_MAX_SHORT_MSG_SIZE  8000  # default is 128000 bytes
setenv MPICH_PTL_UNEX_EVENTS    960000 # default is  90000 (unexpected recv queue size)
#etenv MPICH_UNEX_BUFFER_SIZE    1000M # default is    60M (unexpected short msgs buff size)
setenv MPICH_MSGS_PER_PROC      160000 # default is  32768
setenv MPICH_PTL_SEND_CREDITS       -1
setenv MPICH_ENV_DISPLAY 1
setenv MPICH_VERSION_DISPLAY 1

# The environment variables below produce corefiles and maybe (?) should be
# moved to DEBUG mode at some point
setenv MPICH_DBMASK 0x200
limit coredumpsize unlimited
limit stacksize unlimited

# The environment variable below increase the stack size, which is necessary for
# CICE to run threaded on this machine.  
setenv MPSTKZ 64M
setenv OMP_STACKSIZE 64M

