#!/bin/bash
set -e

pkg="examl"

export OMPI_MCA_rmaps_base_oversubscribe=1

if [ "$ADTTMP" = "" ] ; then
  ADTTMP=`mktemp -d /tmp/${pkg}-test.XXXXXX`
  trap "rm -rf $ADTTMP" 0 INT QUIT ABRT PIPE TERM
fi

cp -a /usr/share/doc/${pkg}/testData $ADTTMP

cd $ADTTMP

gunzip -r *

parse-examl -s testData/49 -m DNA -n 49.unpartitioned
parse-examl -s testData/49 -q testData/49.model -m DNA -n 49.partitioned

examl -t testData/49.tree -m GAMMA -s 49.unpartitioned.binary -n T1
examl -s 49.unpartitioned.binary -R ExaML_binaryCheckpoint.T1_5 -m GAMMA -n T1_RESTART
examl -t testData/49.tree -m GAMMA -s 49.partitioned.binary -n T2

examl -s 49.unpartitioned.binary -t treeSet -f e -m GAMMA -n T3 || true
# ---->
# /usr/lib/examl/bin/examl-AVX -s 49.unpartitioned.binary -t treeSet -f e -m GAMMA -n T3 
# Memory Saving Option: DISABLED
# The file treeSet you want to open for reading does not exist, exiting ...
# -------------------------------------------------------
# Primary job  terminated normally, but 1 process returned
# a non-zero exit code. Per user-direction, the job has been aborted.
# -------------------------------------------------------
# --------------------------------------------------------------------------
# mpirun detected that one or more processes exited with non-zero status, thus causing
# the job to be terminated. The first process to do so was:
# 
#   Process name: [[60438,1],0]
#   Exit code:    255
# --------------------------------------------------------------------------

examl -s 49.unpartitioned.binary -t treeSet -f E -m GAMMA -n T4 || true
# ---->
# /usr/lib/examl/bin/examl-AVX -s 49.unpartitioned.binary -t treeSet -f E -m GAMMA -n T4 
# Memory Saving Option: DISABLED
# The file treeSet you want to open for reading does not exist, exiting ...
# -------------------------------------------------------
# Primary job  terminated normally, but 1 process returned
# a non-zero exit code. Per user-direction, the job has been aborted.
# -------------------------------------------------------
# --------------------------------------------------------------------------
# mpirun detected that one or more processes exited with non-zero status, thus causing
# the job to be terminated. The first process to do so was:
# 
#   Process name: [[60781,1],0]
#   Exit code:    255
# --------------------------------------------------------------------------

exit 0

#  Hmmmm, the following command does not end in a sensible time frame
examl-OMP -t testData/49.tree -m GAMMA -s 49.unpartitioned.binary -n T1-OMP
examl-OMP -s 49.unpartitioned.binary -R ExaML_binaryCheckpoint.T1_5 -m GAMMA -n T1_RESTART-OMP
examl-OMP -t testData/49.tree -m GAMMA -s 49.partitioned.binary -n T2-OMP
#examl-OMP -s 49.unpartitioned.binary -t treeSet -f e -m GAMMA -n T3-OMP
#examl-OMP -s 49.unpartitioned.binary -t treeSet -f E -m GAMMA -n T4-OMP
