-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_fv3lam.sh
executable file
·268 lines (225 loc) · 6.83 KB
/
run_fv3lam.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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/env bash
function usage {
echo " "
echo " USAGE: $0 [options] [VARDEFNS] task"
echo " "
echo " PURPOSE: Run UFS SRWeather jobs based on ROCOTO workflow file: FV3LAM_wflow.xml "
echo " "
echo " VARDEFNS - var_defns.sh file generated by FV3LAM regional workflow"
echo " default: \"../var_defns.sh\""
echo " task - a task to run, one from (grid, orog, sfc, ics, lbcs, fcst, post)"
echo " "
echo " OPTIONS:"
echo " -h Display this message"
echo " -n Show command to be run only"
echo " -v Verbose mode"
echo " -m odin Machine (odin, stampede or macos)"
echo " default, determine automatically based on hostname."
echo " "
echo " -- By Y. Wang (2020.10.21)"
echo " "
exit $1
}
#-----------------------------------------------------------------------
#
# Default values
#
#-----------------------------------------------------------------------
show=0
verb=0
task=" "
xmlparser="$(dirname $0)/read_xml.py"
VARDEFNS="../var_defns.sh"
host_name=$(hostname)
if [[ $host_name =~ "stampede2" ]]; then
machine="stampede"
elif [[ $host_name =~ "odin" ]]; then
machine="odin"
elif [[ $host_name =~ "4373-Wang-mbp" ]]; then
machine="macos"
else
machine="UNKOWN"
fi
#-----------------------------------------------------------------------
#
# Handle command line arguments
#
#-----------------------------------------------------------------------
while [[ $# > 0 ]]
do
key="$1"
case $key in
-h)
usage 0
;;
-n)
show=1
;;
-v)
verb=1
;;
-m)
machine=$2
shift
;;
-*)
echo "Unknown option: $key"
exit
;;
*)
if [[ -f $key ]]; then
VARDEFNS=$key
elif [[ $key =~ (grid|orog|sfc|ics|lbcs|fcst|post) ]]; then
task=$key
else
echo ""
echo "ERROR: unknown option, get [$key]."
usage -2
fi
;;
esac
shift # past argument or value
done
if [[ ! $task =~ (grid|orog|sfc|ics|lbcs|fcst|post) ]]; then
echo "ERROR: unsupport task - <$task>. Must be one from [grid|orog|sfc|ics|lbcs|fcst|post]."
usage -1
fi
if [[ -f $VARDEFNS ]]; then
echo "VARDEFNS = $VARDEFNS"
else
echo ""
echo "ERROR: cannot find var_defns.sh - <$VARDEFNS>."
usage -2
fi
#-----------------------------------------------------------------------
#
# Definitions
#
#-----------------------------------------------------------------------
VARDEFNS="$(realpath ${VARDEFNS})"
source ${VARDEFNS}
declare -A tasknames queues wrappers
tasknames=(["grid"]="make_grid" ["orog"]="make_orog" \
["sfc"]="make_sfc_climo" ["ics"]="make_ics" \
["lbcs"]="make_lbcs" ["fcst"]="run_fcst" \
["post"]="run_post" )
queues=(["grid"]="${QUEUE_DEFAULT}" ["orog"]="${QUEUE_DEFAULT}" \
["sfc"]="${QUEUE_DEFAULT}" ["ics"]="${QUEUE_DEFAULT}" \
["lbcs"]="${QUEUE_DEFAULT}" ["fcst"]="${QUEUE_FCST}" \
["post"]="${QUEUE_DEFAULT}")
wrappers=(["grid"]="run_make_grid.sh" ["orog"]="run_make_orog.sh" \
["sfc"]="run_make_sfc_climo.sh" ["ics"]="run_make_ics.sh" \
["lbcs"]="run_make_lbcs.sh" ["fcst"]="run_fcst.sh" \
["post"]="run_post.sh" )
#---------------- Decode rocoto XML file -------------------------------
wflow=0
if [[ -f $EXPTDIR/FV3LAM_wflow.xml ]]; then
echo "FV3LAM_wflow = $EXPTDIR/FV3LAM_wflow.xml"
wflow=1
metatask=""
if [[ $task =~ "post" ]]; then
metatask="-m"
fi
resources=$($xmlparser -t ${tasknames[$task]} $metatask -g nodes $EXPTDIR/FV3LAM_wflow.xml)
#echo $resources
nodes=${resources%%:ppn=*}
ppn=${resources##*:ppn=}
numprocess=$(( nodes*ppn ))
walltime=$($xmlparser -t ${tasknames[$task]} $metatask -g walltime $EXPTDIR/FV3LAM_wflow.xml)
queue=${queues[$task]}
else
nodes=1
ppn=4
numprocess=$(( nodes*ppn ))
walltime="3:00:00"
queue="None"
fi
if [[ $verb -eq 1 ]]; then
echo "task = \"$task\", taskname = \"${tasknames[$task]}\""
echo "nodes = \"$nodes\", ppn = \"$ppn\", walltime = \"$walltime\", queue = \"$queue\""
fi
##---------------- Prepare Python environment --------------------------
case $machine in
odin)
read -r -d '' pythonstring <<- EOM
source /scratch/software/Odin/python/anaconda2/etc/profile.d/conda.sh
conda activate regional_workflow
EOM
;;
stampede)
pythonstring="module load python3/3.7.0"
;;
macos)
read -r -d '' pythonstring <<- EOM
source ~/.python
conda activate regional_workflow
EOM
;;
*)
echo "ERROR: unsupported machine - $machine"
usage 0
;;
esac
if [[ $verb -eq 1 ]]; then
echo "machine = \"${machine}\""
fi
##================ Prepare job script ==================================
CODEBASE="${HOMErrfs}"
WRKDIR="${LOGDIR}"
if [[ ! -d $WRKDIR ]]; then
mkdir $WRKDIR
fi
cd $WRKDIR
if [[ $wflow -eq 1 ]]; then
read -r -d '' taskheader <<EOF
#!/bin/sh -l
#SBATCH -A ${ACCOUNT}
#SBATCH -p ${queue}
#SBATCH -J ${tasknames[$task]}
#SBATCH --nodes=${nodes} --ntasks-per-node=${ppn}
#SBATCH --exclusive
#SBATCH -t ${walltime}
#SBATCH -o out.${tasknames[$task]}_%j
#SBATCH -e err.${tasknames[$task]}_%j
${pythonstring}
export EXPTDIR=${EXPTDIR}
EOF
else
read -r -d '' taskheader <<EOF
#!/bin/bash
${pythonstring}
export EXPTDIR=${EXPTDIR}
EOF
fi
##@@@@@@@@@@@@@@@@@@@@@ Submit job script @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
jobscript="${tasknames[$task]}.job"
sed "1d" ${CODEBASE}/ush/wrappers/${wrappers[$task]} > ${jobscript}
echo "$taskheader" | cat - ${jobscript} > temp && mv temp ${jobscript}
if [[ $verb -eq 1 ]]; then
echo "jobscript: $WRKDIR/$jobscript is created."
fi
if [[ $show -eq 1 ]]; then
if [[ $wflow -eq 1 ]]; then
echo "Submit \"$WRKDIR/$jobscript\" manually to run <${tasknames[$task]}>."
else
echo "Execute \"$WRKDIR/$jobscript\" manually to run <${tasknames[$task]}>."
fi
else
if [[ $wflow -eq 1 ]]; then
output=$(sbatch ${jobscript})
echo "${output}"
words=(${output})
jobid=${words[-1]}
echo " "
echo "Logfiles for this job (once started) are:"
echo " ${LOGDIR}/out.${tasknames[$task]}_${jobid}"
echo " ${LOGDIR}/err.${tasknames[$task]}_${jobid}"
echo " "
#touch out.${tasknames[$task]}_${jobid}
#touch err.${tasknames[$task]}_${jobid}
else
chmod +x ${jobscript}
${jobscript} |& ${LOGDIR}/out.${tasknames[$task]}_${jobid}
fi
fi
exit 0