|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +# Check for an optional timeout threshold in seconds. If the duration of the |
| 6 | +# model run as executed below, takes longer that this threshhold |
| 7 | +# then the run will be aborted. Note that the "timeout" command |
| 8 | +# must be supported by executing OS. |
| 9 | + |
| 10 | +# The timeout argument is optional. By default the "run_model" swift |
| 11 | +# app fuction sends 3 arguments, and no timeout value is set. If there |
| 12 | +# is a 4th (the TIMEOUT_ARG_INDEX) argument, we use that as the timeout value. |
| 13 | + |
| 14 | +# !!! IF YOU CHANGE THE NUMBER OF ARGUMENTS PASSED TO THIS SCRIPT, YOU MUST |
| 15 | +# CHANGE THE TIMEOUT_ARG_INDEX !!! |
| 16 | +TIMEOUT_ARG_INDEX=4 |
| 17 | +TIMEOUT="" |
| 18 | +if [[ $# == $TIMEOUT_ARG_INDEX ]] |
| 19 | +then |
| 20 | + TIMEOUT=${!TIMEOUT_ARG_INDEX} |
| 21 | +fi |
| 22 | + |
| 23 | +TIMEOUT_CMD="" |
| 24 | +if [ -n "$TIMEOUT" ]; then |
| 25 | + TIMEOUT_CMD="timeout $TIMEOUT" |
| 26 | +fi |
| 27 | + |
| 28 | +# Set param_line from the first argument to this script |
| 29 | +# param_line is the string containing the model parameters for a run. |
| 30 | +param_file=$1 |
| 31 | + |
| 32 | +# Set emews_root to the root directory of the project (i.e. the directory |
| 33 | +# that contains the scripts, swift, etc. directories and files) |
| 34 | +emews_root=$2 |
| 35 | + |
| 36 | +# Each model run, runs in its own "instance" directory |
| 37 | +# Set instance_directory to that and cd into it. |
| 38 | +instance_directory=$3 |
| 39 | +cd $instance_directory |
| 40 | + |
| 41 | +# TODO: Define the command to run the model |
| 42 | +#VERSION="$(<$emews_root/../Release/version.txt)" |
| 43 | +#APP=$emews_root/../Release/transmission_model-$VERSION |
| 44 | +#PROPS_FILE=$emews_root/../config/model.props |
| 45 | +# TODO configure python correctly |
| 46 | +# export PYTHONPATH=$emews_root/python:$benchmark_path |
| 47 | +PYTHON="/home/pbalapra/anaconda2/envs/idp/bin/python" |
| 48 | +export LD_LIBRARY_PATH="/home/pbalapra/anaconda2/envs/idp/lib" |
| 49 | +export PATH="/home/pbalapra/anaconda2/envs/idp/bin:$PATH" |
| 50 | +export PYTHONHOME="/home/pbalapra/anaconda2/envs/idp" |
| 51 | +export PYTHONPATH="/home/pbalapra/anaconda2/envs/idp/lib/python2.7:/home/ncollier/repos/Benchmarks/Pilot1/P1B3:/home/pbalapra/anaconda2/envs/idp/lib/python2.7/site-packages" |
| 52 | +MODEL_CMD="python $emews_root/python/stage_data.py" |
| 53 | + |
| 54 | +# Turn bash error checking off. This is |
| 55 | +# required to properly handle the model execution return value |
| 56 | +# the optional timeout. |
| 57 | +set +e |
| 58 | +echo $MODEL_CMD |
| 59 | +$TIMEOUT_CMD $MODEL_CMD |
| 60 | +# $? is the exit status of the most recently executed command (i.e the |
| 61 | +# line above) |
| 62 | +RES=$? |
| 63 | +if [ "$RES" -ne 0 ]; then |
| 64 | + if [ "$RES" == 124 ]; then |
| 65 | + echo "---> Timeout error in $MODEL_CMD" |
| 66 | + else |
| 67 | + echo "---> Error in $MODEL_CMD" |
| 68 | + fi |
| 69 | +fi |
0 commit comments