/[MITgcm]/MITgcm/tools/tst_2+2
ViewVC logotype

Contents of /MITgcm/tools/tst_2+2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.13 - (show annotations) (download)
Mon Jan 11 20:46:05 2016 UTC (3 years, 3 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65s, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, HEAD
Changes since 1.12: +9 -4 lines
try to ignore difference between +0 and -0 in binary file, causing
 test to fail for no good reason.

1 #! /usr/bin/env bash
2
3 # $Header: /u/gcmpack/MITgcm/tools/tst_2+2,v 1.12 2012/05/08 15:09:26 jmc Exp $
4 # $Name: $
5
6 rnp_loc()
7 {
8 # rnp_loc arg_1 arg_2
9 # rename files with prefix = 'arg_1' to files with prefix = 'arg_2'
10 if [ $prt -ge 1 ] ; then echo ' rnp_loc:' $1 $2 ; fi
11 # rnp -s $1 $2
12 listY=`ls -1 $1*`
13 for yy in $listY
14 do
15 zz=`echo $yy | sed "s/^$1/$2/"`
16 if [ $prt -ge 2 ] ; then echo ' '$cmdMV $yy $zz ; fi
17 if test $action = 1 ; then $cmdMV $yy $zz ; fi
18 done
19 }
20
21 #-----------
22
23 move_outp()
24 {
25 # move_outp arg_1
26 # move mitgcm output files to directory 'arg_1'
27 if [ $prt -ge 1 ] ; then echo ' move_outp:' $1 ; fi
28 mv *.data *.meta $1
29 listF=`ls -1 *.txt STD???.00?? 2> /dev/null`
30 if test "x$listF" != x ; then mv $listF $1 ; fi
31 #- move back sym link:
32 listL=`find $1 -type l`
33 ttd=`echo $listL | wc -w`
34 #echo "ttd=$ttd"
35 if test $ttd != 0 ; then
36 #echo "listL='$listL'"
37 if [ $prt -ge 2 ] ; then echo " mv back:" $listL | sed "s/$1\///g" ; fi
38 mv $listL .
39 fi
40 }
41
42 #---------------------------
43
44 #- exit status:
45 # 0 -> test is successful
46 # 1 -> fail in 1rst run
47 # 2 -> fail in 2nd run
48 # 3 -> fail in 3rd run
49 # 4 -> pickup*.data (written at the end of 2+2 & 4 it run) are different
50 # 5 -> pickup*.meta (written at the end of 2+2 & 4 it run) are different
51 # 6 -> missing 'data.tst' file (removed or not yet generated ?)
52 # 7 -> missing executable or standard output from previous run
53 # 8 -> missing information (in standard output of previous run) about pickup
54 # 9 -> error in argument list
55
56 #- default:
57 Nit=2
58 prt=1 # 1 = print some informations ; 2 = print more informations
59 action=1
60 cmdMV='mv -f'
61 tmpDir='temp_tst'
62 wait2run=0 # if needs sometime for file system syncro on all nodes
63
64 #- default executable, command-line , using MPI:
65 gcmEXE=./mitgcmuv
66 cmdEXE=
67 mpi=0
68
69 nArg=$#
70 prev=
71 for xx ; do
72 #echo "xx='$xx'"
73 # If the previous option needs an argument, assign it.
74 if test -n "$prev"; then
75 eval "$prev=\$xx"
76 prev=
77 nArg=`expr $nArg - 2`
78 continue
79 fi
80
81 case $xx in
82 -mpi ) mpi=1 ; nArg=`expr $nArg - 1` ;;
83 -exe ) prev=gcmEXE ;;
84 -command ) prev=cmdEXE ;;
85 *) flag=$xx ;;
86 esac
87 done
88 #echo "cmdEXE='$cmdEXE'"
89 #echo "nArg=$nArg ; mpi=$mpi ; flag='$flag'"
90
91 case $nArg in
92 1) ;;
93 *) echo "Usage: `basename $0` flag [-mpi] [-exe EXECUTABLE] [-command COMMAND]"
94 echo " Check restart: compare 1 run of 2 x $Nit it long"
95 echo " with 2 consecutive runs of $Nit it long each"
96 echo " where: flag = 0 -> prepare (from a previous run) pickup & data files"
97 echo " flag = 1 -> do the 3 runs (using COMMAND"
98 echo " or simply using EXECUTABLE, default=$gcmEXE)"
99 echo " flag = 2 -> compare std_outp"
100 echo " flag = 3 -> compare pickup files"
101 echo " flag = 4 -> clean-up output files"
102 echo " flag = NC -> do 0,1,2,3 sequentially (no cleaning)"
103 echo " flag = All -> do 0,1,2,3,4 sequentially"
104 exit 9 ;;
105 esac
106 if test $flag = 'NC' -o $flag = 'All' ; then Multi=1 ; else Multi=0 ; fi
107
108 #-- set the run-command :
109 if test "x$cmdEXE" = x
110 then
111 if [ $mpi -ge 1 ] ; then
112 cmdEXE="mpirun -machinefile ../../mf -v -np 2 $gcmEXE"
113 else
114 cmdEXE=$gcmEXE
115 fi
116 fi
117 echo "cmdEXE='$cmdEXE'"
118 #=========================
119
120 if test $flag = '0' -o $Multi = '1' ; then
121 #----------------------------------------------------------------------
122 # check for executable:
123 if test ! -x $gcmEXE ; then
124 echo "file '$gcmEXE' does not exist or is not executable"
125 exit 7
126 fi
127 # last pickup written (from previous run):
128 if [ $mpi -ge 1 ]
129 then outpRun='STDOUT.0000'
130 else outpRun='output.txt'
131 fi
132 if test -r $outpRun
133 then
134 # grep ' %CHECKPOINT ' $outpRun | tail -1
135 lastPick=`grep ' %CHECKPOINT ' $outpRun | sed 's/^.*%CHECKPOINT //' | tail -1`
136 if test "x$lastPick" = x
137 then
138 echo "no pickup information written in '$outpRun' from previous run"
139 exit 8
140 else
141 iter=`echo $lastPick | awk '{print $1}'`
142 sufx=`echo $lastPick | awk '{print $2}'`
143 echo "from previous run $outpRun, lastPick='$lastPick' ; iter='$iter' ; sufx='$sufx'"
144 fi
145 else
146 echo "no standard output file '$outpRun' from previous run"
147 exit 7
148 fi
149
150 #-------------------------
151 echo "prepare parameter file 'data.tst' :"
152 cp -p -f data data.tst
153 listOut='startTime endTime nIter0 nTimeSteps nEndIter chkPtFreq pChkPtFreq'
154 listOut=$listOut' pickupSuff usePickupBeforeC54 mdsioLocalDir pickupStrictlyMatch'
155 #- comment out (in data.tst) all parameters from list: 'listOut'
156 for yy in $listOut
157 do
158 if [ $prt -ge 2 ] ; then echo -n ' commenting out:' $yy ; fi
159 nn=`grep -i -c "^ *$yy *=" data.tst`
160 if [ $nn -ge 1 ]
161 then
162 listN=`grep -i -n "^ *$yy *=" data.tst | sed 's/:.*$//'`
163 if [ $prt -ge 2 ] ; then echo " : found on line: $listN" ; fi
164 for ll in $listN
165 do
166 sed "$ll s/^./#&/" data.tst > data.tmp_$$
167 # diff data.tmp_$$ data.tst
168 mv -f data.tmp_$$ data.tst
169 done
170 else if [ $prt -ge 2 ] ; then echo ' : not found' ; fi
171 fi
172 done
173 if [ $prt -ge 2 ] ; then echo ' ' ; fi
174 # add nIter0 & nTimeSteps in namelist "PARM03":
175 Dbl=`expr $Nit \* 2`
176 sed "/^ *\&PARM03/a \ nTimeSteps=$Dbl," data.tst > data.tmp_$$
177 mv -f data.tmp_$$ data.tst
178 sed "/^ *\&PARM03/a \ nIter0=$iter," data.tst > data.tmp_$$
179 mv -f data.tmp_$$ data.tst
180 echo "prepare file 'data.tst' : done"
181 if [ $prt -ge 1 ] ; then
182 echo ' diff data.tst data' ; diff data.tst data ; echo ' ' ;
183 fi
184 #---- clean up current dir: move output to temp_tst dir:
185 if test $action = 1 ; then
186 rm -rf $tmpDir
187 mkdir $tmpDir
188 mv -f *.data $tmpDir
189 mv -f *.meta $tmpDir
190 mv -f *.txt $tmpDir 2> /dev/null
191 mv -f STD???.0[0-9][0-9][0-9] $tmpDir
192 #- move main parameter file "data":
193 mv -f data $tmpDir
194 #- do not deal with MNC pickup at all:
195 cp -p -f data.pkg data.tmp_$$
196 mv -f data.pkg $tmpDir
197 mv -f data.tmp_$$ data.pkg
198 yy='useMNC'
199 if [ $prt -ge 2 ] ; then echo -n " commenting out: $yy in data.pkg" ; fi
200 nn=`grep -i -c "^ *$yy *=" data.pkg`
201 if [ $nn -ge 1 ]
202 then
203 listN=`grep -i -n "^ *$yy *=" data.pkg | sed 's/:.*$//'`
204 if [ $prt -ge 2 ] ; then echo " : found on line: $listN" ; fi
205 for ll in $listN
206 do
207 sed "$ll s/^./#&/" data.pkg > data.tmp_$$
208 if [ $prt -ge 1 ] ; then echo ' changes in data.pkg'
209 diff data.tmp_$$ data.pkg ; echo ' ' ; fi
210 mv -f data.tmp_$$ data.pkg
211 done
212 else if [ $prt -ge 2 ] ; then echo ' : not found' ; echo ' ' ; fi
213 fi
214 fi
215 #-------------------------
216 #-- link back pickup files
217 listS=`ls $tmpDir/pickup*.${sufx}* 2> /dev/null | head -1`
218 if test "x$listS" != x ; then
219 if [ $prt -ge 1 ] ; then echo ' link back:' $tmpDir'/pickup*.'${sufx}'*' ; fi
220 if test $action = 1 ; then ln -s $tmpDir/pickup*.${sufx}* . ; fi
221 fi
222 #- rename pickup (if needed)
223 nIt0c=`printf "%10.10i\n" $iter`
224 if test $sufx = $nIt0c
225 then
226 echo "no need to change pickup sufix"
227 else
228 listP=`ls pickup*.${sufx}* 2> /dev/null | sed 's/\..*//g' | uniq`
229 if test "x$listP" = x
230 then echo ' rename' $sufx '->' $nIt0c ': no file to rename'
231 else
232 if [ $prt -ge 1 ] ; then echo ' rename' $sufx '->' $nIt0c 'for all:' $listP ; fi
233 for yy in $listP
234 do
235 rnp_loc $yy.${sufx} $yy.$nIt0c
236 done
237 fi
238 fi
239 #----------------------------------------------------------------------
240 fi
241
242 #=========================
243
244 if test -r data.tst ; then
245 #- extract length of runs & starting iter number from file "data.tst"
246 num0=`sed -n 's/^ nIter0=//p' data.tst | sed 's/,//g' | sed 's/ //g'`
247 Dbl=`sed -n 's/^ nTimeSteps=//p' data.tst | sed 's/,//g'`
248 Nit=`expr $Dbl / 2`
249 # Nit = Nb of iter of 2nd & 3rd run (1rst one is 2 x Nit iter long)
250 else
251 echo '=> Need a readable "data.tst" file for the 2 x Nit iterations run'
252 exit 6
253 fi
254
255 #- dir where to put the results :
256 dir1=res_2it
257 dir2=res_1iA
258 dir3=res_1iB
259
260 #---------------------------
261 num1=`expr $num0 + $Nit`
262 num2=`expr $num0 + $Dbl`
263 num0c=`printf "%10.10i\n" $num0`
264 num1c=`printf "%10.10i\n" $num1`
265 num2c=`printf "%10.10i\n" $num2`
266 echo " start-end iter: $num0 , $num1 , $num2"
267 echo " sufix: '$num0c' '$num1c' '$num2c'"
268 echo ' cmdEXE='$cmdEXE
269 #exit
270 #---------------------------
271
272 if test $flag = '1' -o $Multi = '1' ; then
273 #----------------------------------------------------------------------
274 #- check at the end of each run for pickup with prefix:
275 pref='pickup'
276 offLine=`grep -i -c '^ *useOffLine *= *\.TRUE\.' data.pkg`
277 if [ $offLine -ge 1 ] ; then pref='pickup_ptracers' ; fi
278 #---------------------------
279 if test -d $dir1 -o -d $dir2 -o -d $dir3
280 then echo -n 'remove dir: '
281 if test -d $dir1 ; then echo -n $dir1 ' , ' ; rm -r $dir1 ; fi
282 if test -d $dir2 ; then echo -n $dir2 ' , ' ; rm -r $dir2 ; fi
283 if test -d $dir3 ; then echo -n $dir3 ' , ' ; rm -r $dir3 ; fi
284 echo ' '
285 fi
286 mkdir $dir1 $dir2 $dir3
287 rm -f STDERR.0000
288
289 #--- 1rst run ( 2 x Nit iter )
290 cp -p data.tst data
291 echo '==> START RUN 2 x' $Nit 'it'
292 if [ $mpi -ge 1 ]
293 then
294 sleep $wait2run
295 $cmdEXE > TTT.out.2it 2>&1
296 mv STDOUT.0000 std_outp.2it
297 cat TTT.out.2it
298 else $cmdEXE > std_outp.2it
299 fi
300 if test ! -s std_outp.2it
301 then echo "empty or no output file: 'std_outp.2it' => exit" ; exit 1 ; fi
302 mv STDERR.0000 std__err.2it
303 out=`egrep -c 'STOP ABNORMAL END' std_outp.2it`
304 if test $out != 0
305 then echo "==> RUN 2 x $Nit it : ABNORMAL END => exit" ; exit 1 ; fi
306 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
307 if test "x$listF" = x
308 then echo "==> RUN 2 x $Nit it STOP without writing $pref => exit" ; exit 1
309 else echo "==> END RUN 2 x $Nit it" ; fi
310 listP=`ls pickup*.ckptA* | sed 's/\..*//g' | uniq`
311 echo ' listP=' $listP
312 for xx in $listP
313 do
314 rnp_loc $xx.ckptA $xx.$num2c
315 done
316 move_outp $dir1
317 #--- 2nd run ( Nit iter , restart from same Iter = num0 as 1rst run )
318 sed "s/^ nTimeSteps=$Dbl/ nTimeSteps=$Nit/g" data.tst > data.tmp
319 mv -f data.tmp data
320 echo '==> START RUN 1iA'
321 if [ $mpi -ge 1 ]
322 then
323 sleep $wait2run
324 $cmdEXE > TTT.out.1iA 2>&1
325 mv STDOUT.0000 std_outp.1iA
326 cat TTT.out.1iA
327 else $cmdEXE > std_outp.1iA
328 fi
329 if test ! -s std_outp.1iA
330 then echo "empty or no output file: 'std_outp.1iA' => exit" ; exit 2 ; fi
331 mv STDERR.0000 std__err.1iA
332 out=`egrep -c 'STOP ABNORMAL END' std_outp.1iA`
333 if test $out != 0
334 then echo "==> RUN 1iA : ABNORMAL END => exit" ; exit 2 ; fi
335 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
336 if test "x$listF" = x
337 then echo "==> RUN 1iA STOP without writing $pref => exit" ; exit 2
338 else echo "==> END RUN 1iA" ; fi
339 for xx in $listP
340 do
341 rnp_loc $xx.ckptA $xx.$num1c
342 done
343 move_outp $dir2
344 #--- 3rd run ( Nit iter , restart from 2nd )
345 ln -s $dir2/pickup*.$num1c.* .
346 sed "s/^ nIter0=$num0/ nIter0=$num1/g" data > data.tmp
347 mv -f data.tmp data
348 echo '==> START RUN 1iB'
349 if [ $mpi -ge 1 ]
350 then
351 sleep $wait2run
352 $cmdEXE > TTT.out.1iB 2>&1
353 mv STDOUT.0000 std_outp.1iB
354 cat TTT.out.1iB
355 else $cmdEXE > std_outp.1iB
356 fi
357 if test ! -s std_outp.1iB
358 then echo "empty or no output file: 'std_outp.1iB' => exit" ; exit 3 ; fi
359 mv STDERR.0000 std__err.1iB
360 out=`egrep -c 'STOP ABNORMAL END' std_outp.1iB`
361 if test $out != 0
362 then echo "==> RUN 1iB : ABNORMAL END => exit" ; exit 3 ; fi
363 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
364 if test "x$listF" = x
365 then echo "==> RUN 1iB STOP without writing $pref => exit" ; exit 3
366 else echo "==> END RUN 1iB" ; fi
367 for xx in $listP
368 do
369 rnp_loc $xx.ckptA $xx.$num2c
370 done
371 # remove pickup*.$mun1c* sym-link:
372 find . ! -name . -prune -type l -name 'pickup*.'${num1c}'*' -exec rm {} \;
373 move_outp $dir3
374 rm data
375 #----------------------------------------------------------------------
376 fi
377
378 if test $flag = '2' -o $Multi = '1' ; then
379 #----------------------------------------------------------------------
380 listCGini="2"
381 #-- check if using 3-D solver
382 nn=`grep -i -c "^ *nonHydrostatic *= *\.TRUE\." data.tst`
383 if [ $nn -eq 0 ] ; then
384 nn=`grep -i -c "^ *implicitIntGravWave *= *\.TRUE\." data.tst`
385 fi
386 if [ $nn -ge 1 ] ; then listCGini="$listCGini 3"; fi
387 for nn in $listCGini
388 do
389 echo ' ' ; echo "== compare cg${nn}d_init_res :"
390 echo ' run 1iA:'
391 grep "cg${nn}d_init_res" std_outp.1iA \
392 | sed "s/.* cg${nn}d_init_res =//"
393 echo ' run 1iB:'
394 grep "cg${nn}d_init_res" std_outp.1iB \
395 | sed "s/.* cg${nn}d_init_res =//"
396 echo ' run 2it:'
397 grep "cg${nn}d_init_res" std_outp.2it \
398 | sed "s/.* cg${nn}d_init_res =//"
399 done
400 #----------------------------------------------------------------------
401 fi
402
403 if test $flag = '3' -o $Multi = '1' ; then
404 #----------------------------------------------------------------------
405 echo ' '
406 echo "== diff pickup files : end of 1rst run (2x$Nit it) & end of 3rd run (2nd $Nit it)"
407 listP=`( cd $dir1 ; ls pickup*.$num2c* | sed 's/\..*//g' | uniq )`
408 chkmeta='Y'
409 for yy in $listP
410 do
411 listY=`(cd $dir1 ; ls $yy.$num2c*.data | sed "s/$yy\.$num2c//" | sed "s/data$//")`
412 zz=$yy.$num2c
413 echo '--> file='$zz', listY='$listY
414 for xx in $listY
415 do
416 echo ' diff' $dir1/$zz${xx}data $dir3
417 diff $dir1/$zz${xx}data $dir3
418 out=$?
419 if test $out != 0 ; then
420 #-- refined check: exclude diff between +0 and -0
421 nbDif=`cmp -l $dir1/$zz${xx}data $dir3/$zz${xx}data \
422 | sed -e '/ 0 200$/d' -e '/ 200 0$/d' | wc -l`
423 if test $nbDif != 0 ; then
424 echo "Diff outp= $out (nb-Diff= $nbDif ) ==> stop"
425 exit 4
426 fi
427 fi
428 if test $chkmeta = 'Y' -a -f $dir1/$zz${xx}meta ; then
429 echo ' diff' $dir1/$zz${xx}meta $dir3
430 diff $dir1/$zz${xx}meta $dir3
431 out=$?
432 if test $out != 0 ; then
433 echo 'Diff outp=' $out ' ==> stop'
434 exit 5
435 fi
436 fi
437 done
438 done
439 #----------------------------------------------------------------------
440 fi
441
442 if test $flag = '4' -o $flag = 'All' ; then
443 #-------------
444 echo ' '
445 echo "== clean-up and reset :"
446 echo '--> remove pickup*.'$num0c'* sym-links:'
447 #find . ! -name . -prune -type l -name 'pickup*.'${num0c}'*' -exec rm {} \;
448 listS=`find . ! -name . -prune -type l -name 'pickup*.'${num0c}'*'`
449 if [ $prt -ge 2 ] ; then echo ' rm' $listS ; fi
450 rm -f $listS
451 echo '--> remove output dir and output files:'
452 echo ' rm -rf' $dir1 $dir2 $dir3
453 rm -rf $dir1 $dir2 $dir3
454 echo ' rm -f' std_????.?i?
455 rm -f std_????.?i?
456 rm -f TTT.out.?i? 2> /dev/null
457 echo ' rm -f' data.pkg data.tst
458 rm -f data.pkg data.tst
459 #- move back files from temp_tst dir:
460 if test -d $tmpDir ; then
461 echo "--> move back files from 'temp_tst' dir."
462 cd $tmpDir ; mv -f * .. ; cd ..
463 rmdir $tmpDir
464 fi
465 #-------------
466 fi
467 exit 0

  ViewVC Help
Powered by ViewVC 1.1.22