/[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.5 - (hide annotations) (download)
Tue Mar 3 20:59:40 2009 UTC (11 years ago) by jmc
Branch: MAIN
CVS Tags: checkpoint61j, checkpoint61k
Changes since 1.4: +2 -2 lines
works also when I use "sed --posix" (-> to disable all GNU extensions)

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

  ViewVC Help
Powered by ViewVC 1.1.22