iprbench/usecases/ipr/hibench/starbench-template.job

110 lines
3.9 KiB
Bash

#!/usr/bin/env bash
# this job file is a template file for starbench jobs
git_repos_url="$1" # eg "https://github.com/hibridon/hibridon"
git_user="$2" # eg 'g-raffy'
git_pass_file="$3" # eg "$HOME/.github/personal_access_tokens/bench.hibridon.cluster.ipr.univ-rennes1.fr.pat"
code_version="$4" # git branch id or commit id eg : 'a3bed1c3ccfbca572003020d3e3d3b1ff3934fad'
cmake_options="$5" # eg '-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON'
benchmark_command="$6" # eg 'ctest -L ^arch4_quick$'
env_vars_bash_commands="$7" # defines extra environment variables prior to launch starbench. eg "export MKLROOT=/opt/intel/compilers_and_libraries_2020.1.217/linux/mkl"
starbench_src_url="$8" # location of starbench source (eg /opt/ipr/cluster/work.global/graffy/hibridon/benchmarks/starbench/hibench/2024-10-08T16:39:52+02:00/starbench)
cmake_path="$9" # eg '/opt/cmake/cmake-3.23.0/bin/cmake'
executed_by_sge=''
if [ "${JOB_ID}" = '' ]
then
executed_by_sge='false'
# this script is not executed by sge... set dummy values for test
TMPDIR=/tmp
JOB_ID=666666
NSLOTS=2
else
executed_by_sge='true'
fi
launch_dir="$(pwd)"
echo "Executing job ${JOB_ID} on $(hostname) from ${launch_dir}"
echo "date: $(date --iso-8601=seconds)"
temp_dir=${TMPDIR}/$(whoami)/${JOB_ID}
if [ -d "${temp_dir}" ]
then
rm -Rf "${temp_dir}"
fi
mkdir -p "${temp_dir}"
# create a virtual environment to install starbench
venv_path="${temp_dir}/starbench.venv"
python3 -m virtualenv "$venv_path"
if [ $? != 0 ]
then
echo "failed to create the virtual environment $venv_path"
exit 1
fi
source "$venv_path/bin/activate"
if [ $? != 0 ]
then
echo "failed to activate the virtual environment $venv_path"
exit 1
fi
pip install $starbench_src_url
if [ $? != 0 ]
then
echo "failed to install starbench ($starbench_src_url) in the virtual environment $venv_path"
exit 1
fi
output_dir="${temp_dir}"
num_cores=${NSLOTS}
# set environment variables
echo "env_vars_bash_commands=$env_vars_bash_commands"
eval $env_vars_bash_commands
# launch starbench
strUr1ProxyUrl='http://proxy-nt.univ-rennes1.fr:3128'
strProxyVars=''
strProxyVars="$strProxyVars HTTP_PROXY=$strUr1ProxyUrl"
strProxyVars="$strProxyVars HTTPS_PROXY=$strUr1ProxyUrl"
strProxyVars="$strProxyVars FTP_PROXY=$strUr1ProxyUrl"
strProxyVars="$strProxyVars http_proxy=$strUr1ProxyUrl"
strProxyVars="$strProxyVars https_proxy=$strUr1ProxyUrl"
strProxyVars="$strProxyVars ftp_proxy=$strUr1ProxyUrl"
command="$strProxyVars starbench"
command="${command} --git-repos-url ${git_repos_url}"
command="${command} --git-user ${git_user}"
command="${command} --git-pass-file ${git_pass_file}"
command="${command} --num-cores ${num_cores}"
command="${command} --output-dir ${output_dir}"
command="${command} --code-version ${code_version}"
command="${command} --cmake-path ${cmake_path}"
# echo "cmake_options: @$cmake_options@"
for cmake_option in ${cmake_options}
do
command="${command} --cmake-option=${cmake_option}"
done
command="${command} --benchmark-command=\"${benchmark_command}\""
echo "command: ${command}"
eval ${command}
if [ "$?" = '0' ]
then
echo "the command ${command} succeeded"
rsync -va --exclude 'build' --exclude 'source.git' "${output_dir}/" ${launch_dir}/ # exclude the source.git and build directories (one for each worker) because they are big and not that precious
# TMPDIR will be deleted by sge at the end of the job
else
if [ ${executed_by_sge} = 'true' ]
then
# TMPDIR will be deleted by sge at the end of the job. Backup data for investigation
backup_dir="/opt/ipr/cluster/work.local/$(whoami)/${JOB_ID}"
echo "moving ${output_dir} to ${backup_dir} to that it doesn't get deleted by sge at the end of the job. This way, data gets a chance to be investigated then manually deleted."
mv "${output_dir}" "${backup_dir}"
fi
echo "the command ${command} failed... the output data dir (${output_dir}) is expected to be cleaned up manually after investigation"
exit 1
fi