1 |
edhill |
1.19 |
#! /usr/bin/env bash |
2 |
edhill |
1.1 |
# |
3 |
edhill |
1.27 |
# $Header: $ |
4 |
edhill |
1.12 |
# $Name: $ |
5 |
edhill |
1.1 |
# |
6 |
|
|
|
7 |
|
|
usage() |
8 |
|
|
{ |
9 |
|
|
echo |
10 |
|
|
echo "Usage: $0 [OPTIONS]" |
11 |
|
|
echo |
12 |
|
|
echo "where possible OPTIONS are:" |
13 |
|
|
echo " (-help|-h) print usage" |
14 |
edhill |
1.7 |
echo " (-mpi) use MPI input files" |
15 |
edhill |
1.10 |
echo " (-ieee|-noieee) if possible, use IEEE compiler flags" |
16 |
edhill |
1.20 |
echo " (DEF=\"noieee\")" |
17 |
edhill |
1.6 |
echo " (-optfile=|-of=)STRING list of optfiles to use" |
18 |
edhill |
1.20 |
echo " (-a|-addr) STRING list of email recipients" |
19 |
edhill |
1.6 |
echo " (DEF=\"edhill@mitgcm.org\")" |
20 |
edhill |
1.20 |
echo " (-t|-tdir) STRING list of test dirs to use" |
21 |
edhill |
1.6 |
echo " (DEF=\"\" which builds all)" |
22 |
edhill |
1.20 |
echo " (-b|-bash) STRING preferred location of a \"bash\" or" |
23 |
|
|
echo " Bourne-compatible \"sh\" shell" |
24 |
|
|
echo " (DEF=\"\" for \"bash\")" |
25 |
edhill |
1.24 |
echo " (-adm|-ad) perform an adjoint run" |
26 |
edhill |
1.20 |
echo " (-command) STRING command to run" |
27 |
edhill |
1.6 |
echo " (DEF=\"make output.txt\")" |
28 |
edhill |
1.20 |
echo " (-m|-make) STRING command to use for \"make\"" |
29 |
edhill |
1.8 |
echo " (DEF=\"make\")" |
30 |
edhill |
1.10 |
echo " (-clean) *ONLY* run \"make CLEAN\"" |
31 |
|
|
echo " (-quick|-q) same as \"-nogenmake -noclean -nodepend\"" |
32 |
|
|
echo " (-nogenmake|-ng) skip the genmake stage" |
33 |
|
|
echo " (-noclean|-nc) skip the \"make clean\" stage" |
34 |
|
|
echo " (-nodepend|-nd) skip the \"make depend\" stage" |
35 |
edhill |
1.6 |
echo |
36 |
|
|
echo "and where STRING follows a whitespace-delimited format" |
37 |
|
|
echo "such as:" |
38 |
|
|
echo " -t 'exp0 exp2 exp3' " |
39 |
|
|
echo " -addr='abc@123.com testing@home.org'" |
40 |
edhill |
1.1 |
echo |
41 |
|
|
exit 1 |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
# build the mpack utility |
45 |
|
|
build_mpack() |
46 |
|
|
{ |
47 |
|
|
echo -n "building the mpack utility... " |
48 |
|
|
if test ! -x "$MPACKDIR/mpack" ; then |
49 |
|
|
if test ! -d $MPACKDIR ; then |
50 |
edhill |
1.20 |
echo |
51 |
edhill |
1.1 |
echo "Error: can't find \"$MPACKDIR\"" |
52 |
|
|
echo " are you sure this program is being run in the correct " |
53 |
|
|
echo " (that is, \"MITGCM_ROOT\verification\") directory?" |
54 |
edhill |
1.20 |
echo |
55 |
|
|
HAVE_MPACK=f |
56 |
edhill |
1.1 |
fi |
57 |
|
|
echo -n "building mpack... " |
58 |
edhill |
1.26 |
if test "x$CC" = x ; then |
59 |
|
|
export CC=cc |
60 |
|
|
fi |
61 |
edhill |
1.25 |
( cd $MPACKDIR && ./configure && $MAKE ) > tr_build_mpack.out 2>&1 |
62 |
edhill |
1.1 |
RETVAL=$? |
63 |
|
|
if test "x$RETVAL" != x0 ; then |
64 |
|
|
echo |
65 |
|
|
echo "Error building the mpack tools at: $MPACK_DIR" |
66 |
edhill |
1.20 |
echo |
67 |
|
|
HAVE_MPACK=f |
68 |
|
|
else |
69 |
edhill |
1.25 |
rm -f tr_build_mpack.out |
70 |
edhill |
1.20 |
HAVE_MPACK=t |
71 |
edhill |
1.1 |
fi |
72 |
edhill |
1.20 |
else |
73 |
|
|
HAVE_MPACK=t |
74 |
edhill |
1.1 |
fi |
75 |
|
|
echo "OK" |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
testoutput_for_prop() |
79 |
|
|
{ |
80 |
|
|
# testoutput_for_prop dir s1 label subdir |
81 |
|
|
# |
82 |
|
|
# compares files in $dir/$subdir/output.txt and $dir/results/output.txt |
83 |
|
|
# using search strings s1 and text label |
84 |
|
|
|
85 |
|
|
if [ $debug -gt 0 ]; then |
86 |
|
|
echo testoutput_for_prop: grep "$2" $1/$4/output.txt 1>&2 |
87 |
|
|
fi |
88 |
|
|
if [ -r $1/$4/output.txt ]; then |
89 |
edhill |
1.15 |
grep "$2" $1/$4/output.txt | sed 's/.*=//' | cat -n > tmp1.txt |
90 |
edhill |
1.1 |
lncnt=`wc -l tmp1.txt | awk '{print $1}' ` |
91 |
|
|
if [ $lncnt -lt 3 ]; then |
92 |
|
|
if [ $verbose -gt 0 ]; then |
93 |
|
|
echo Not enough lines of output when searching for "$2" 1>&2 |
94 |
|
|
fi |
95 |
|
|
return 99 |
96 |
|
|
fi |
97 |
|
|
else |
98 |
|
|
echo testoutput_for_prop: output.txt from model run was not readable 1>&2 |
99 |
|
|
return 99 |
100 |
|
|
fi |
101 |
|
|
if [ $debug -gt 0 ]; then |
102 |
|
|
echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2 |
103 |
|
|
fi |
104 |
edhill |
1.15 |
grep "$2" $1/results/output.txt | sed 's/.*=//' | cat -n > tmp2.txt |
105 |
edhill |
1.1 |
lncnt=`wc -l tmp2.txt | awk '{print $1}' ` |
106 |
|
|
if [ $lncnt -lt 3 ]; then |
107 |
|
|
if [ $verbose -gt 0 ]; then |
108 |
|
|
echo Not enough lines of output when searching for "$2" 1>&2 |
109 |
|
|
fi |
110 |
|
|
return 99 |
111 |
|
|
fi |
112 |
|
|
if [ $debug -gt 0 ]; then |
113 |
|
|
echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2 |
114 |
|
|
fi |
115 |
|
|
join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt |
116 |
|
|
if [ $debug -gt 0 ]; then |
117 |
|
|
echo testoutput_for_prop: compare_lines 1>&2 |
118 |
|
|
fi |
119 |
edhill |
1.22 |
if [ $verbose -gt 1 ]; then |
120 |
|
|
cat tmp3.txt 1>&2 |
121 |
|
|
fi |
122 |
|
|
echo "-1" >> tmp3.txt |
123 |
edhill |
1.23 |
# On the SGI O3K (*not* the O2K), "cat -n" inserts a ":" after the line number |
124 |
|
|
cat tmp3.txt | sed -e 's|:||g' > tmp4.txt |
125 |
|
|
digits_of_similarity=`./tmp_cmpnum < tmp4.txt` |
126 |
edhill |
1.1 |
if [ $digits_of_similarity -eq 99 ]; then |
127 |
|
|
if [ $verbose -gt 0 ]; then |
128 |
|
|
echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2 |
129 |
|
|
fi |
130 |
|
|
digits_of_similarity=99 |
131 |
|
|
else |
132 |
|
|
if [ $verbose -gt 0 ]; then |
133 |
|
|
echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2 |
134 |
|
|
fi |
135 |
|
|
fi |
136 |
edhill |
1.23 |
rm -f tmp1.txt tmp2.txt tmp3.txt tmp4.txt |
137 |
edhill |
1.1 |
|
138 |
|
|
return $digits_of_similarity |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
dashnum() |
142 |
|
|
{ |
143 |
|
|
# dashnum n1 n2 n3 ... |
144 |
|
|
# |
145 |
|
|
# print numbers using %3i format or "--" if number = 99 |
146 |
|
|
|
147 |
|
|
for num in $@ ; do |
148 |
|
|
if [ $num = 99 ]; then |
149 |
|
|
printf ' --' |
150 |
|
|
else |
151 |
|
|
printf '%3i' $num |
152 |
|
|
fi |
153 |
|
|
done |
154 |
|
|
} |
155 |
|
|
|
156 |
edhill |
1.24 |
testoutput_ad() |
157 |
|
|
{ |
158 |
|
|
grep $3 $1/results_ad/output.txt_adm | awk '{print NR " " $5}' > t05.txt |
159 |
|
|
grep $3 $1/$2/output.txt_adm | awk '{print NR " " $5}' > t15.txt |
160 |
|
|
grep $3 $1/results_ad/output.txt_adm | awk '{print NR " " $6}' > t06.txt |
161 |
|
|
grep $3 $1/$2/output.txt_adm | awk '{print NR " " $6}' > t16.txt |
162 |
|
|
join t05.txt t15.txt > t5.txt |
163 |
|
|
join t06.txt t16.txt > t6.txt |
164 |
|
|
echo "-1" >> t5.txt |
165 |
|
|
echo "-1" >> t6.txt |
166 |
|
|
digits_5=`./tmp_cmpnum < t5.txt` |
167 |
|
|
digits_6=`./tmp_cmpnum < t6.txt` |
168 |
|
|
dashnum $digits_5 $digits_6 |
169 |
|
|
rm -f t[01][56].txt t[56].txt |
170 |
|
|
} |
171 |
|
|
|
172 |
edhill |
1.1 |
testoutput() |
173 |
|
|
{ |
174 |
edhill |
1.24 |
# testoutput directory subdir |
175 |
edhill |
1.1 |
# |
176 |
|
|
# test output in "directory" |
177 |
edhill |
1.24 |
if test "x$ADM" = x ; then |
178 |
|
|
if [ $debug -gt 0 ]; then |
179 |
|
|
echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2 |
180 |
|
|
fi |
181 |
|
|
testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual" $2; cg2dres=$? |
182 |
|
|
if [ $debug -gt 0 ]; then |
183 |
|
|
echo testoutput: cg2dres=$cg2dres 1>&2 |
184 |
|
|
fi |
185 |
|
|
testoutput_for_prop $1 "dynstat_theta_min" "theta minimum" $2; tmin=$? |
186 |
|
|
testoutput_for_prop $1 "dynstat_theta_max" "theta maximum" $2; tmax=$? |
187 |
|
|
testoutput_for_prop $1 "dynstat_theta_mean" "theta mean" $2; tmean=$? |
188 |
|
|
testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d." $2; tsd=$? |
189 |
|
|
testoutput_for_prop $1 "dynstat_salt_min" "salt minimum" $2; smin=$? |
190 |
|
|
testoutput_for_prop $1 "dynstat_salt_max" "salt maximum" $2; smax=$? |
191 |
|
|
testoutput_for_prop $1 "dynstat_salt_mean" "salt mean" $2; smean=$? |
192 |
|
|
testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d." $2; ssd=$? |
193 |
|
|
testoutput_for_prop $1 "dynstat_uvel_min" "U minimum" $2; umin=$? |
194 |
|
|
testoutput_for_prop $1 "dynstat_uvel_max" "U maximum" $2; umax=$? |
195 |
|
|
testoutput_for_prop $1 "dynstat_uvel_mean" "U mean" $2; umean=$? |
196 |
|
|
testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d." $2; usd=$? |
197 |
|
|
testoutput_for_prop $1 "dynstat_vvel_min" "V minimum" $2; vmin=$? |
198 |
|
|
testoutput_for_prop $1 "dynstat_vvel_max" "V maximum" $2; vmax=$? |
199 |
|
|
testoutput_for_prop $1 "dynstat_vvel_mean" "V mean" $2; vmean=$? |
200 |
|
|
testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d." $2; vsd=$? |
201 |
|
|
dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \ |
202 |
|
|
$umin $umax $umean $usd $vmin $vmax $vmean $vsd |
203 |
|
|
else |
204 |
|
|
testoutput_ad $1 $2 "precision_grdchk_result" |
205 |
edhill |
1.1 |
fi |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
genmakemodel() |
209 |
|
|
{ |
210 |
|
|
# genmakemodel directory |
211 |
edhill |
1.10 |
if test "x$NOGENMAKE" = xt ; then |
212 |
|
|
echo "genmake skipped!" |
213 |
|
|
else |
214 |
|
|
GENMAKE2="$BASH ../../../tools/genmake2" |
215 |
|
|
( |
216 |
|
|
cd $1; |
217 |
edhill |
1.24 |
command="$GENMAKE2 -ds -m $MAKE" |
218 |
|
|
if test "x$ADM" = x ; then |
219 |
|
|
command="$command --mods=../code" |
220 |
|
|
else |
221 |
|
|
command="$command --mods=../code_ad" |
222 |
|
|
command="$command -adof=../../../tools/adjoint_options/adjoint_staf" |
223 |
|
|
fi |
224 |
edhill |
1.10 |
if test "x$OPTFILE" != xNONE ; then |
225 |
|
|
command="$command --optfile=$OPTFILE" |
226 |
|
|
fi |
227 |
|
|
if test "x$IEEE" != x ; then |
228 |
|
|
command="$command -ieee" |
229 |
|
|
fi |
230 |
|
|
printf 'genmake ... ' 1>&2 |
231 |
|
|
$command > make.log 2>&1 |
232 |
|
|
RETVAL=$? |
233 |
edhill |
1.21 |
cp Makefile $CDIR |
234 |
edhill |
1.10 |
if test "x$RETVAL" != x0 ; then |
235 |
|
|
tail make.log |
236 |
|
|
echo "genmakemodel: genmake failed" 1>&2 |
237 |
edhill |
1.21 |
cp genmake_* make.log $CDIR |
238 |
edhill |
1.10 |
return 1 |
239 |
|
|
else |
240 |
edhill |
1.20 |
echo "successful" 1>&2 |
241 |
edhill |
1.1 |
fi |
242 |
edhill |
1.10 |
) |
243 |
|
|
fi |
244 |
edhill |
1.1 |
} |
245 |
|
|
|
246 |
|
|
makeclean() |
247 |
|
|
{ |
248 |
|
|
# makeclean directory |
249 |
edhill |
1.10 |
if test "x$NOCLEAN" = xt ; then |
250 |
|
|
echo "make CLEAN skipped!" |
251 |
|
|
else |
252 |
|
|
( |
253 |
|
|
cd $1; |
254 |
|
|
if test -e output.txt ; then |
255 |
|
|
rm -f output.txt |
256 |
|
|
fi |
257 |
|
|
printf 'make CLEAN ... ' 2>&1 |
258 |
|
|
if test -r Makefile ; then |
259 |
|
|
$MAKE CLEAN >> make.log 2>&1 |
260 |
|
|
RETVAL=$? |
261 |
|
|
if test "x$RETVAL" != x0 ; then |
262 |
|
|
tail make.log |
263 |
|
|
echo "makeclean: \"make CLEAN\" failed" 1>&2 |
264 |
|
|
cp make.log $CDIR"/make.log" |
265 |
|
|
return 1 |
266 |
|
|
fi |
267 |
|
|
fi |
268 |
edhill |
1.20 |
echo successful 1>&2 |
269 |
edhill |
1.10 |
exit 0 |
270 |
|
|
) |
271 |
|
|
fi |
272 |
|
|
} |
273 |
|
|
|
274 |
|
|
makedependmodel() |
275 |
|
|
{ |
276 |
|
|
# makedependmodel directory |
277 |
|
|
if test "x$NODEPEND" = xt ; then |
278 |
|
|
echo "make depend skipped!" |
279 |
|
|
else |
280 |
|
|
( |
281 |
|
|
cd $1; |
282 |
|
|
printf 'make depend ... ' 1>&2 |
283 |
|
|
$MAKE depend >> make.log 2>&1 |
284 |
edhill |
1.1 |
RETVAL=$? |
285 |
|
|
if test "x$RETVAL" != x0 ; then |
286 |
|
|
tail make.log |
287 |
edhill |
1.10 |
echo "makedependmodel: make depend failed" 1>&2 |
288 |
edhill |
1.1 |
cp make.log $CDIR"/make.log" |
289 |
|
|
return 1 |
290 |
edhill |
1.10 |
else |
291 |
edhill |
1.20 |
echo successful 1>&2 |
292 |
edhill |
1.1 |
fi |
293 |
edhill |
1.10 |
) |
294 |
|
|
fi |
295 |
edhill |
1.1 |
} |
296 |
|
|
|
297 |
|
|
makemodel() |
298 |
|
|
{ |
299 |
|
|
# makemodel directory |
300 |
|
|
( |
301 |
|
|
cd $1; |
302 |
|
|
if test -r Makefile ; then |
303 |
|
|
printf 'make ... ' 1>&2 |
304 |
edhill |
1.24 |
if test "x$ADM" = x ; then |
305 |
|
|
$MAKE >> make.log 2>&1 |
306 |
|
|
else |
307 |
|
|
$MAKE adall >> make.log 2>&1 |
308 |
|
|
fi |
309 |
edhill |
1.1 |
RETVAL=$? |
310 |
|
|
if test "x$RETVAL" != x0 ; then |
311 |
|
|
tail make.log |
312 |
|
|
echo failed 1>&2 |
313 |
|
|
cp make.log $CDIR"/make.log" |
314 |
|
|
return 1 |
315 |
|
|
else |
316 |
edhill |
1.20 |
echo successful 1>&2 |
317 |
edhill |
1.1 |
fi |
318 |
|
|
fi |
319 |
|
|
) |
320 |
|
|
} |
321 |
|
|
|
322 |
edhill |
1.27 |
symlink_mpifiles() |
323 |
|
|
{ |
324 |
|
|
# Put special links so that MPI specific files are used |
325 |
|
|
# This MUST be invoked between makeclean and makelinks because |
326 |
|
|
# the Makefile will link to non-mpi files by default |
327 |
|
|
|
328 |
|
|
dir=$1 |
329 |
|
|
code_dir=$2 |
330 |
|
|
BUILD_DIR=$dir/$3 |
331 |
|
|
CODE_DIR=$dir/$code_dir |
332 |
|
|
|
333 |
|
|
# These are files that should replace their counter-part when using -mpi |
334 |
|
|
MPI_FILES=`(cd $CODE_DIR; find . -name "*_mpi")` |
335 |
|
|
|
336 |
|
|
# Is this an MPI run? |
337 |
|
|
if test "x$MPI" = xt ; then |
338 |
|
|
# YES: We symbolically link these files to the build |
339 |
|
|
# dir so long as there is no real file in place |
340 |
|
|
for ii in $MPI_FILES ; do |
341 |
|
|
i=`echo $ii | sed 's:^\./::'` |
342 |
|
|
name=`echo $i | sed 's:_mpi::' ` |
343 |
|
|
cmp $CODE_DIR/$i $BUILD_DIR/$name > /dev/null 2>&1 |
344 |
|
|
RETVAL=$? |
345 |
|
|
if test "x$RETVAL" != x0 ; then |
346 |
|
|
if ! test -f $BUILD_DIR/$i ; then |
347 |
|
|
#echo Linking $name to $i |
348 |
|
|
(cd $BUILD_DIR; ln -sf ../$code_dir/$i $name) |
349 |
|
|
fi |
350 |
|
|
fi |
351 |
|
|
done |
352 |
|
|
else |
353 |
|
|
# NO: We undo any _mpi symbolically linked files |
354 |
|
|
for ii in $MPI_FILES ; do |
355 |
|
|
i=`echo $ii | sed 's:^\./::'` |
356 |
|
|
name=`echo $i | sed 's:_mpi::' ` |
357 |
|
|
if test -L $BUILD_DIR/$name ; then |
358 |
|
|
linktarg=`(cd $BUILD_DIR; readlink $name)` |
359 |
|
|
if test $linktarg = "../$code_dir/$name"_mpi ; then |
360 |
|
|
#echo Un-linking $name from $linktarg |
361 |
|
|
rm -f $BUILD_DIR/$name |
362 |
|
|
fi |
363 |
|
|
fi |
364 |
|
|
done |
365 |
|
|
fi |
366 |
|
|
|
367 |
|
|
} |
368 |
|
|
|
369 |
edhill |
1.1 |
linkdata() |
370 |
|
|
{ |
371 |
|
|
# linkdata flag |
372 |
|
|
# |
373 |
|
|
# symbolically link data files to run directory |
374 |
edhill |
1.12 |
if test "x$1" = x1 ; then |
375 |
|
|
( |
376 |
|
|
cd $2 |
377 |
edhill |
1.24 |
if test "x$ADM" = x ; then |
378 |
|
|
files=`( cd ../input ; ls -1 | grep -v CVS )` |
379 |
|
|
for i in $files ; do |
380 |
|
|
if test ! -d "../input/"$i ; then |
381 |
|
|
ln -sf "../input/"$i $i |
382 |
|
|
fi |
383 |
|
|
done |
384 |
|
|
else |
385 |
|
|
files=`( cd ../input ; ls -1 *.bin | grep -v CVS )` |
386 |
|
|
for i in $files ; do |
387 |
|
|
if test ! -d "../input/"$i ; then |
388 |
|
|
ln -sf "../input/"$i $i |
389 |
|
|
fi |
390 |
|
|
done |
391 |
|
|
files=`( cd ../input_ad ; ls -1 | grep -v CVS )` |
392 |
|
|
for i in $files ; do |
393 |
|
|
if test ! -d "../input_ad/"$i ; then |
394 |
|
|
ln -sf "../input_ad/"$i $i |
395 |
|
|
fi |
396 |
|
|
done |
397 |
|
|
fi |
398 |
edhill |
1.12 |
) |
399 |
edhill |
1.1 |
fi |
400 |
|
|
} |
401 |
|
|
|
402 |
|
|
runmodel() |
403 |
|
|
{ |
404 |
edhill |
1.6 |
# runmodel directory |
405 |
edhill |
1.1 |
# |
406 |
edhill |
1.24 |
# runs "$COMMAND in "directory" |
407 |
edhill |
1.6 |
# (where "$COMMAND" is relative to "directory") |
408 |
edhill |
1.1 |
( |
409 |
|
|
cd $1 |
410 |
edhill |
1.20 |
printf 'runmodel ... ' 1>&2 |
411 |
edhill |
1.6 |
# make output.txt |
412 |
edhill |
1.20 |
$COMMAND >> run.log 2>&1 |
413 |
edhill |
1.6 |
RETVAL=$? |
414 |
|
|
if test "x$RETVAL" = x0 ; then |
415 |
edhill |
1.20 |
echo successful 1>&2 |
416 |
edhill |
1.24 |
if test "x$ADM" = x ; then |
417 |
|
|
cp output.txt $CDIR"/output.txt" |
418 |
|
|
else |
419 |
|
|
cp output.txt_adm $CDIR"/output.txt_adm" |
420 |
|
|
fi |
421 |
edhill |
1.6 |
return 0 |
422 |
|
|
else |
423 |
edhill |
1.20 |
tail run.log |
424 |
|
|
echo failed 1>&2 |
425 |
|
|
cp run.log $CDIR"/run.log" |
426 |
edhill |
1.6 |
return 1 |
427 |
edhill |
1.1 |
fi |
428 |
|
|
) |
429 |
|
|
} |
430 |
|
|
|
431 |
|
|
createcodelet() |
432 |
|
|
{ |
433 |
|
|
# create codelet for comparing model output |
434 |
|
|
|
435 |
|
|
echo -n "creating the comparison code... " |
436 |
edhill |
1.22 |
cat > tmp_cmpnum.c <<EOF |
437 |
|
|
#include <stdio.h> |
438 |
|
|
#include <math.h> |
439 |
|
|
int main( int argc, char** argv ) { |
440 |
|
|
int linnum,best; |
441 |
|
|
double a,b,diff; |
442 |
|
|
best = -16; |
443 |
|
|
while( 1 ) { |
444 |
|
|
scanf("%d", &linnum); |
445 |
|
|
if (linnum == -1) break; |
446 |
|
|
scanf("%lf", &a); scanf("%lf", &b); |
447 |
|
|
diff = 0.5*(fabs(a)+fabs(b)); |
448 |
|
|
if (diff > 1.e-12) { |
449 |
|
|
diff=fabs(a-b)/diff; |
450 |
|
|
if (diff > 0.0) { |
451 |
|
|
linnum = (int)log10(diff); |
452 |
|
|
best = (best > linnum) ? best : linnum; |
453 |
|
|
} |
454 |
|
|
else { |
455 |
|
|
if (best == -16 && diff != 0) best = -22; |
456 |
|
|
} |
457 |
|
|
} |
458 |
|
|
} |
459 |
|
|
printf("%d\n", -best); |
460 |
|
|
return 0; |
461 |
|
|
} |
462 |
|
|
EOF |
463 |
|
|
cc -o tmp_cmpnum tmp_cmpnum.c -lm |
464 |
edhill |
1.1 |
|
465 |
edhill |
1.22 |
if [ -x ./tmp_cmpnum ]; then |
466 |
edhill |
1.1 |
echo "OK" |
467 |
|
|
return 0 |
468 |
|
|
else |
469 |
|
|
echo |
470 |
edhill |
1.21 |
echo "ERROR: failed to compile comparison code" |
471 |
edhill |
1.1 |
exit 1 |
472 |
|
|
fi |
473 |
|
|
} |
474 |
|
|
|
475 |
|
|
formatresults() |
476 |
|
|
{ |
477 |
|
|
# formatresults expt genmake depend make run results* |
478 |
|
|
|
479 |
|
|
nm=$1 |
480 |
|
|
printf '%s %s %s %s' $2 $3 $4 $5 |
481 |
|
|
shift; shift; shift; shift; shift; |
482 |
|
|
printf '%3s' $@ |
483 |
|
|
|
484 |
|
|
if [ $1 = '--' ]; then |
485 |
|
|
printf ' N/O ' |
486 |
|
|
else |
487 |
|
|
if [ $1 -gt 12 ]; then |
488 |
|
|
printf ' pass' |
489 |
|
|
else |
490 |
|
|
printf ' FAIL' |
491 |
|
|
fi |
492 |
|
|
fi |
493 |
|
|
printf ' %s' $nm |
494 |
|
|
printf '\n' |
495 |
|
|
|
496 |
|
|
} |
497 |
|
|
|
498 |
|
|
show_help() |
499 |
|
|
{ |
500 |
|
|
cat - << EOF |
501 |
|
|
$0 [-help] [-quick] [-verbose] dir1 [dir2] [...] |
502 |
edhill |
1.10 |
|
503 |
|
|
-help|-h Show this help message |
504 |
edhill |
1.1 |
-quiet Reduce the amount of output |
505 |
|
|
-verbose Produce copious amounts of output |
506 |
|
|
-debug Produce even more output which will mean nothing to most |
507 |
|
|
-force Do "make CLEAN" before compiling. This forces a complete rebuild. |
508 |
|
|
-clean Do "make CLEAN" after compiling and testing. |
509 |
|
|
-cleanup Aggresively removes all model output, executables and object files |
510 |
|
|
and then exits. Use with care. |
511 |
|
|
|
512 |
|
|
Normal usage: |
513 |
|
|
$0 * Configure, compile, run and analyze in all experiment directories |
514 |
|
|
EOF |
515 |
|
|
} |
516 |
|
|
|
517 |
|
|
scandirs() |
518 |
|
|
{ |
519 |
|
|
if [ $# -eq 0 ]; then |
520 |
|
|
for arg in * ; do |
521 |
|
|
test -d $arg/input && echo $arg |
522 |
|
|
done |
523 |
|
|
else |
524 |
|
|
echo $* |
525 |
|
|
fi |
526 |
|
|
} |
527 |
|
|
|
528 |
|
|
|
529 |
|
|
############################################################################### |
530 |
|
|
|
531 |
|
|
|
532 |
|
|
# Default properties |
533 |
|
|
debug=0 |
534 |
|
|
verbose=1 |
535 |
|
|
clean=0 |
536 |
|
|
expts='' |
537 |
edhill |
1.6 |
# ieee=1 |
538 |
edhill |
1.10 |
|
539 |
|
|
IEEE= |
540 |
|
|
if test "x$MITGCM_IEEE" != x ; then |
541 |
|
|
IEEE=$MITGCM_IEEE |
542 |
|
|
fi |
543 |
|
|
|
544 |
|
|
|
545 |
|
|
CLEANUP=f |
546 |
|
|
QUICK=f |
547 |
|
|
NOGENMAKE=f |
548 |
|
|
NOCLEAN=f |
549 |
|
|
NODEPEND=f |
550 |
edhill |
1.1 |
|
551 |
edhill |
1.4 |
BASH= |
552 |
edhill |
1.10 |
OPTFILE=NONE |
553 |
|
|
ADDRESSES= |
554 |
edhill |
1.1 |
TESTDIRS= |
555 |
|
|
MPACKDIR="../tools/mpack-1.6" |
556 |
edhill |
1.20 |
HAVE_MPACK= |
557 |
edhill |
1.1 |
MPACK="$MPACKDIR/mpack" |
558 |
edhill |
1.24 |
COMMAND= |
559 |
edhill |
1.8 |
MAKE=make |
560 |
edhill |
1.7 |
MPI=f |
561 |
edhill |
1.1 |
|
562 |
edhill |
1.24 |
ADM= |
563 |
|
|
|
564 |
edhill |
1.1 |
echo -n "parsing options... " |
565 |
|
|
|
566 |
|
|
ac_prev= |
567 |
|
|
for ac_option ; do |
568 |
|
|
|
569 |
|
|
# If the previous option needs an argument, assign it. |
570 |
|
|
if test -n "$ac_prev"; then |
571 |
|
|
eval "$ac_prev=\$ac_option" |
572 |
|
|
ac_prev= |
573 |
|
|
continue |
574 |
|
|
fi |
575 |
|
|
|
576 |
|
|
ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` |
577 |
|
|
|
578 |
|
|
case $ac_option in |
579 |
|
|
|
580 |
|
|
-help | --help | -h | --h) |
581 |
|
|
usage ;; |
582 |
|
|
|
583 |
edhill |
1.2 |
-optfile | --optfile | -of | --of) |
584 |
edhill |
1.10 |
ac_prev=OPTFILE ;; |
585 |
edhill |
1.2 |
-optfile=* | --optfile=* | -of=* | --of=*) |
586 |
edhill |
1.10 |
OPTFILE=$ac_optarg ;; |
587 |
edhill |
1.1 |
|
588 |
|
|
-addr | --addr | -a | --a) |
589 |
|
|
ac_prev=ADDRESSES ;; |
590 |
|
|
-addr=* | --addr=*) |
591 |
|
|
ADDRESSES=$ac_optarg ;; |
592 |
|
|
|
593 |
|
|
-tdir | --tdir | -t | --t) |
594 |
|
|
ac_prev=TESTDIRS ;; |
595 |
|
|
-tdir=* | --tdir=*) |
596 |
|
|
TESTDIRS=$ac_optarg ;; |
597 |
edhill |
1.4 |
|
598 |
|
|
-bash | --bash | -b | --b) |
599 |
|
|
ac_prev=BASH ;; |
600 |
|
|
-bash=* | --bash=*) |
601 |
|
|
BASH=$ac_optarg ;; |
602 |
edhill |
1.5 |
|
603 |
edhill |
1.6 |
-command | --command | -c | --c) |
604 |
|
|
ac_prev=COMMAND ;; |
605 |
|
|
-command=* | --command=*) |
606 |
|
|
COMMAND=$ac_optarg ;; |
607 |
edhill |
1.8 |
|
608 |
|
|
-make | --make | -m | --m) |
609 |
|
|
ac_prev=MAKE ;; |
610 |
|
|
-make=* | --make=*) |
611 |
|
|
MAKE=$ac_optarg ;; |
612 |
edhill |
1.1 |
|
613 |
edhill |
1.10 |
-clean | --clean) |
614 |
|
|
CLEANUP=t ;; |
615 |
|
|
|
616 |
|
|
-quick | --quick | -q | --q) |
617 |
|
|
QUICK=t ;; |
618 |
|
|
-nogenmake | --nogenmake | -ng | --ng) |
619 |
|
|
NOGENMAKE=t ;; |
620 |
|
|
-noclean | --noclean | -nc | --nc) |
621 |
|
|
NOCLEAN=t ;; |
622 |
|
|
-nodepend | --nodepend | -nd | --nd) |
623 |
|
|
NODEPEND=t ;; |
624 |
|
|
|
625 |
edhill |
1.18 |
-mpi) MPI=t ;; |
626 |
edhill |
1.10 |
|
627 |
edhill |
1.24 |
-adm | -ad) ADM=t ;; |
628 |
|
|
|
629 |
edhill |
1.10 |
-ieee) IEEE=true ;; |
630 |
|
|
-noieee) IEEE= ;; |
631 |
|
|
|
632 |
edhill |
1.1 |
-verbose) verbose=2 ;; |
633 |
|
|
-debug) debug=1 ;; |
634 |
|
|
-quiet) verbose=0 ;; |
635 |
|
|
|
636 |
|
|
-*) |
637 |
|
|
echo "Error: unrecognized option: "$ac_option |
638 |
|
|
usage |
639 |
|
|
;; |
640 |
|
|
|
641 |
|
|
*) |
642 |
|
|
echo "Error: unrecognized argument: "$ac_option |
643 |
|
|
usage |
644 |
|
|
;; |
645 |
|
|
|
646 |
|
|
esac |
647 |
|
|
|
648 |
|
|
done |
649 |
|
|
|
650 |
edhill |
1.10 |
if test "x$QUICK" = xt ; then |
651 |
|
|
NOGENMAKE=t |
652 |
|
|
NOCLEAN=t |
653 |
|
|
NODEPEND=t |
654 |
|
|
fi |
655 |
|
|
|
656 |
edhill |
1.1 |
if test "x$TESTDIRS" = x ; then |
657 |
|
|
TESTDIRS=`scandirs` |
658 |
|
|
fi |
659 |
|
|
|
660 |
edhill |
1.10 |
if test "x$OPTFILE" = xNONE -a "x$MITGCM_OF" != x ; then |
661 |
|
|
OPTFILE=$MITGCM_OF |
662 |
|
|
fi |
663 |
|
|
|
664 |
edhill |
1.24 |
if test "x$ADM" = xt -a "x$COMMAND" = x ; then |
665 |
|
|
COMMAND="./mitgcmuv_ad > output.txt_adm 2>&1" |
666 |
|
|
fi |
667 |
|
|
|
668 |
|
|
if test "x$COMMAND" = x ; then |
669 |
|
|
COMMAND="make output.txt" |
670 |
|
|
fi |
671 |
|
|
|
672 |
edhill |
1.1 |
echo "OK" |
673 |
|
|
|
674 |
|
|
# create the FORTRAN comparison code |
675 |
|
|
createcodelet |
676 |
|
|
|
677 |
|
|
# build the mpack utility |
678 |
|
|
build_mpack |
679 |
|
|
|
680 |
|
|
# Create a uniquely named directory to store results |
681 |
|
|
MACH=`hostname` |
682 |
edhill |
1.2 |
UNAMEA=`uname -a` |
683 |
edhill |
1.1 |
DATE=`date +%Y%m%d` |
684 |
edhill |
1.25 |
BASE="tr_"$MACH"_"$DATE"_" |
685 |
edhill |
1.1 |
DNUM=0 |
686 |
|
|
DRESULTS="$BASE$DNUM" |
687 |
|
|
while test -e $DRESULTS ; do |
688 |
|
|
DNUM=$(( $DNUM + 1 )) |
689 |
|
|
DRESULTS="$BASE$DNUM" |
690 |
|
|
done |
691 |
|
|
mkdir $DRESULTS |
692 |
|
|
RETVAL=$? |
693 |
|
|
if test "x$RETVAL" != x0 ; then |
694 |
edhill |
1.20 |
echo "ERROR: Can't create results directory \"./$DRESULTS\"" |
695 |
edhill |
1.1 |
exit 1 |
696 |
|
|
fi |
697 |
|
|
SUMMARY="$DRESULTS/summary.txt" |
698 |
edhill |
1.13 |
echo -n "Start time: " >> $SUMMARY |
699 |
edhill |
1.16 |
start_date=`date` |
700 |
edhill |
1.17 |
echo $start_date > $SUMMARY |
701 |
edhill |
1.1 |
|
702 |
edhill |
1.11 |
of_path= |
703 |
edhill |
1.10 |
if test "x$OPTFILE" != xNONE ; then |
704 |
|
|
if test -r $OPTFILE ; then |
705 |
edhill |
1.11 |
# get the path |
706 |
|
|
path=${OPTFILE%/*} |
707 |
|
|
if test "x$path" = x ; then |
708 |
|
|
of_path=`pwd` |
709 |
|
|
else |
710 |
|
|
of_path=`( cd $path > /dev/null 2>&1 ; pwd )` |
711 |
|
|
fi |
712 |
|
|
file=${OPTFILE##*/} |
713 |
|
|
OPTFILE=$of_path/$file |
714 |
edhill |
1.21 |
cp $OPTFILE $DRESULTS |
715 |
|
|
echo >> $SUMMARY |
716 |
|
|
echo " OPTFILE=$OPTFILE" >> $SUMMARY |
717 |
edhill |
1.11 |
else |
718 |
edhill |
1.21 |
echo | tee $SUMMARY |
719 |
|
|
echo "ERROR: can't read OPTFILE=\"$OPTFILE\"" | tee $SUMMARY |
720 |
|
|
exit 1 |
721 |
edhill |
1.10 |
fi |
722 |
edhill |
1.21 |
else |
723 |
|
|
echo >> $SUMMARY |
724 |
|
|
echo "No \"OPTFILE\" was explicitly specified by testreport," >> $SUMMARY |
725 |
|
|
echo " so the genmake default will be used." >> $SUMMARY |
726 |
edhill |
1.10 |
fi |
727 |
|
|
echo |
728 |
|
|
echo >> $SUMMARY |
729 |
edhill |
1.24 |
if test "x$ADM" = x ; then |
730 |
|
|
cat << EOF | tee -a $SUMMARY |
731 |
edhill |
1.21 |
T S U V |
732 |
|
|
G D M c m s m s m s m s |
733 |
|
|
E p a R g m m e . m m e . m m e . m m e . |
734 |
|
|
N n k u 2 i a a d i a a d i a a d i a a d |
735 |
|
|
2 d e n d n x n . n x n . n x n . n x n . |
736 |
|
|
|
737 |
|
|
EOF |
738 |
edhill |
1.24 |
else |
739 |
|
|
echo "ADJOINT=true" >> $SUMMARY |
740 |
|
|
echo >> $SUMMARY |
741 |
|
|
cat << EOF | tee -a $SUMMARY |
742 |
|
|
G D M C G |
743 |
|
|
E p a R o r |
744 |
|
|
N n k u s a |
745 |
|
|
2 d e n t d |
746 |
|
|
|
747 |
|
|
EOF |
748 |
|
|
fi |
749 |
edhill |
1.1 |
|
750 |
edhill |
1.10 |
# ...and each test directory... |
751 |
|
|
for dir in $TESTDIRS ; do |
752 |
|
|
|
753 |
|
|
# Cleanup only! |
754 |
|
|
if test "x$CLEANUP" = xt ; then |
755 |
|
|
if test -r $dir/build/Makefile ; then |
756 |
|
|
( cd $dir/build ; make CLEAN ) |
757 |
|
|
fi |
758 |
|
|
if test -r $dir/input/Makefile ; then |
759 |
|
|
( cd $dir/input ; make CLEAN ) |
760 |
|
|
fi |
761 |
|
|
continue |
762 |
edhill |
1.1 |
fi |
763 |
edhill |
1.3 |
|
764 |
edhill |
1.10 |
# Verify that the testdir exists and contains previous |
765 |
|
|
# results in the correct location--or skip this directory! |
766 |
edhill |
1.24 |
fout= |
767 |
|
|
if test "x$ADM" = x ; then |
768 |
|
|
fout=$dir"/results/output.txt" |
769 |
|
|
else |
770 |
|
|
fout=$dir"/results_ad/output.txt_adm" |
771 |
|
|
fi |
772 |
|
|
if test ! -r $fout ; then |
773 |
|
|
echo "can't read \"$fout\" -- skipping $dir" |
774 |
edhill |
1.10 |
continue |
775 |
|
|
fi |
776 |
edhill |
1.7 |
|
777 |
edhill |
1.10 |
echo "-------------------------------------------------------------------------------" |
778 |
|
|
echo |
779 |
|
|
echo "Experiment: $dir" |
780 |
|
|
echo |
781 |
|
|
unset genmake makedepend make run |
782 |
|
|
results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --' |
783 |
edhill |
1.1 |
|
784 |
edhill |
1.12 |
builddir="input" |
785 |
|
|
rundir="input" |
786 |
|
|
use_seperate_build=0 |
787 |
|
|
if test -d $dir/build -a -r $dir/build ; then |
788 |
|
|
builddir="build" |
789 |
|
|
rundir="build" |
790 |
|
|
use_seperate_build=1 |
791 |
|
|
linkdata $use_seperate_build $dir/$rundir |
792 |
edhill |
1.10 |
fi |
793 |
|
|
|
794 |
edhill |
1.24 |
if test "x$ADM" = x ; then |
795 |
edhill |
1.27 |
code_dir=code |
796 |
edhill |
1.24 |
CODE_DIR=$dir/code |
797 |
|
|
else |
798 |
edhill |
1.27 |
code_dir=code_ad |
799 |
edhill |
1.24 |
CODE_DIR=$dir/code_ad |
800 |
|
|
fi |
801 |
edhill |
1.10 |
BUILD_DIR=$dir/$builddir |
802 |
|
|
|
803 |
|
|
# Create an output dir for each OPTFILE/tdir combination |
804 |
edhill |
1.20 |
rel_CDIR=$DRESULTS"/"$dir |
805 |
|
|
mkdir $rel_CDIR |
806 |
|
|
CDIR=`pwd`"/$rel_CDIR" |
807 |
edhill |
1.10 |
|
808 |
|
|
if test "x$CLEANUP" = xt ; then |
809 |
|
|
makeclean $dir/$builddir |
810 |
|
|
else |
811 |
edhill |
1.1 |
genmakemodel $dir/$builddir && genmake=Y \ |
812 |
|
|
&& makeclean $dir/$builddir \ |
813 |
edhill |
1.27 |
&& symlink_mpifiles $dir $code_dir $builddir \ |
814 |
edhill |
1.1 |
&& makedependmodel $dir/$builddir && makedepend=Y \ |
815 |
|
|
&& makemodel $dir/$builddir && make=Y \ |
816 |
edhill |
1.12 |
&& linkdata $use_seperate_build $dir/$rundir \ |
817 |
|
|
&& runmodel $dir/$rundir && run=Y \ |
818 |
edhill |
1.1 |
&& results=`testoutput $dir $rundir` |
819 |
edhill |
1.10 |
fi |
820 |
|
|
|
821 |
|
|
echo |
822 |
edhill |
1.24 |
if test "x$ADM" = x ; then |
823 |
|
|
fres=`formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results` |
824 |
|
|
else |
825 |
|
|
fres=`printf '%s %s %s %s' ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N}` |
826 |
|
|
fres=$fres"$results $dir" |
827 |
|
|
fi |
828 |
edhill |
1.10 |
echo |
829 |
edhill |
1.21 |
echo "$fres" >> $SUMMARY |
830 |
|
|
echo "fresults='$fres'" > $CDIR"/summary.txt" |
831 |
edhill |
1.10 |
echo "MACH='$MACH'" >> $CDIR"/summary.txt" |
832 |
|
|
echo "UNAMEA='$UNAMEA'" >> $CDIR"/summary.txt" |
833 |
|
|
echo "DATE='$DATE'" >> $CDIR"/summary.txt" |
834 |
|
|
echo "tdir='$dir'" >> $CDIR"/summary.txt" |
835 |
|
|
|
836 |
|
|
echo "-------------------------------------------------------------------------------" |
837 |
|
|
|
838 |
edhill |
1.1 |
done |
839 |
|
|
|
840 |
edhill |
1.13 |
echo -n "Start time: " >> $SUMMARY |
841 |
edhill |
1.16 |
echo $start_date >> $SUMMARY |
842 |
edhill |
1.13 |
echo -n "End time: " >> $SUMMARY |
843 |
|
|
date >> $SUMMARY |
844 |
edhill |
1.20 |
|
845 |
|
|
# If addresses were supplied and mpack built successfully, then try |
846 |
|
|
# to send email using mpack. |
847 |
|
|
if test "x$ADDRESSES" = xNONE -o "x$ADDRESSES" = x ; then |
848 |
|
|
echo "No results email was sent." |
849 |
|
|
else |
850 |
|
|
if test "x$HAVE_MPACK" = xt ; then |
851 |
|
|
tar -cf $DRESULTS".tar" $DRESULTS > /dev/null 2>&1 \ |
852 |
|
|
&& gzip $DRESULTS".tar" \ |
853 |
|
|
&& $MPACK -s MITgcm-test -m 1500000 $DRESULTS".tar.gz" $ADDRESSES |
854 |
|
|
RETVAL=$? |
855 |
|
|
if test "x$RETVAL" != x0 ; then |
856 |
|
|
echo |
857 |
|
|
echo "Warning: The tar, gzip, & mpack step failed. Please send email" |
858 |
|
|
echo " to <MITgcm-support@mitgcm.org> for help. You may copy the " |
859 |
|
|
echo " summary of results from the directory \"$DRESULTS\"." |
860 |
|
|
echo |
861 |
|
|
else |
862 |
|
|
echo |
863 |
|
|
echo "An email containing results was sent to the following addresses:" |
864 |
|
|
echo " \"$ADDRESSES\"" |
865 |
|
|
echo |
866 |
|
|
fi |
867 |
|
|
test -f $DRESULTS".tar" && rm -f $DRESULTS".tar" |
868 |
|
|
test -f $DRESULTS".tar.gz" && rm -f $DRESULTS".tar.gz" |
869 |
|
|
fi |
870 |
|
|
fi |
871 |
edhill |
1.13 |
|
872 |
edhill |
1.22 |
# rm -f tmp_cmpnum.f a.out |
873 |
|
|
rm -f tmp_cmpnum.c tmp_cmpnum |
874 |
edhill |
1.1 |
|
875 |
edhill |
1.12 |
if test "x$CLEANUP" != xt ; then |
876 |
|
|
cat $SUMMARY |
877 |
edhill |
1.25 |
if test -e tr_out.txt ; then |
878 |
|
|
mv tr_out.txt tr_out.txt.old |
879 |
edhill |
1.14 |
fi |
880 |
edhill |
1.25 |
cat $SUMMARY > tr_out.txt |
881 |
edhill |
1.12 |
fi |
882 |
edhill |
1.1 |
|