forked from mabarnes/moment_kinetics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit-restart.sh
executable file
·130 lines (116 loc) · 3.69 KB
/
submit-restart.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
set -e
# job settings for the run
##########################
# Get setup for Julia
source julia.env
JOBINFO=($(util/get-job-info.jl))
MACHINE=${JOBINFO[0]}
ACCOUNT=${JOBINFO[1]}
RUNTIME=${JOBINFO[2]}
NODES=${JOBINFO[3]}
POSTPROCTIME=${JOBINFO[4]}
POSTPROCMEMORY=${JOBINFO[5]}
PARTITION=${JOBINFO[6]}
QOS=${JOBINFO[7]}
# Parse command line options
# [See e.g. https://www.stackchief.com/tutorials/Bash%20Tutorial%3A%20getopts
# for examples of how to use Bash's getopts]
POSTPROC=0
SUBMIT=0
RESTARTFROM=""
FOLLOWFROM=""
MAKIEPOSTPROCESS=1
while getopts "haf:m:n:p:oq:r:st:u:" opt; do
case $opt in
h)
echo "Submit jobs for a simulation (using INPUT_FILE for input) and post-processing to the queue
Usage: submit-run.sh [option] INPUT_FILE
-h Print help and exit
-a Do not submit post-processing job after the run
-f JOBID Make this job start after JOBID finishes successfully
-m MEM The requested memory for post-processing
-n NODES The number of nodes to use for the simulation
-o Use original post_processing, instead of makie_post_processing, for the post-processing job
-p PARTITION The 'partition' (passed to 'sbatch --partition')
-q QOS The 'quality of service' (passed to 'sbatch --qos')
-r FILE The output file to restart from (defaults to latest output in the run directory)
-s Only create submission scripts, do not actually submit jobs
-t TIME The run time, e.g. 24:00:00
-u TIME The run time for the post-processing, e.g. 1:00:00"
exit 1
;;
a)
POSTPROC=1
;;
f)
FOLLOWFROM="-d afterok:$OPTARG"
;;
m)
POSTPROCMEM=$OPTARG
;;
n)
NODES=$OPTARG
;;
o)
MAKIEPOSTPROCESS=0
;;
p)
PARTITION=$OPTARG
;;
q)
QOS=$OPTARG
;;
r)
RESTARTFROM=$OPTARG
;;
s)
SUBMIT=1
;;
t)
RUNTIME=$OPTARG
;;
u)
POSTPROCTIME=$OPTARG
;;
esac
done
# Get the positional argument as INPUTFILE
# [See https://stackoverflow.com/a/13400237]
INPUTFILE=${@:$OPTIND:1}
if [ -z "$INPUTFILE" ]; then
echo "No input file passed - must pass an input file name as a positional argument"
exit 1
fi
RUNNAME=$(util/get-run-name.jl $INPUTFILE)
RUNDIR=runs/$RUNNAME/
mkdir -p $RUNDIR
if [[ $POSTPROC -eq 0 ]]; then
echo "Submitting $INPUTFILE for restart from '$RESTARTFROM' and post-processing..."
else
echo "Submitting $INPUTFILE for restart from '$RESTARTFROM'..."
fi
# Create a submission script for the run
RESTARTJOBSCRIPT=${RUNDIR}$RUNNAME-restart.job
sed -e "s|NODES|$NODES|" -e "s|RUNTIME|$RUNTIME|" -e "s|ACCOUNT|$ACCOUNT|" -e "s|PARTITION|$PARTITION|" -e "s|QOS|$QOS|" -e "s|RUNDIR|$RUNDIR|" -e "s|INPUTFILE|$INPUTFILE|" -e "s|RESTARTFROM|$RESTARTFROM|" machines/$MACHINE/jobscript-restart.template > $RESTARTJOBSCRIPT
if [[ $SUBMIT -eq 0 ]]; then
JOBID=$(sbatch $FOLLOWFROM --parsable $RESTARTJOBSCRIPT)
echo "Restart: $JOBID"
echo "In the queue" > ${RUNDIR}slurm-$JOBID.out
fi
if [[ $POSTPROC -eq 0 ]]; then
# Create a submission script for post-processing
POSTPROCJOBSCRIPT=${RUNDIR}$RUNNAME-post.job
if [[ MAKIEPOSTPROCESS -eq 1 ]]; then
POSTPROCESSTEMPLATE=jobscript-postprocess.template
else
POSTPROCESSTEMPLATE=jobscript-postprocess-plotsjl.template
fi
sed -e "s|POSTPROCMEMORY|$POSTPROCMEMORY|" -e "s|POSTPROCTIME|$POSTPROCTIME|" -e "s|ACCOUNT|$ACCOUNT|" -e "s|RUNDIR|$RUNDIR|" machines/$MACHINE/$POSTPROCESSTEMPLATE > $POSTPROCJOBSCRIPT
if [[ $SUBMIT -eq 0 ]]; then
POSTID=$(sbatch -d afterany:$JOBID --parsable $POSTPROCJOBSCRIPT)
echo "Postprocess: $POSTID"
echo "In the queue" > ${RUNDIR}slurm-post-$POSTID.out
fi
fi
echo "Done"