#!/bin/bash -el
ulimit -c 0

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

module load devpack/20180521/openmpi/2.1.2/gcc/7.2.0/cuda/9.2.88
module swap openblas/0.2.20/gcc/7.2.0 netlib/3.8.0/gcc/7.2.0
# Trilinos now requires cmake version >= 3.10.0
module swap cmake/3.9.6 cmake/3.12.3
export OMP_NUM_THREADS=8
export JENKINS_DO_CUDA=OFF
export JENKINS_DO_OPENMP=ON
export JENKINS_DO_PTHREAD=OFF
export JENKINS_DO_SERIAL=OFF
export JENKINS_DO_COMPLEX=OFF

export JENKINS_ARCH="Power8"
export JENKINS_ARCH_CXX_FLAG="-mcpu=power8"
export JENKINS_ARCH_C_FLAG="-mcpu=power8"
export BLAS_LIBRARIES="${BLAS_ROOT}/lib/libblas.a;gfortran;gomp"
export LAPACK_LIBRARIES="${LAPACK_ROOT}/lib/liblapack.a;gfortran;gomp"

export JENKINS_DO_TESTS=ON
export JENKINS_DO_EXAMPLES=ON

export QUEUE=rhel7T

module load python/2.7.12

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_lsf ${TRILINOS_UPDATED_PATH} ${TRILINOS_PRISTINE_PATH} ${TRILINOS_UPDATED_PATH}/sampleScripts/Sandia-SEMS/configure-testbeds-jenkins-all TestCompare ${QUEUE}

