#!/bin/bash -el
ulimit -c 0
module load devpack/openmpi/2.1.1/intel/17.4.196/cuda/none

KOKKOSKERNELS_BRANCH=$1
TRILINOS_UPDATE_BRANCH=$2
TRILINOS_PRISTINE_BRANCH=$3
KOKKOS_UPDATE_BRANCH=$4

if [ -z $KOKKOSKERNELS_BRANCH ]
then
  KOKKOSKERNELS_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=OFF
export JENKINS_DO_SERIAL=ON
export JENKINS_DO_COMPLEX=ON

export JENKINS_ARCH_CXX_FLAG="-xCORE-AVX2 -mkl"
export JENKINS_ARCH_C_FLAG="-xCORE-AVX2 -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=haswell


module load python


export KOKKOSKERNELS_PATH=${PWD}/kokkos-kernels

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

cd ${KOKKOSKERNELS_PATH}
git checkout $KOKKOSKERNELS_BRANCH
git pull
cd ..

if [ -n $KOKKOS_UPDATE_BRANCH ]
then
  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_UPDATE_BRANCH
  git pull
  cd ..
fi

source ${KOKKOSKERNELS_PATH}/scripts/trilinos-integration/prepare_trilinos_repos.sh $TRILINOS_UPDATE_BRANCH $TRILINOS_PRISTINE_BRANCH $KOKKOS_UPDATE_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}
