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