forked from jmccreight/wrfHydroScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanRun.sh
More file actions
executable file
·206 lines (183 loc) · 4.99 KB
/
cleanRun.sh
File metadata and controls
executable file
·206 lines (183 loc) · 4.99 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
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
#!/bin/bash
help="
cleanRun.sh :: help
Purpose: clean up WRF-Hydro output in the current directory and
start a new run. Optionally create/cleanup a specified directory
and run there. ASSUMES that the model is wrf_hydro.exe in calling
directory.
Options:
Those taken by cleanup (-r) and linkToTestCase (-fpunc). The later
are onlyPassed to linkToTestCase when the optional second argument
is used to establish a run directory.
Arguments:
1) The number of mpi tasks (processors)
2) OPTIONAL A directory for the run. This ASSUMES the script
is called from a run directory. NOTE THAT THIS CAN BECOME
A MESS IF DIRECTORIES ABOVE THE RUN DIRECTORY ARE REFERENCED
IN THE NAMELIST. The suggestion is to have all namelist
dependencies in ./ instead of ../ which can be achieved
by symlinking ../dep to ./dep. The intent of creating run
directories here is so that multiple runs can be happening
simultaneously for the same domain.
3) OPTIONAL The binary to use, will be copied to run directory.
Note:
There is a special section to detect the correct build of mpi,
which is likely to cause others issues at some point.
"
## options are just passed to linkToTestCase.sh
## Wish there were an easier way to do this other than copy the code.
fOpt=''
pOpt=''
uOpt=''
nOpt=''
cOpt=''
dOpt=''
oOpt=''
rOpt=''
while getopts ":fpuncdor" opt; do
case $opt in
u)
uOpt="-u"
;;
c)
cOpt="-c"
;;
f)
fOpt="-f"
;;
d)
dOpt="-d"
;;
o)
dOpt="-o"
;;
n)
nOpt="-n"
;;
p)
pOpt="-p"
;;
r)
rOpt="-r"
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
;;
esac
done
shift "$((OPTIND-1))" # Shift off the options and optional
whsPath=`grep "wrfHydroScripts" ~/.wrfHydroScripts | cut -d '=' -f2 | tr -d ' '`
numProc=`nproc`
numProc=`echo "$numProc/2" | bc`
## first argument is required: the number of mpi tasks
if [ ! -z "$1" ]
then
nMpiTasks=$1
if [ ! "$nMpiTasks" -gt 0 ] && [ ! "$nMpiTasks" -le "$numProc" ]
then
echo 'Unacceptable value for number of processors.'
echo "Please use a value in 1-${numProc}"
echo "(Script currently assumes a multithreading which reports"
echo " actual number of processors*2, may need change for your machine."
exit 1
fi
else
echo "Please specify the number of mpi tasks mpirun. $help"
exit 1
fi
## second and third arguments are optional: a run directory and/or a binary
## set a default (rather than complicated logic)
theBinary=wrf_hydro.exe
rundir=''
if [ ! -z "$2" ]
then
## was there a binary passed? Which argument?
checkBinary=`ldd $2`
if [ $? -eq 0 ]
then
## the second argument is the binary
theBinary=$2
if [ ! -z "$3" ]; then runDir=$3; fi
else
## if there's a third argument
if [ ! -z "$3" ]
then
checkBinary=`ldd $3`
if [ $? -eq 0 ]
then
theBinary=$3
else
echo -e "\e[31mNeither argument 2 nor 3 is a valid binary. Please check."
exit 1
fi
runDir=$2
fi
fi
fi
## now deal with the run directory
if [ ! -z $runDir ]
then
if [ ! -d $runDir ]
then
mkdir -p $runDir
if [ ! $? -eq 0 ]
then
echo -e "\e[31mProblems creating run dir:\e[0m $runDir"
exit 1
fi
fi
## clean up the run directory BEFORE linking to restarts
origDir=`pwd`
cd $runDir
$whsPath/cleanup.sh $rOpt
cd $origDir
## setup the new run directory
$whsPath/linkToTestCase.sh \
$cOpt $fOpt $oOpt $dOpt $uOpt $nOpt $pOpt . `pwd` `pwd`/$runDir
origDir=`pwd`
cd $runDir
## always copy the binary
cp $origDir/$theBinary .
else
$whsPath/cleanup.sh $rOpt
fi
## potentially different invocations of mpirun.
## deal with host differences: put your flavor here
theHost=`hostname`
## YELLOWSTONE
if [[ $theHost == *"ys"* ]]
then
echo "Running on yellowstone!"
mpirun.lsf ./$theBinary
fi
## HYDRO-C1
if [[ $theHost == *"hydro-c1"* ]]
then
## a check for the ifort versus the pg compiler
useIfort=`ldd $theBinary | grep ifort | wc -l`
if [ ! $? -eq 0 ]
then
echo -e "\e[31mProblems with executable:\e[0m wrf_hydro.exe"
exit 1
fi
if [ "$useIfort" -gt 0 ]
then
echo -e "\e[31mDetected intel fortran binary\e[0m"
MPIRUN="/opt/openmpi-1.10.0-intel/bin/mpirun --prefix /opt/openmpi-1.10.0-intel"
else
MPIRUN=mpirun
fi
echo "$MPIRUN -np $nMpiTasks ./$theBinary"
$MPIRUN -np $nMpiTasks ./$theBinary
fi
## MPI return
mpiReturn=$?
echo -e "\e[36mReturn code: $mpiReturn\e[0m"
## THis dosent work under qsub because stdout/err arent written untill after the job completes.
if [ ! -z $cleanRunDateId ]
then
cd $origDir
mv ${cleanRunDateId}.* ${runDir}/.
fi
exit $mpiReturn