-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
executable file
·150 lines (114 loc) · 3.74 KB
/
run.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
# defaults
readonly DEF_NUM_CPUS=1
readonly DEF_PARTITION=debug
readonly DEF_JOB_NAME=povray
readonly DEF_SCENE=sphere
readonly DEF_FRAMES=600
readonly DEF_POVARGS="+A0.01 -J +W7680 +H4320"
readonly DEF_SLURM_CPUS_PER_TASK=4
######
readonly PROGNAME=$(basename $0)
readonly ARGS="$@"
SCENE=$DEF_SCENE
FRAMES=$DEF_FRAMES
POV_ARGS="$DEF_POVARGS"
SLURM_CPUS_PER_TASK=$DEF_SLURM_CPUS_PER_TASK
function usage() {
cat <<-EOF
usage: $PROGNAME [-c] [-t] [-p] [-J] [-w] [-s] [-f] [-o]
optional arguments:
-c: number of CPU cores to request (default: $DEF_NUM_CPUS)
-t: number of CPU cores per task (default: $DEF_SLURM_CPUS_PER_TASK)
-p: partition to run job in (default: $DEF_PARTITION)
-J: job name (default: $DEF_JOB_NAME)
-s: povray scene (default: $DEF_SCENE)
-f: number of frames (default: $DEF_FRAMES)
-o: povray args (default: $DEF_POVARGS)
-w: node name
written by: Jakob Flierl <[email protected]>
EOF
exit 0
}
function parse_options() {
while getopts ":t:c:p:J:w:s:f:" opt; do
case $opt in
t)
# make sure -t is passed a valid integer
if ! [[ "$OPTARG" =~ ^[0-9]+$ ]]; then
usage
fi
SLURM_CPUS_PER_TASK=$OPTARG
;;
c)
# make sure -c is passed a valid integer
if ! [[ "$OPTARG" =~ ^[0-9]+$ ]]; then
usage
fi
NUM_CPUS=$OPTARG
;;
p)
PARTITION=$OPTARG
;;
J)
JOB_NAME=$OPTARG
;;
w)
NODE_NAME=$OPTARG
;;
s)
SCENE=$OPTARG
;;
f)
FRAMES=$OPTARG
;;
o)
POV_ARGS=$OPTARG
;;
\?|:)
usage
;;
esac
done
}
function envsetup() {
# check to see if user requested a specific number of CPUs
# ... otherwise use the default
if [[ -z $NUM_CPUS ]]; then
NUM_CPUS=$DEF_NUM_CPUS
fi
# set the CPU allocation
SBATCH_OPTS="-n $NUM_CPUS"
SBATCH_OPTS="$SBATCH_OPTS --cpus-per-task $SLURM_CPUS_PER_TASK"
# check for a job name, otherwise use default
SBATCH_OPTS="$SBATCH_OPTS -J ${JOB_NAME:-$DEF_JOB_NAME}"
# see if the user specified a partition, otherwise use default
SBATCH_OPTS="$SBATCH_OPTS -p ${PARTITION:-$DEF_PARTITION}"
# default time for interactive jobs is 8 hours, ~1 working day
SBATCH_OPTS="$SBATCH_OPTS -t 8:00:00"
# if user specifies a node name, run all the tasks in the specified node
if [[ -n "$NODE_NAME" ]]; then
SBATCH_OPTS="$SBATCH_OPTS -w ${NODE_NAME} --ntasks-per-node=$NUM_CPUS"
fi
}
# pass the shell's argument array to the parsing function
parse_options $ARGS
# setup the defaults
envsetup
echo "submitting job $SCENE.pov with $FRAMES frames"
CMD="sbatch --hint=compute_bound $SBATCH_OPTS -O -J $SCENE -a 0-$FRAMES povray.sbatch $SCENE $FRAMES "\'$POV_ARGS\'""
echo " executing: $CMD"
MSG="$($CMD)"
ID=$(echo "$MSG" | awk '{ print $4 }')
JOB=$SCENE-$ID
mkdir -p $JOB
echo " * created povray job $ID in `pwd`/$JOB"
echo "#!/usr/bin/env bash" > $JOB/ffmpeg.sbatch
echo "time nice ffmpeg -y -framerate 60 -pattern_type glob -i '*.png' -c:v libx264 -preset veryslow -qp 0 -r 60 -pix_fmt yuv420p ../$SCENE-$ID.mkv" >> $JOB/ffmpeg.sbatch
CMD="sbatch --hint=compute_bound $SBATCH_OPTS --job-name=ffmpeg --depend=afterok:$ID -D $JOB $JOB/ffmpeg.sbatch"
echo " executing: $CMD"
MSG="$($CMD)"
ID=$(echo "$MSG" | awk '{ print $4 }')
echo " * created ffmpeg job $ID for `pwd`/$JOB"
echo "done"
# EOF