#!/bin/bash -el
ulimit -c 0
module load devpack/20171203/openmpi/2.1.2/intel/18.1.163
# Trilinos now requires cmake version >= 3.10.0
module swap cmake/3.9.0 cmake/3.10.2

KOKKOS_BRANCH=$1
TRILINOS_UPDATE_BRANCH=$2
TRILINOS_PRISTINE_BRANCH=$3

if [ -z $KOKKOS_BRANCH ]
then
  KOKKOS_BRANCH=develop
fi

if [ -z $TRILINOS_UPDATE_BRANCH ]
then
  TRILINOS_UPDATE_BRANCH=develop
fi

if [ -z $TRILINOS_PRISTINE_BRANCH ]
then
  TRILINOS_PRISTINE_BRANCH=develop
fi

export OMP_NUM_THREADS=8
export JENKINS_DO_CUDA=OFF
export JENKINS_DO_OPENMP=OFF
export JENKINS_DO_PTHREAD=ON
export JENKINS_DO_SERIAL=OFF
export JENKINS_DO_COMPLEX=OFF

export JENKINS_ARCH=SKX
export JENKINS_ARCH_CXX_FLAG="-xCORE-AVX512 -mkl"
export JENKINS_ARCH_C_FLAG="-xCORE-AVX512 -mkl"
export BLAS_LIBRARIES="-mkl;${MKLROOT}/lib/intel64/libmkl_intel_lp64.a;${MKLROOT}/lib/intel64/libmkl_intel_thread.a;${MKLROOT}/lib/intel64/libmkl_core.a"
export LAPACK_LIBRARIES=${BLAS_LIBRARIES}

export JENKINS_DO_TESTS=ON
export JENKINS_DO_EXAMPLES=ON
export JENKINS_DO_SHARED=ON

export QUEUE=blake


module load python/2.7.13


export KOKKOS_PATH=${PWD}/kokkos

#Already done:
if [ ! -d "${KOKKOS_PATH}" ]; then
  git clone https://github.com/kokkos/kokkos ${KOKKOS_PATH}
fi

cd ${KOKKOS_PATH}
git checkout $KOKKOS_BRANCH
git pull
cd ..

source ${KOKKOS_PATH}/scripts/trilinos-integration/prepare_trilinos_repos.sh $TRILINOS_UPDATE_BRANCH $TRILINOS_PRISTINE_BRANCH

${TRILINOS_UPDATED_PATH}/sampleScripts/Sandia-SEMS/run_repo_comparison_slurm ${TRILINOS_UPDATED_PATH} ${TRILINOS_PRISTINE_PATH} ${TRILINOS_UPDATED_PATH}/sampleScripts/Sandia-SEMS/configure-testbeds-jenkins-all TestCompare ${QUEUE}
