/[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.10 - (show annotations) (download)
Fri Nov 4 17:42:32 2011 UTC (9 years, 5 months ago) by jmc
Branch: MAIN
Changes since 1.9: +12 -7 lines
check for executable

1 #! /usr/bin/env bash
2
3 # $Header: /u/gcmpack/MITgcm/tools/tst_2+2,v 1.9 2010/12/08 16:47:11 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
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 std.outp, 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 mv STDERR.0000 std__err.2it
301 out=`egrep -c 'STOP ABNORMAL END' std_outp.2it`
302 if test $out != 0
303 then echo "==> RUN 2 x $Nit it : ABNORMAL END => exit" ; exit 1 ; fi
304 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
305 if test "x$listF" = x
306 then echo "==> RUN 2 x $Nit it STOP without writing $pref => exit" ; exit 1
307 else echo "==> END RUN 2 x $Nit it" ; fi
308 listP=`ls pickup*.ckptA* | sed 's/\..*//g' | uniq`
309 echo ' listP=' $listP
310 for xx in $listP
311 do
312 rnp_loc $xx.ckptA $xx.$num2c
313 done
314 move_outp $dir1
315 #--- 2nd run ( Nit iter , restart from same Iter = num0 as 1rst run )
316 sed "s/^ nTimeSteps=$Dbl/ nTimeSteps=$Nit/g" data.tst > data.tmp
317 mv -f data.tmp data
318 echo '==> START RUN 1iA'
319 if [ $mpi -ge 1 ]
320 then
321 sleep $wait2run
322 $cmdEXE > TTT.out.1iA 2>&1
323 mv STDOUT.0000 std_outp.1iA
324 cat TTT.out.1iA
325 else $cmdEXE > std_outp.1iA
326 fi
327 mv STDERR.0000 std__err.1iA
328 out=`egrep -c 'STOP ABNORMAL END' std_outp.1iA`
329 if test $out != 0
330 then echo "==> RUN 1iA : ABNORMAL END => exit" ; exit 2 ; fi
331 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
332 if test "x$listF" = x
333 then echo "==> RUN 1iA STOP without writing $pref => exit" ; exit 2
334 else echo "==> END RUN 1iA" ; fi
335 for xx in $listP
336 do
337 rnp_loc $xx.ckptA $xx.$num1c
338 done
339 move_outp $dir2
340 #--- 3rd run ( Nit iter , restart from 2nd )
341 ln -s $dir2/pickup*.$num1c.* .
342 sed "s/^ nIter0=$num0/ nIter0=$num1/g" data > data.tmp
343 mv -f data.tmp data
344 echo '==> START RUN 1iB'
345 if [ $mpi -ge 1 ]
346 then
347 sleep $wait2run
348 $cmdEXE > TTT.out.1iB 2>&1
349 mv STDOUT.0000 std_outp.1iB
350 cat TTT.out.1iB
351 else $cmdEXE > std_outp.1iB
352 fi
353 mv STDERR.0000 std__err.1iB
354 out=`egrep -c 'STOP ABNORMAL END' std_outp.1iB`
355 if test $out != 0
356 then echo "==> RUN 1iB : ABNORMAL END => exit" ; exit 3 ; fi
357 listF=`ls -1 $pref.ckptA*.data 2> /dev/null`
358 if test "x$listF" = x
359 then echo "==> RUN 1iB STOP without writing $pref => exit" ; exit 3
360 else echo "==> END RUN 1iB" ; fi
361 for xx in $listP
362 do
363 rnp_loc $xx.ckptA $xx.$num2c
364 done
365 # remove pickup*.$mun1c* sym-link:
366 find . ! -name . -prune -type l -name 'pickup*.'${num1c}'*' -exec rm {} \;
367 move_outp $dir3
368 rm data
369 #----------------------------------------------------------------------
370 fi
371
372 if test $flag = '2' -o $Multi = '1' ; then
373 #----------------------------------------------------------------------
374 listCGini="2"
375 #-- check if using 3-D solver
376 nn=`grep -i -c "^ *nonHydrostatic *= *\.TRUE\." data.tst`
377 if [ $nn -eq 0 ] ; then
378 nn=`grep -i -c "^ *implicitIntGravWave *= *\.TRUE\." data.tst`
379 fi
380 if [ $nn -ge 1 ] ; then listCGini="$listCGini 3"; fi
381 for nn in $listCGini
382 do
383 echo ' ' ; echo "== compare cg${nn}d_init_res :"
384 echo ' run 1iA:'
385 grep "cg${nn}d_init_res" std_outp.1iA \
386 | sed "s/.* cg${nn}d_init_res =//"
387 echo ' run 1iB:'
388 grep "cg${nn}d_init_res" std_outp.1iB \
389 | sed "s/.* cg${nn}d_init_res =//"
390 echo ' run 2it:'
391 grep "cg${nn}d_init_res" std_outp.2it \
392 | sed "s/.* cg${nn}d_init_res =//"
393 done
394 #----------------------------------------------------------------------
395 fi
396
397 if test $flag = '3' -o $Multi = '1' ; then
398 #----------------------------------------------------------------------
399 echo ' '
400 echo "== diff pickup files : end of 1rst run (2x$Nit it) & end of 3rd run (2nd $Nit it)"
401 listP=`( cd $dir1 ; ls pickup*.$num2c* | sed 's/\..*//g' | uniq )`
402 chkmeta='Y'
403 for yy in $listP
404 do
405 listY=`(cd $dir1 ; ls $yy.$num2c*.data | sed "s/$yy\.$num2c//" | sed "s/data$//")`
406 zz=$yy.$num2c
407 echo '--> file='$zz', listY='$listY
408 for xx in $listY
409 do
410 echo ' diff' $dir1/$zz${xx}data $dir3
411 diff $dir1/$zz${xx}data $dir3
412 out=$?
413 if test $out != 0 ; then
414 echo 'Diff outp=' $out ' ==> stop'
415 exit 4
416 fi
417 if test $chkmeta = 'Y' -a -f $dir1/$zz${xx}meta ; then
418 echo ' diff' $dir1/$zz${xx}meta $dir3
419 diff $dir1/$zz${xx}meta $dir3
420 out=$?
421 if test $out != 0 ; then
422 echo 'Diff outp=' $out ' ==> stop'
423 exit 5
424 fi
425 fi
426 done
427 done
428 #----------------------------------------------------------------------
429 fi
430
431 if test $flag = '4' -o $flag = 'All' ; then
432 #-------------
433 echo ' '
434 echo "== clean-up and reset :"
435 echo '--> remove pickup*.'$num0c'* sym-links:'
436 #find . ! -name . -prune -type l -name 'pickup*.'${num0c}'*' -exec rm {} \;
437 listS=`find . ! -name . -prune -type l -name 'pickup*.'${num0c}'*'`
438 if [ $prt -ge 2 ] ; then echo ' rm' $listS ; fi
439 rm -f $listS
440 echo '--> remove output dir and output files:'
441 echo ' rm -rf' $dir1 $dir2 $dir3
442 rm -rf $dir1 $dir2 $dir3
443 echo ' rm -f' std_????.?i?
444 rm -f std_????.?i?
445 rm -f TTT.out.?i? 2> /dev/null
446 echo ' rm -f' data.pkg data.tst
447 rm -f data.pkg data.tst
448 #- move back files from temp_tst dir:
449 if test -d $tmpDir ; then
450 echo "--> move back files from 'temp_tst' dir."
451 cd $tmpDir ; mv -f * .. ; cd ..
452 rmdir $tmpDir
453 fi
454 #-------------
455 fi
456 exit 0

  ViewVC Help
Powered by ViewVC 1.1.22