From fd6c9867f27d96df7c0f13adebf8bd897a60456c Mon Sep 17 00:00:00 2001 From: "Kasper D. Fischer" Date: Thu, 27 May 2021 12:27:03 +0200 Subject: [PATCH] add example scripts This scripts are for testing and to show how to write your own gridengine scripts --- examples/jobs/matlab_script.sh | 81 ++++++++++++++++++++ examples/jobs/show_available_cuda_devices.sh | 44 +++++++++++ examples/jobs/simple_conda_test.sh | 37 +++++++++ 3 files changed, 162 insertions(+) create mode 100755 examples/jobs/matlab_script.sh create mode 100755 examples/jobs/show_available_cuda_devices.sh create mode 100755 examples/jobs/simple_conda_test.sh diff --git a/examples/jobs/matlab_script.sh b/examples/jobs/matlab_script.sh new file mode 100755 index 0000000..2edcdd7 --- /dev/null +++ b/examples/jobs/matlab_script.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +############################################################# +# This example produces a very simple plot and # +# saves it as Matlab figure file and as PNG file # +############################################################# + +############################################################# +# set qsub options # +############################################################# +# run in low.q +#$ -l low + +# request enough memory +#$ -l h_vmem=8G,memory=8G,h_stack=8M + +# request 1 matlab license. +#$ -l matlab=1 + +# Name the job 'Matlab' +#$ -N Matlab + +# send e-mail after job has finished +# use the -M option to define your e-mail address +# #$ -M meine-email@example.org +#$ -m e + +# join stdout and stderr in one file +#$ -j y + +############################################################# +# output hostname and date (comment out if not needed) # +############################################################# +echo "Runnning Matlab on host " `hostname` +echo "Starting Matlab at " `date` + +############################################################# +# launch matlab # +############################################################# + +# run non-interactive Matlab session +# use no display (-nodisplay) +# don't show splash screen at startup (-nosplash) +# don't start the matlab desktop (-nodesktop) +# use software opengl (-softwareopengl) +# only use single threaded computations (limit to use of 1 core, -singleCompThread) +# execute all matlab commands between '<< END' and matching 'END' + +# Don't forget to add 'exit' and 'END' after replacing +# the commands with your own! + +/opt/matlab/bin/matlab -nodisplay -nosplash -nodesktop -softwareopengl -singleCompThread << END + + % get environment variable JOB_ID + jobid=str2num(getenv('JOB_ID')); + if isempty(jobid) + jobid = 0; + end + + % create filenames for the figure + filename=sprintf('matlab_figure_%d', jobid); + + % create new empty figure and save figure handle + fh = figure(); + + % draw plot + plot(-pi:0.01:pi, sin(-pi:0.01:pi)); + + % save figure as matlab figure and PNG + saveas(fh, filename, 'fig'); + saveas(fh, filename, 'png'); + + % EXIT MATLAB + exit; + +END + +############################################################# +# output date (comment out if not needed) # +############################################################# +echo "Matlab finnished at " `date` diff --git a/examples/jobs/show_available_cuda_devices.sh b/examples/jobs/show_available_cuda_devices.sh new file mode 100755 index 0000000..f73e99e --- /dev/null +++ b/examples/jobs/show_available_cuda_devices.sh @@ -0,0 +1,44 @@ +#!/bin/bash +############################################################# +# use tensorflow to show availabel GPU devices # +# optional argument is the conda environment to use # +# default is tf-gpu # +############################################################# +TF_ENV=${1:-tf-gpu} +if [ ${TF_ENV} = "-h" ] ; then + echo "Usage: $(basename $0) [tensor_flow_env]" + exit 0 +fi + +############################################################# +# set qsub options # +############################################################# +#$ -cwd +#$ -N CUDAtest +#$ -l memory=64G,h_vmem=64G + +############################################################# +# initialize conda # +############################################################# +__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" +if [ $? -eq 0 ]; then + eval "$__conda_setup" +else + if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then + . "/opt/anaconda3/etc/profile.d/conda.sh" + else + export PATH="/opt/anaconda3/bin:$PATH" + fi +fi +unset __conda_setup +# <<< conda initialize <<< + +############################################################# +# activate conda env ent call python commands # +############################################################# +conda activate ${TF_ENV} +export TF_CPP_MIN_LOG_LEVEL=3 +export TF_FORCE_GPU_ALLOW_GROWTH=true +echo "CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:-''}." +python3 -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())" +conda deactivate diff --git a/examples/jobs/simple_conda_test.sh b/examples/jobs/simple_conda_test.sh new file mode 100755 index 0000000..4f5c9a9 --- /dev/null +++ b/examples/jobs/simple_conda_test.sh @@ -0,0 +1,37 @@ +#! /bin/bash + +############################################################# +# This example show a list of availabel conda environments # +############################################################# + +############################################################# +# set qsub options # +############################################################# +# run in low.q +#$ -l low + +# request enough memory +# #$ -l h_vmem=8G,memory=8G,h_stack=8M + +# Name the job 'Conda-Test' +#$ -N Conda-Test + +############################################################# +# initialize conda # +############################################################# +__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" +if [ $? -eq 0 ]; then + eval "$__conda_setup" +else + if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then + . "/opt/anaconda3/etc/profile.d/conda.sh" + else + export PATH="/opt/anaconda3/bin:$PATH" + fi +fi +unset __conda_setup + +############################################################# +# show conda environments # +############################################################# +conda env list