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

Annotation of /MITgcm/tools/tst_2+2

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


Revision 1.9 - (hide annotations) (download)
Wed Dec 8 16:47:11 2010 UTC (9 years, 8 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint63d, checkpoint63a, checkpoint63b, checkpoint63c, checkpoint63, checkpoint62s, checkpoint62r, checkpoint62q, checkpoint62p, checkpoint62w, checkpoint62v, checkpoint62u, checkpoint62t, checkpoint62z, checkpoint62y, checkpoint62x
Changes since 1.8: +3 -3 lines
when running 2+2 test, keep "globalFiles" and comment out "pickupStrictlyMatch"

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

  ViewVC Help
Powered by ViewVC 1.1.22