-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjobsubmissionscript.slurm
More file actions
111 lines (89 loc) · 3.62 KB
/
jobsubmissionscript.slurm
File metadata and controls
111 lines (89 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash -l
# Copyright (c) 2025, Amogh S. Joshi
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# FILENAME: jobsubmissionscript
#SBATCH -A cocosys
#SBATCH --nodes=1
#SBATCH --time=6:00:00
#SBATCH --job-name=%u_%j
#SBATCH --gpus-per-node=1
#SBATCH --output=/home/%u/joboutput/%u_%j.log
#SBATCH --error=/home/%u/joboutput/%u_%j.log
#SBATCH --signal=B:USR1@60
# The sbatch comments above are a special kind of comment that act as arguments to the sbatch command unless superceded by cmd-line args in the launch file.
# DO NOT MODIFY THESE SPECIAL COMMENTS
# signal trap and fwding function. DO NOT MODIFY
# function to fwd SLURM's SIGUSR1 to child process (the user script being executed)
function sig_handler(){
kill -SIGUSR1 $PID
}
# necessary imports
source config_slurm.bash
# handle job renaming for default name jobs
if [[ $SLURM_JOB_NAME == "%u_%j" ]]; then
scontrol update job=$SLURM_JOB_ID JobName=$(whoami)_$SLURM_JOB_ID
fi
# trap SIGUSR1 coming from sbatch and pass to user script
trap 'sig_handler' SIGUSR1
# Print the hostname of the compute node on which this job is running.
echo -e "Hostname: $(/bin/hostname)\n"
# usage help message
usage() {
echo "usage: $0 [-h] [-e ENV_NAME] [-t SCRIPT_TYPE] [-d JOB_SCRIPT_DIR] [-f SCRIPT_FILE]" 1>&2;
echo "-h: Display help message"
echo "-e ENV_NAME: Name of the script's conda environment. Defaults to 'base'"
echo "-t SCRIPT_TYPE: Type of script to execute. Supported values: bash, python. Defaults to 'python'"
echo "-d JOB_SCRIPT_DIR: Absolute path to directory containing the script to be run. Defaults to '${HOME}/rcac-utils'"
echo "-f SCRIPT_FILE: Name of user file to run. Defaults to helloWorld.py"
exit 1;
}
# arg init
ENV_NAME=base
SCRIPT_DIR=$HOME/rcac-utils
SCRIPT_TYPE=python
SCRIPT_FILE=helloWorld.py
# read args
while getopts "he:t:d:f:" opts; do
case "${opts}" in
h) usage;;
e) ENV_NAME=$OPTARG;;
t) SCRIPT_TYPE=$OPTARG;;
d) SCRIPT_DIR=$OPTARG;;
f) SCRIPT_FILE=$OPTARG;;
*) usage;;
esac
done
# necessary init
if [[ $CLUSTER == *"gautschi"* ]]; then
module purge
module load conda
module load cuda
conda activate $ENV_NAME
# The following commands may not be needed as folks on nano rarey use conda. Comment if needed.
else
source $HOME/.bashrc
conda activate $ENV_NAME
fi
# Change to the directory containing job script
cd $SCRIPT_DIR
# actual call to your script (uncomment the desired version, comment the other one)
# version 1: simple call, OS signalling from SLURM not implemented
# $SCRIPT_TYPE $SCRIPT_FILE
# version 2: better call, OS signalling from SLURM enabled (exception catching and handling left to the user)
$SCRIPT_TYPE $SCRIPT_FILE &
PID="$!"
wait "${PID}"