-
-
Save ipstone/4779990b5709a1b7cbdb4e5c2217d735 to your computer and use it in GitHub Desktop.
start interactive job on HPC Helix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Wrapper to run interactive job on helix hpc. | |
# @sbamin | helix | |
# usage | |
show_help() { | |
cat << EOF | |
Start interactive job on Helix: Only one job is allowed at a time. | |
-h display this help and exit | |
-j job name (default: j<random id>_username) | |
-w work directory (default: present work directory) | |
-q job queue (default: interactive) | |
-t walltime in HH:MM:SS (default: 01:00:00, max: 08:00:00) | |
-m memory in gb (default: 8, max: 64) | |
-n number of nodes (default: 1, max: 1) | |
-c cpu cores per node (default: 2, max: 12) | |
-o email notifications (default: a) | |
-e extra options to MSUB (default: none) | |
-d dry run (default: NO, type YES for printing command string but skip requesting interactive queue) | |
Usage: ${0##*/} -c <number of cores> -m <memory in gb> -t <walltime in hh:mm:ss> | |
Example: ${0##*/} -c 2 -m 16 -t 02:00:00 | |
Quote variable names containig spaces and special characters. | |
Bare execution with ${0##*/} will request default interactive job with | |
1 hr walltime, 2 cores and 8gb memory | |
${0##*/} -h for help | |
Add -d YES for dry run, i.e., print qsub interactive command | |
EOF | |
} | |
while getopts "j:w:q:t:m:n:c:o:e:d:h" opt; do | |
case "$opt" in | |
h) show_help;exit 0;; | |
j) JOBNAME=$OPTARG;; | |
w) CWD=$OPTARG;; | |
q) QUEUE=$OPTARG;; | |
t) WALLTIME=$OPTARG;; | |
m) MEMORY=$OPTARG;; | |
n) NODES=$OPTARG;; | |
c) CPU=$OPTARG;; | |
o) EMAILOPTS=$OPTARG;; | |
e) EXTRA_OPTS=$OPTARG;; | |
d) DRYRUN=$OPTARG;; | |
'?')show_help >&2 exit 1 ;; | |
esac | |
done | |
DJOBID=$(printf "j%s_%s" "$RANDOM" "$(whoami)") | |
JOBNAME=${JOBNAME:-$DJOBID} | |
CWD=${CWD:-$(pwd)} | |
QUEUE=${QUEUE:-"interactive"} | |
WALLTIME=${WALLTIME:-"01:00:00"} | |
MEMORY=${MEMORY:-"8gb"} | |
NODES=${NODES:-"1"} | |
CPU=${CPU:-"2"} | |
EMAILOPTS=${EMAILOPTS:-"a"} | |
EXTRA_OPTS=${EXTRA_OPTS:-""} | |
DRYRUN=${DRYRUN:-"NO"} | |
INTCMD=$(printf "qsub -I -V -r y -S /bin/bash -m %s -q %s -l nodes=1:ppn=%s,walltime=%s,mem=%s -d %s %s" "${EMAILOPTS}" "${QUEUE}" "${CPU}" "${WALLTIME}" "${MEMORY}" "${CWD}" "${EXTRA_OPTS}") | |
if [[ ${DRYRUN} != "YES" ]]; then | |
printf "\nRequesting interactive queue using following command:\n\n%s\n\n" "${INTCMD}" | |
sleep 2 | |
## request interactive job | |
eval "${INTCMD}" | |
EXITSTAT=$? | |
TSTAMP=$(date +%d%b%y_%H%M%S%Z) | |
printf "\n\nInteractive job completed at %s with exit status %s\n\n" "${TSTAMP}" "${EXITSTAT}" | |
else | |
printf "\n#### DRY RUN ####\nYou can request interactive queue using following command:\n\n%s\n\n" "${INTCMD}" | |
fi | |
## END ## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment