1 |
#!/bin/csh -f |
#!/bin/sh |
2 |
|
|
3 |
# Run this script from the verification directory |
similar() |
4 |
# It will automatically configure, compile, run and verify all experiments |
{ |
5 |
# in the verification directory for whcih there is an results/output.txt |
# similar digits a b |
6 |
# file. |
# |
7 |
|
# compare the floating point number a and b and successively reduced |
8 |
# This is the number of least-significant digits allows to be |
# truncation until a match is found |
9 |
# in error before the test is classified as a "fail". |
for digits in 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
10 |
|
do |
11 |
set on_error_die |
a=`printf '%22.'$digits'e\n' $1` |
12 |
set passaccuracy=7 |
b=`printf '%22.'$digits'e\n' $2` |
13 |
set SKIP=( ) |
if [ $a = $b ]; then |
14 |
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' " " Make " " " " Exact "# of" " " " " > summary.txt |
if [ $verbose -gt 1 ]; then |
15 |
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' Config Depend Compile Execute Match Digits Status Experiment >> summary.txt |
echo $1 $2 $a 1>&2 |
16 |
|
fi |
17 |
# Pass any arguments |
break |
18 |
foreach arg ($argv) |
fi |
19 |
switch ($arg) |
done |
20 |
case -clean: |
return $digits |
21 |
echo Cleaning ... |
} |
22 |
foreach dr ([a-zA-Z01-9]*) |
|
23 |
if (-d $dr/input) then |
compare_lines() |
24 |
echo Entering $dr |
{ |
25 |
cd $dr/input |
# compare_lines digits < file |
26 |
echo "" |
# |
27 |
make CLEAN |
# read each line of file and test the 2nd and 3rd column values for |
28 |
\rm -f {*output,*high,*low}.txt *.log |
# similarity based on the function similar() |
29 |
\rm -f ?ake* |
worst_so_far=$1 |
30 |
cd ../.. |
while read linenum a b |
31 |
endif |
do |
32 |
end |
if [ $debug -gt 0 ]; then |
33 |
rm -f summary.txt |
echo compare_lines: similar a=$a b=$b 1>&2 |
34 |
exit 0 |
fi |
35 |
breaksw |
similar $a $b |
36 |
case -nodie: |
digits=$? |
37 |
unset on_error_die |
if [ $digits -lt $worst_so_far ]; then |
38 |
breaksw |
worst_so_far=$digits |
39 |
case -skip=*: |
fi |
40 |
set SKIP = ( $SKIP `echo $arg | sed 's/-skip=//' | sed 's/,/ /g' `) |
done |
41 |
breaksw |
if [ $debug -gt 0 ]; then |
42 |
default: |
echo compare_lines: worst_so_far=$worst_so_far 1>&2 |
43 |
echo Unknown argument given to $0 |
fi |
44 |
exit 1 |
return $worst_so_far |
45 |
endsw |
} |
46 |
end |
|
47 |
|
compare_lines2() |
48 |
foreach dr ([a-zA-Z01-9]*) |
{ |
49 |
if (! -d $dr/input ) continue |
# use codelet to compare lines |
50 |
foreach skip ($SKIP) |
return `./a.out < tmp3.txt` |
51 |
if ( `echo $dr | sed s/$skip.'*'//` == '' ) continue;continue |
} |
52 |
end |
|
53 |
set config=- |
testoutput_for_prop() |
54 |
set makedepend=- |
{ |
55 |
set compile=- |
# testoutput_for_prop dir s1 label |
56 |
set execute=- |
# |
57 |
set exactmatch=- |
# compares files in $dir/input/output.txt and $dir/results.output.txt |
58 |
set accuracy=- |
# using search strings s1 and text label |
59 |
set pass=FAIL |
|
60 |
echo ============================================================================== |
if [ $debug -gt 0 ]; then |
61 |
echo Entering $dr |
echo testoutput_for_prop: grep "$2" $1/input/output.txt 1>&2 |
62 |
cd $dr |
fi |
63 |
echo "" |
if [ -r $1/input/output.txt ]; then |
64 |
if (! -r results/output.txt) then |
grep "$2" $1/input/output.txt | sed 's/.*=//' | nl > tmp1.txt |
|
echo " ***** No results to compare with *****" |
|
|
if (! $?untested) set untested |
|
|
set untested=($untested $dr) |
|
65 |
else |
else |
66 |
set config=NO |
echo testoutput_for_prop: output.txt from model run was not readable 1>&2 |
67 |
cd input |
return 99 |
68 |
echo -n " generating Makefile ..." |
fi |
69 |
../../../tools/genmake -mods=../code >&! make.log |
if [ $debug -gt 0 ]; then |
70 |
if ($status == 0) set config=Yes |
echo testoutput_for_prop: grep "$2" $1/results/output.txt 1>&2 |
71 |
set makedepend=NO |
fi |
72 |
echo " done." |
grep "$2" $1/results/output.txt | sed 's/.*=//' | nl > tmp2.txt |
73 |
echo -n " make depend ..." |
if [ $debug -gt 0 ]; then |
74 |
make cleanlinks depend >>& make.log |
echo testoutput_for_prop: join tmp1.txt tmp2.txt 1>&2 |
75 |
if ($status == 0) set makedepend=Yes |
fi |
76 |
echo " done." |
join tmp1.txt tmp2.txt | awk '{print $1 " " $2 " " $3}' > tmp3.txt |
77 |
echo -n " make ..." |
if [ $debug -gt 0 ]; then |
78 |
make >>& make.log |
echo testoutput_for_prop: compare_lines 1>&2 |
79 |
if ($status) then |
fi |
80 |
echo " ***** An error occurred during make *****" |
#compare_lines 99 < tmp3.txt |
81 |
cat make.log |
compare_lines2 |
82 |
echo The error during compilation occured in \"$dr\" |
digits_of_similarity=$? |
83 |
set compile=NO |
if [ $digits_of_similarity -eq 99 ]; then |
84 |
if ($?on_error_die) exit 1 |
if [ $verbose -gt 0 ]; then |
85 |
else |
echo testoutput_for_prop: No comparison was available for \"$2\" 1>&2 |
86 |
set compile=Yes |
fi |
87 |
set execute=NO |
digits_of_similarity=99 |
88 |
endif |
else |
89 |
echo " done." |
if [ $verbose -gt 0 ]; then |
90 |
echo -n " running model ..." |
echo There were $digits_of_similarity decimal places of similarity for \"$2\" 1>&2 |
91 |
if ($compile == 'Yes') then |
fi |
92 |
# ./mitgcmuv | & grep "D iters" > output.txt |
fi |
93 |
./mitgcmuv > & output.txt |
rm tmp1.txt tmp2.txt tmp3.txt |
94 |
if ($status == 0) then |
|
95 |
set execute=Yes |
return $digits_of_similarity |
96 |
set exactmatch=NO |
} |
97 |
set accuracy=- |
|
98 |
echo " done." |
dashnum() |
99 |
grep "D iters" output.txt | sed 's/.*D iters, err =//' \ |
{ |
100 |
| grep " 0 " \ |
# dashnum n1 n2 n3 ... |
101 |
> high.txt |
# |
102 |
grep "D iters" ../results/output.txt \ |
# print numbers using %3i format or "--" if number = 99 |
103 |
| sed 's/.*D iters, err =//' \ |
for num in $@ |
104 |
| grep " 0 " \ |
do |
105 |
> oldhigh.txt |
if [ $num = 99 ]; then |
106 |
diff oldhigh.txt high.txt > /dev/null |
printf ' --' |
107 |
if ($status) then |
else |
108 |
echo " output differs:" |
printf '%3i' $num |
109 |
diff oldhigh.txt high.txt |
fi |
110 |
echo "" |
done |
111 |
@ lvl=0 |
} |
112 |
set accuracy='.' |
|
113 |
set fail |
testoutput() |
114 |
echo -n Trying reduced accuracy |
{ |
115 |
while ($lvl <= $passaccuracy) |
# testoutput diretory |
116 |
@ lvl+=1 |
# |
117 |
echo -n " " $lvl |
# test output in "directory" |
118 |
sed s/{$accuracy}E/E/ high.txt > low.txt |
|
119 |
sed s/{$accuracy}E/E/ oldhigh.txt > oldlow.txt |
if [ $debug -gt 0 ]; then |
120 |
diff oldlow.txt low.txt > /dev/null |
echo testoutput: testoutput_for_prop $1 cg2d_init_res 1>&2 |
121 |
if ($status == 0) then |
fi |
122 |
unset fail |
testoutput_for_prop $1 "cg2d_init_res" "cg2d init. residual"; cg2dres=$? |
123 |
break |
if [ $debug -gt 0 ]; then |
124 |
|
echo testoutput: cg2dres=$cg2dres 1>&2 |
125 |
|
fi |
126 |
|
|
127 |
|
if [ $testmore -gt 0 ]; then |
128 |
|
testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$? |
129 |
|
testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$? |
130 |
|
testoutput_for_prop $1 "dynstat_theta_mean" "theta mean"; tmean=$? |
131 |
|
testoutput_for_prop $1 "dynstat_theta_sd" "theta s.d."; tsd=$? |
132 |
|
testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$? |
133 |
|
testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$? |
134 |
|
testoutput_for_prop $1 "dynstat_salt_mean" "salt mean"; smean=$? |
135 |
|
testoutput_for_prop $1 "dynstat_salt_sd" "salt s.d."; ssd=$? |
136 |
|
testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$? |
137 |
|
testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$? |
138 |
|
testoutput_for_prop $1 "dynstat_uvel_mean" "U mean"; umean=$? |
139 |
|
testoutput_for_prop $1 "dynstat_uvel_sd" "U s.d."; usd=$? |
140 |
|
testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$? |
141 |
|
testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$? |
142 |
|
testoutput_for_prop $1 "dynstat_vvel_mean" "V mean"; vmean=$? |
143 |
|
testoutput_for_prop $1 "dynstat_vvel_sd" "V s.d."; vsd=$? |
144 |
|
else |
145 |
|
testoutput_for_prop $1 "dynstat_theta_min" "theta minimum"; tmin=$? |
146 |
|
testoutput_for_prop $1 "dynstat_theta_max" "theta maximum"; tmax=$? |
147 |
|
testoutput_for_prop $1 "dynstat_salt_min" "salt minimum"; smin=$? |
148 |
|
testoutput_for_prop $1 "dynstat_salt_max" "salt maximum"; smax=$? |
149 |
|
testoutput_for_prop $1 "dynstat_uvel_min" "U minimum"; umin=$? |
150 |
|
testoutput_for_prop $1 "dynstat_uvel_max" "U maximum"; umax=$? |
151 |
|
testoutput_for_prop $1 "dynstat_vvel_min" "V minimum"; vmin=$? |
152 |
|
testoutput_for_prop $1 "dynstat_vvel_max" "V maximum"; vmax=$? |
153 |
|
fi |
154 |
|
|
155 |
|
dashnum $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \ |
156 |
|
$umin $umax $umean $usd $vmin $vmax $vmean $vsd |
157 |
|
#printf '%3i' $cg2dres $tmin $tmax $tmean $tsd $smin $smax $smean $ssd \ |
158 |
|
# $umin $umax $umean $usd $vmin $vmax $vmean $vsd |
159 |
|
} |
160 |
|
|
161 |
|
genmakemodel() |
162 |
|
{ |
163 |
|
# genmakemodel directory |
164 |
|
( cd $1; |
165 |
|
if [ $quick -eq 0 -o ! -r Makefile ]; then |
166 |
|
printf 'genmake ... ' 1>&2 |
167 |
|
../../../tools/genmake -mods=../code > make.log 2>&1 |
168 |
|
if [ $? -ne 0 ]; then |
169 |
|
tail make.log |
170 |
|
echo makemodel: genmake failed 1>&2 |
171 |
|
return 1 |
172 |
|
else |
173 |
|
echo succesful 1>&2 |
174 |
|
fi |
175 |
|
fi |
176 |
|
) |
177 |
|
} |
178 |
|
|
179 |
|
makedependmodel() |
180 |
|
{ |
181 |
|
# makedependmodel directory |
182 |
|
( cd $1; |
183 |
|
if [ $quick -eq 0 -o ! -r Makefile ]; then |
184 |
|
printf 'make depend ... ' 1>&2 |
185 |
|
make cleanlinks >> make.log 2>&1 |
186 |
|
make depend >> make.log 2>&1 |
187 |
|
if [ $? -ne 0 ]; then |
188 |
|
tail make.log |
189 |
|
echo makemodel: make depend failed 1>&2 |
190 |
|
return 1 |
191 |
|
else |
192 |
|
echo succesful 1>&2 |
193 |
|
fi |
194 |
|
fi |
195 |
|
) |
196 |
|
} |
197 |
|
|
198 |
|
makemodel() |
199 |
|
{ |
200 |
|
# makemodel directory |
201 |
|
( cd $1; |
202 |
|
if [ -r Makefile ]; then |
203 |
|
printf 'make ... ' 1>&2 |
204 |
|
make >> make.log 2>&1 |
205 |
|
if [ $? -ne 0 ]; then |
206 |
|
tail make.log |
207 |
|
echo failed 1>&2 |
208 |
|
return 1 |
209 |
|
else |
210 |
|
echo succesful 1>&2 |
211 |
|
fi |
212 |
|
fi |
213 |
|
) |
214 |
|
} |
215 |
|
|
216 |
|
runmodel() |
217 |
|
{ |
218 |
|
# runmodel directory exe |
219 |
|
# |
220 |
|
# runs the model "exe" in "directory" (exe is relative to directory) |
221 |
|
|
222 |
|
( cd $1 |
223 |
|
if [ -x $2 ]; then |
224 |
|
if [ ! -r output.txt -o $quick -eq 0 ]; then |
225 |
|
echo runmodel: running... 1>&2 |
226 |
|
( ./$2 > output.txt 2>&1 ) && return 0 |
227 |
|
return 1 |
228 |
|
else |
229 |
|
echo runmodel: output.txt is newer than executable 1>&2 |
230 |
|
return 0 |
231 |
|
fi |
232 |
|
else |
233 |
|
echo runmodel: executable \"$1/$2\" is missing 1>&2 |
234 |
|
return 1 |
235 |
|
fi |
236 |
|
) |
237 |
|
} |
238 |
|
|
239 |
|
createcodelet() |
240 |
|
{ |
241 |
|
# create codelet for comparing model output |
242 |
|
cat > tmp_cmpnum.f <<EOFA |
243 |
|
program cmpnum |
244 |
|
implicit none |
245 |
|
real*8 a,b,diff |
246 |
|
integer linnum,best |
247 |
|
best=-16 |
248 |
|
99 read(*,*,end=70,err=60) linnum,a,b |
249 |
|
diff=0.5*(abs(a)+abs(b)) |
250 |
|
if (diff.gt.0.) then |
251 |
|
diff=abs(a-b)/diff |
252 |
|
if (diff.gt.0.) then |
253 |
|
c print *,int(log10(diff)),diff |
254 |
|
linnum=int(log10(diff)) |
255 |
|
best=max(best,linnum) |
256 |
|
c else |
257 |
|
c print *,-16 |
258 |
endif |
endif |
259 |
set accuracy=`echo $accuracy | sed 's/\./../'` |
c else |
260 |
end |
c diff=0. |
261 |
echo "" |
c print *,-16 |
|
if ($?fail ) then |
|
|
if (! $?fails) set fails |
|
|
set fails=($fails $dr) |
|
|
set pass=FAIL |
|
|
echo " ***** FAIL *****" |
|
|
else |
|
|
if (! $?passes) set passes |
|
|
set passes=($passes $dr) |
|
|
set pass=Pass |
|
|
echo "" |
|
|
echo " ***** PASS (grade $lvl) *****" |
|
262 |
endif |
endif |
263 |
set accuracy=$lvl |
goto 99 |
264 |
else |
60 stop 'cmpnum: An error occured reading a,b' |
265 |
set exactmatch=Yes |
70 print *,-best |
266 |
set pass=Pass |
end |
267 |
echo "" |
EOFA |
268 |
echo Model passed at highest accuracy. |
f77 tmp_cmpnum.f |
269 |
echo "" |
if [ -x ./a.out ]; then |
270 |
echo " ***** PASS *****" |
return 0 |
271 |
if (! $?passes) set passes |
else |
272 |
set passes=($passes $dr) |
echo createcodelet: failed to compile codelet 1>&2 |
273 |
endif |
exit 1 |
274 |
|
fi |
275 |
|
} |
276 |
|
|
277 |
|
formatresults() |
278 |
|
{ |
279 |
|
# formatresults expt genmake depend make run results* |
280 |
|
|
281 |
|
nm=$1 |
282 |
|
printf '%s %s %s %s' $2 $3 $4 $5 |
283 |
|
shift; shift; shift; shift; shift; |
284 |
|
printf '%3s' $@ |
285 |
|
|
286 |
|
if [ $1 = '--' ]; then |
287 |
|
printf ' N/O ' |
288 |
|
else |
289 |
|
if [ $1 -gt 12 ]; then |
290 |
|
printf ' pass' |
291 |
else |
else |
292 |
echo " error" |
printf ' FAIL' |
293 |
echo " ***** An error occured running the model *****" |
fi |
294 |
tail output.txt |
fi |
295 |
echo The runtime error occured in \"$dr\" |
printf ' %s' $nm |
296 |
if ($?on_error_die) exit 1 |
printf '\n' |
297 |
set pass=- |
|
298 |
endif |
} |
299 |
rm -f high.txt oldhigh.txt low.txt oldlow.txt output.txt make.log |
|
300 |
endif |
show_help() |
301 |
cd .. |
{ |
302 |
endif |
cat - << EOF |
303 |
echo "" |
$0 [-help] [-quick] [-verbose] dir1 [dir2] [...] |
304 |
cd .. |
-help Show this help message |
305 |
# Pretty summary |
-quick Skip "genmake" and "make depend" if the Makefile exists |
306 |
printresults: |
-quiet Reduce the amount of output |
307 |
printf ' %s\t %s\t %s\t %s\t %s\t %s\t %s\t%s\n' $config $makedepend $compile $execute $exactmatch $accuracy $pass $dr >> summary.txt |
-verbose Produce copious amounts of output |
308 |
end |
|
309 |
echo ============================================================================== |
Normal usage: |
310 |
echo "" |
$0 * Configure, compile, run and analyze in all experiment directories |
311 |
|
EOF |
312 |
|
} |
313 |
|
|
314 |
|
############################################################################### |
315 |
|
|
316 |
|
# Main function |
317 |
|
|
318 |
|
# Default properties |
319 |
|
debug=0 |
320 |
|
verbose=1 |
321 |
|
quick=0 |
322 |
|
testmore=0 |
323 |
|
expts='' |
324 |
|
|
325 |
|
# Process arguments |
326 |
|
for arg in $@ |
327 |
|
do |
328 |
|
case $arg in |
329 |
|
-quick) quick=1;; |
330 |
|
-verbose) verbose=2;; |
331 |
|
-debug) debug=1;; |
332 |
|
-testmore) testmore=1;; |
333 |
|
-quiet) verbose=0;; |
334 |
|
-help) show_help; exit 0;; |
335 |
|
*) test -d $arg && expts=`echo $expts $arg`;; |
336 |
|
esac |
337 |
|
done |
338 |
|
|
339 |
|
if [ ${#expts} -eq 0 ]; then |
340 |
|
echo Scanning all directories |
341 |
|
for arg in * |
342 |
|
do |
343 |
|
test -d $arg && expts=`echo $expts $arg` |
344 |
|
done |
345 |
|
fi |
346 |
|
|
347 |
|
createcodelet |
348 |
|
|
349 |
|
if [ $testmore -eq 0 ]; then |
350 |
|
cat << EOF > summary.txt |
351 |
|
T S U V |
352 |
|
C D M c m s m s m s m s |
353 |
|
n p a R g m m e . m m e . m m e . m m e . |
354 |
|
f n k u 2 i a a d i a a d i a a d i a a d |
355 |
|
g d e n d n x n . n x n . n x n . n x n . |
356 |
|
|
357 |
|
EOF |
358 |
|
else |
359 |
|
cat << EOF > summary.txt |
360 |
|
T S U V |
361 |
|
C D M c |
362 |
|
n p a R g m m m m m m m m |
363 |
|
f n k u 2 i a i a i a i a |
364 |
|
g d e n d n x n x n x n x |
365 |
|
|
366 |
|
EOF |
367 |
|
fi |
368 |
|
|
369 |
|
# Now configue, make, run and test in each directory |
370 |
|
for dir in $expts |
371 |
|
do |
372 |
|
if [ -r $dir/results/output.txt ]; then |
373 |
|
echo ------------------------------------------------------------------------------- |
374 |
|
echo |
375 |
|
echo Experiment: $dir |
376 |
|
echo |
377 |
|
unset genmake makedepend make run |
378 |
|
results='-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --' |
379 |
|
results='-- -- -- -- -- -- -- -- --' |
380 |
|
genmakemodel $dir/input && genmake=Y \ |
381 |
|
&& makedependmodel $dir/input && makedepend=Y \ |
382 |
|
&& makemodel $dir/input && make=Y \ |
383 |
|
&& runmodel $dir/input mitgcmuv && run=Y \ |
384 |
|
&& results=`testoutput $dir` |
385 |
|
echo |
386 |
|
formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results |
387 |
|
echo |
388 |
|
formatresults $dir ${genmake:-N} ${makedepend:-N} ${make:-N} ${run:-N} $results >> summary.txt |
389 |
|
fi |
390 |
|
done |
391 |
|
|
392 |
|
rm tmp_cmpnum.f a.out |
393 |
|
|
394 |
echo "Summary:" |
echo ------------------------------------------------------------------------------- |
395 |
echo "" |
echo |
396 |
cat summary.txt |
cat summary.txt |