/[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.3 - (show annotations) (download)
Sat Feb 28 18:55:48 2009 UTC (11 years, 1 month ago) by jmc
Branch: MAIN
Changes since 1.2: +32 -26 lines
simplify a little bit

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

  ViewVC Help
Powered by ViewVC 1.1.22