#!/bin/bash
######################################################################
# ugbash
#-------------------------------------------------------------------
# created by Martin Rupp 01.07.2014
# mail: martin.rupp@gcsc.uni-frankfurt.de
#
# source this file in your ~/.bashrc .
# it will then automatically set up the cluster for ug4
# e.g. loading of lapack/blas/compiler modules.
######################################################################

#scriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
scriptpath=${UG4_ROOT}/ugcore/scripts/shell

if [ -z "$UGSUBMIT_TYPE" ]; then
	source $scriptpath/clusterdetect
	echo "ugconfig: Configuring your bash environment... Your auto-detected cluster is $UGSUBMIT_TYPE."
else
	echo "ugconfig: Configuring your bash environment... Your manually set cluster is $UGSUBMIT_TYPE."
fi



if [ "$UGSUBMIT_TYPE" = "Hermit" ] || [ "$UGSUBMIT_TYPE" = "Hazelhen" ] || [ "$UGSUBMIT_TYPE" = "Hornet" ]; then
	echo "ugconfig: On Hermit/Hornet/Hazelhen, loading gnu compilers" 
	module list 2>&1 | grep PrgEnv-gnu > /dev/null
	if [ $? == 1 ]; then
	echo loading PrgEnv-gnu
	module swap $(module li 2>&1 | awk '/PrgEnv/{print $2}') PrgEnv-gnu
	else
	echo PrgEnv-gnu already loaded.
	fi
	
elif [ "$UGSUBMIT_TYPE" = "cekon" ]; then
	echo "ugconfig: Nothing to configure on cekon. Have a nice day."
	
elif [ "$UGSUBMIT_TYPE" = "cesari" ]; then
	echo "ugconfig: Nothing to configure on cesari. Have a nice day."
	
elif [ "$UGSUBMIT_TYPE" = "mpi" ] && [ "$UGSUBMIT_MORE" = "Apple" ]; then
	echo "ugconfig: Nothing to configure on Apple systems. Have a nice day."
				
elif [ "$UGSUBMIT_TYPE" = "mpi" ]; then
	echo "ugconfig: Nothing to configure on $UGSUBMIT_TYPE. Have a nice day."
		
elif [ "$UGSUBMIT_TYPE" = "Juqueen" ]; then
	echo "ugconfig: Loading cmake and lapack."
	module load cmake
	module load lapack
	
elif [ "$UGSUBMIT_TYPE" = "Jureca" ]; then
	echo "ugconfig: Loading toolchain with compilers and lapack as well as cmake."
	module load Intel           # compilers
	module load ParaStationMPI  # MPI wrappers
	module load imkl            # BLAS / LAPACK
	module load CMake

elif [ "$UGSUBMIT_TYPE" = "Juwels" ]; then
	echo "ugconfig: Loading toolchain with compilers and BLAS / LAPACK as well as CMake."
	module load Intel           # compilers
	module load ParaStationMPI  # MPI wrappers
	module load imkl            # BLAS / LAPACK
	module load CMake

elif [ "$UGSUBMIT_TYPE" = "unknown" ]; then 
    echo "Hello, this is ugconfig trying to config your cluster"
    echo "The UGSUBMIT_TYPE could not be set automatically." 
	echo "please set UGSUBMIT_TYPE manually."
	exit
	
else
    #echo $HOSTNAME
	echo "ugconfig: not yet supported cluster $UGSUBMIT_TYPE".
fi   	

