-
Notifications
You must be signed in to change notification settings - Fork 1
/
batch_sub
executable file
·209 lines (196 loc) · 5.07 KB
/
batch_sub
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
#
# Submit a whole bunch of runs at once
usage="batch_sub -stlrdb [-nhepxyz1]\n\n
Following flags to select type of batch job \n
-s submit batch job \n
-t tar runs and send to warwick \n
-l list runs \n
-r restart runs \n
-d delete runs \n
-b basename of runs \n\n
Following flags for submitting: \n
-n number of processors \n
-h number of hours \n
-e equilibrium file \n
-p proffile file \n
-x first index \n
-y second index \n
-z date of runs in format ddMmm \n\n
Use -1 to do dry run"
# Save the command line arguments
str=''
for i in `seq 1 $#`
do
str=${str}":"${!i}
done
cla=`echo $str | tr ":" " "`
# Default arguments
basename=
equname=""
profname=""
N=
SCALE=
date=
nproc=128
hours=1
# Flags for submission script
flags=
# Need to do getopts twice - once for the submission script, once for the batch commands.
# The catch-all (*) option for first getopts will wipe all the flags we don't use first time
# round. So, keep track of flags needed for second getopts
str=
# Get parameters needed to do batch job
while getopts :n:h:v:b:e:p:x:y:z:stlrd1 OPT; do
case $OPT in
# First set of flags are for submission part
n|+n) nproc=$OPTARG
flags="${flags} -n $nproc";;
h|+h) hours=$OPTARG
flags="${flags} -h $hours";;
v|+v) version=$OPTARG
flags="${flags} -v $version";;
e|+e) equname=$OPTARG
# check an equilibrium file has been given
if [[ -z $equname ]]; then
echo "Equilbrium file flag used, but no equilibrium file given"
echo $usage
exit
fi
flags="${flags} -e ${equname}";;
p|+p) profname=$OPTARG
# check a profile file has been given
if [[ -z $profname ]]; then
echo "Profile file flag used, but no profile file given"
echo $usage
exit
fi
flags="${flags} -p $profname";;
# Next set of flags are for batch part
b|+b) basename=$OPTARG;;
x|+x) N=$OPTARG;;
y|+y) SCALE=$OPTARG;;
z|+z) date=$OPTARG;;
# Next set of flags are for batch commands - used in second getopts later
s) str=${str}s;;
t) str=${str}t;;
l) str=${str}l;;
r) str=${str}r;;
d) str=${str}d;;
1) str=${str}"1";;
# Help and catch-all
\? ) echo -e $usage
exit 1;;
: ) echo "Option -$OPTARG requires an argument." >&2
echo -e $usage
exit 1;;
*) echo -e $usage
# echo "usage: ${0##*/} [+-nhbepxy} [--] ARGS..."
exit 2;;
esac
done
shift $(( OPTIND - 1 ))
OPTIND=1
# Make sure basename has been set
if [[ -z $basename ]]; then
echo "Missing basename. "
echo -e $usage
exit
fi
# WARNING! Will need to change this part if format of basename/scan is different
# Make list of filenames
FILENAME=`for n in $N; do
for scale in $SCALE; do
echo -n "${basename}_n${n}_scale_${scale} "
done
done`
# Select and run batch job
while getopts :n:h:b:e:p:x:y:z:stlrd1 OPT "-${str}"; do
case $OPT in
s|+s)# Submit
echo "submit!"
for filename in $FILENAME
do
echo "subnemo -i ${filename} ${flags}"
subnemo -i ${filename} ${flags}
done
;;
t|+t)# Tar up jobs and scp them to Warwick
echo "tar!"
# Need to have a file to create tarball in first place
touch fish_food
# Name of tarball - .tgz extension is tar + gzip
tarname=${basename}_${date}.tar
tar -cf ${tarname} fish_food
# Add the input file, hdf5 output and STD_OUT file to tarball
for filename in $FILENAME
do
dirname=${filename}_${date}*
tar -rvf ${tarname} ${dirname}/input ${dirname}/orb5_res.h5 ${dirname}/hpcff_nemorb_${version}.o
done
rm fish_food
# Show the filesize of the tarball before sending it
ls -Alh ${tarname}
notify-send "ENTER PASSWORD FOR SCP" &
scp ${tarname} [email protected]:/storage/space2/phrebb/nemo/runs/$(date +%b%Y)/ && notify-send "Finished scp" || notify-send "scp broke"
;;
r|+r)# Restart
echo "restart!"
for filename in $FILENAME
do
dirname=${filename}_${date}*
cd ${WORK}/${dirname}
sed -i 's/\(nlres[ ]*=[ ]*\)f/\1t/' input
msub ${filename}.pbs
done
;;
l|+l)# List directories conforming to the given template
echo "list!"
for filename in $FILENAME
do
echo "looking for: " $filename
ls | grep ${filename}
done
;;
d|+d)# Delete directories
echo "delete!"
for filename in $FILENAME
do
echo ${filename}_${date}*
rm -r ${filename}_${date}*
done
;;
1) # Dry run - print out lots of info!
echo "Dry run!"
for filename in $FILENAME
do
# List directories/filenames
dirname=${filename}_${date}*
echo $filename
cd ${WORK}/${dirname}
pwd
# List .pbs files needed for restart and show what would be changed for restart
echo -n ".pbs file: "
ls ${filename}.pbs
sed -n 's/\(nlres[ ]*=[ ]*\)f/\1t/p' input
# How would submission script be called
echo "subnemo -i ${filename} ${flags}"
done
;;
# Already sorted these above, but need to preserve them from the catch-all
n|+n);;
h|+h);;
b|+b);;
e|+e);;
p|+p);;
x|+x);;
y|+y);;
z|+z);;
*)
echo $OPTARG
echo -e $usage #"usage: ${0##*/} [+-stlr} [--] ARGS..."
exit 2;;
esac
done
shift $(( OPTIND - 1 ))
OPTIND=1