/[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.2 - (hide annotations) (download)
Fri Feb 27 22:58:57 2009 UTC (11 years, 1 month ago) by jmc
Branch: MAIN
Changes since 1.1: +80 -45 lines
modified for MPI test

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

  ViewVC Help
Powered by ViewVC 1.1.22