Commit 3a18acfa authored by Christian Meesters's avatar Christian Meesters

untested, unfinished

parent f98cfa67
#!/bin/bash
# Copyright (c) 2018, Christian Meesters, JGU Mainz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Christian Meesters or the JGU Mainz nor the names of
# its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
# ensure clean environment
module purge
module load chem/ORCA
# guess a users account
_arg_assoc=$(sacct -nu "$USER" -o Account%20 | tail -n1 | tr -d '[:space:]')
_arg_queue="parallel"
_arg_constraint="broadwell"
SCRIPT="$0"
SCRIPT_VERSION="0.1"
die()
{
local _ret=$2
test -n "$_ret" || _ret=1
test "$_PRINT_HELP" = yes && print_help >&2
echo "$1" >&2
exit ${_ret}
}
begins_with_short_option()
{
local first_option all_short_options
all_short_options='lqscmrh'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
print_help ()
{
echo "This script's help msg"
echo 'Usage: ORCA_wrapper [options] <inputdir>'
echo
printf "\\t%s\\n" "--verbose,--no-verbose: verbose execution (off by default)"
printf "\\t%s\\n" "-l,--runlimit: runlimit default is 300 min"
printf "\\t%s\\n" "-p,--partition: queue (default is 'parallel')"
printf "\\t%s\\n" "-A,--account: account (default is the last submit account; an error is triggered if none specified nor can be deduced)"
printf "\\t%s\\n" "--credits: shows credits and version history"
printf "\\t%s\\n" "--version: shows the version number"
printf "\\t%s\\n" "-h,--help: Prints help"
echo "Report issues and create feature requests at: https://gitlab.rlp.net/hpc-jgu-physics-simulations/ab-initio-simulations/issues"
echo "This script will submit itself. DO NOT run it within a job!"
}
credits()
{
echo "Version is: $SCRIPT_VERSION"
echo
echo "History of the implementation:"
echo "- v0.1 -- 20. Dec. 2018 -- release of the implementation for SLURM, supporting the"
echo " ability to run multiple ORCA jobs on Mogon II."
}
# function to redirect simple error messages to stderr
error() {
(>&2 echo -e "ERROR: $1")
}
warning() {
(>&2 echo -e "WARNING: $1")
}
# command line parsing
while test $# -gt 0
do
_key="$1"
case "$_key" in
--test)
_arg_test=on
set -x
;;
--no-verbose|--verbose)
_arg_verbose="on"
test "${1:0:5}" = "--no-" && _arg_verbose="off"
;;
-l*|--runlimit|--runlimit=*)
_val_from_long="${_key##--runlimit=}"
_val_from_short="${_key##-l}"
if test "$_val_from_long" != "$_key"
then
_val="$_val_from_long"
elif test "$_val_from_short" != "$_key" -a -n "$_val_from_short"
then
_val="$_val_from_short"
else
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_val="$2"
shift
fi
_arg_runlimit="$_val"
;;
-p*|--partition|--partition=*)
_val_from_long="${_key##--partition=}"
_val_from_short="${_key##-p}"
if test "$_val_from_long" != "$_key"
then
_val="$_val_from_long"
elif test "$_val_from_short" != "$_key" -a -n "$_val_from_short"
then
_val="$_val_from_short"
else
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_val="$2"
shift
fi
_arg_queue="$_val"
;;
-A*|--account|--account=*)
_val_from_long="${_key##--account=}"
_val_from_short="${_key##-A}"
if test "$_val_from_long" != "$_key"
then
_val="$_val_from_long"
elif test "$_val_from_short" != "$_key" -a -n "$_val_from_short"
then
_val="$_val_from_short"
else
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_val="$2"
shift
fi
_arg_assoc="$_val"
;;
--tag|--tag=*)
_val_from_long="${_key##--tag=}"
_arg_tag=$_val_from_long
;;
-a*|--args|--args=*)
_val_from_long="${_key##--args=}"
_val_from_short="${_key##-a}"
if test "$_val_from_long" != "$_key"
then
_val="$_val_from_long"
elif test "$_val_from_short" != "$_key" -a -n "$_val_from_short"
then
_val="$_val_from_short"
else
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_val="$2"
shift
fi
_arg_args="$_val"
;;
--dependency|--dependency=*)
_val_from_long="${_key##--dependency=}"
_arg_dependency=$_val_from_long
;;
--constraint|--constraint=*)
_val_from_long="${_key##--constraint=}"
_arg_constraint=$_val_from_long
shift
;;
--credits)
credits
exit 0
;;
--version)
echo "$SCRIPT_VERSION"
exit 0
;;
-h*|--help)
print_help
exit 0
;;
*)
_positionals+=("$1")
;;
esac
shift
done
_positional_names=('_arg_inputdir')
for (( ii = 0; ii < 2; ii++)); do
eval "${_positional_names[ii]}=\${_positionals[ii]}" || die "Error during argument parsing, possibly an Argbash bug." 1
done
if [ -z "${_arg_assoc}" ]; then
error "No account given and, alas, not able to deduce one."
print_help
exit 1
fi
if [ -z "${_arg_inputdir}" ]; then
error "Found no indicator for the input."
print_help
exit 1
fi
### look for samples
# all possible samples without discrimination:
samples=$(find -L $(realpath "$_arg_inputdir") -type f \( -iname \*.gjf \) )
# transform to array
read -r -a samples <<< $samples
if [ ${#samples[@]} -eq 0 ]; then
error "no input found (was looking for '*gjf' in $_arg_inputdir)."
exit 1
fi
#check if this script is on node by checking env-variable $SLURM_JOB_ID, else send it to SLURM with given parameters and exit
if [ -z "$SLURM_JOB_ID" ]; then
for sample in "${_arg_inputdir}"/*.gjf; do
### infer job tag
if [ -z "$_arg_tag" ]; then
_arg_tag="ORCA_$(basename "$_arg_inputdir")_on_$(basename "$sample")_%j"
fi
### check if output directory already exists
if [[ ! -d "${_arg_outdir// }" ]]; then
_arg_outdir="$(pwd)/${_arg_tag}"
mkdir -p "${_arg_outdir}"
else
error "${_arg_outdir// } exists already! Possibly over overwrite of results. Cowardly giving up."
fi
sbatch -A "${_arg_assoc}" -p parallel -J "${_arg_tag}" -o "${_arg_outdir}" -n 40 -t 120:00:00 --signal=B:SIGUSR2@600 -N 1 --wrap "$(cat << EOF
cleanup(){
cp /localscratch/${SLURM_JOB_ID}/* "\${_arg_outdir}"
}
trap 'cleanup' SIGUSR2
cp $sample /localscratch/\${SLURM_JOB_ID}
# Go to jobdir and start the program
cd /localscratch/\${SLURM_JOB_ID}
set OMPI_MCA_btl=self,sm
orca $sample
cleanup
EOF
)"
done
fi
https://stackoverflow.com/questions/53071681/use-of-a-heredoc-with-slurm-sbatch-wrap
EOF
)
#./orca.sh ${sample}
done
fi
https://stackoverflow.com/questions/53071681/use-of-a-heredoc-with-slurm-sbatch-wrap
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment