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

Annotation of /MITgcm/tools/do_tst_2+2

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


Revision 1.17 - (hide annotations) (download)
Sun Aug 18 19:55:20 2013 UTC (10 years, 8 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint64n
Changes since 1.16: +23 -11 lines
- add more options (2 new arguments) for sending results (output tar file)
  by mpack (enable to ssh to head node if compute node do not sendmail)

1 jmc 1.2 #! /usr/bin/env bash
2 jmc 1.1
3 jmc 1.17 # $Header: /u/gcmpack/MITgcm/tools/do_tst_2+2,v 1.16 2012/10/11 16:30:56 jmc Exp $
4 jmc 1.1 # $Name: $
5    
6     usage()
7     {
8     echo "Usage: `basename $0` [OPTIONS]"
9     echo " -> perform test 2+2=4 for several experiments"
10     echo ""
11     echo "where possible OPTIONS are:"
12     echo " -help : print usage"
13     echo " -t LIST_EXP : only check experiments in LIST_EXP"
14     echo " -skd LIST_EXP : skip experiments in LIST_EXP"
15 jmc 1.3 echo " -exe COMMAND : use COMMAND to run the tests"
16     echo " -mpi : run the tests using MPI"
17 jmc 1.10 echo " -mf STRING :(MPI) file with list of possible machines to run on"
18 jmc 1.2 echo " -o STRING : used to build output directory name"
19 jmc 1.1 echo " (DEF=\"hostname\")"
20 jmc 1.2 echo " -a,-A STRING : email address to send output to"
21 jmc 1.1 echo " (DEF=\"\" no email is sent)"
22 jmc 1.2 echo " (-A: + save each log file)"
23 jmc 1.17 echo " -send STRING : sending command (instead of using mpack)"
24     echo " -sd STRING : location to save output tar file to send (DEF='$SAVDIR')"
25 jmc 1.1 echo " -clean : clean output & reset"
26     exit
27     }
28    
29     CLEAN=0
30     TESTDIRS=
31     SKIPDIRS=
32 jmc 1.3 SCRIPT='../tools/tst_2+2'
33 jmc 1.13 LOGFILE='tst_2+2_out.log'
34 jmc 1.5 scrArg='All'
35 jmc 1.3 COMMAND=
36     mpi=0
37 jmc 1.10 MPI_MFILE=
38 jmc 1.4 OUTDIR=`hostname | sed 's/\..*$//'`
39 jmc 1.2 SAVELOG=0
40 jmc 1.1 ADDRESS=
41     MPACK="../tools/mpack-1.6/mpack"
42 jmc 1.17 SENDCMD=
43     SAVDIR='.'
44 jmc 1.1 here=`pwd`
45     yy=
46     for xx
47     do
48     if test -n "$yy"; then
49     eval "$yy=\$xx"
50     yy=
51     else
52     case $xx in
53     -help ) usage ;;
54     -clean) CLEAN=1 ;;
55     -t ) yy=TESTDIRS ;;
56     -skd ) yy=SKIPDIRS ;;
57 jmc 1.3 -exe ) yy=COMMAND ;;
58     -mpi ) mpi=1 ;;
59 jmc 1.10 -mf ) yy=MPI_MFILE ;;
60 jmc 1.1 -a ) yy=ADDRESS ;;
61 jmc 1.2 -A ) yy=ADDRESS ; SAVELOG=1 ;;
62 jmc 1.17 -send ) yy=SENDCMD ;;
63     -sd ) yy=SAVDIR ;;
64 jmc 1.1 -o ) yy=OUTDIR ;;
65     *) echo "Error: unrecognized option: "$xx ; usage ; exit ;;
66     esac
67     fi
68     done
69     #------------------------
70    
71 jmc 1.2 if test "x$TESTDIRS" = x ; then TESTDIRS=`ls ` ; fi
72 jmc 1.1 LIST=""
73     for xx in $TESTDIRS
74     do
75     yy=`echo $SKIPDIRS | grep -c $xx`
76     if test $yy = 0 ; then
77 jmc 1.2 if test -f $xx/results/output.txt ; then
78 jmc 1.1 LIST=${LIST}" "$xx
79     # else
80     # echo ""; echo -n " -- skip \"$xx\" (not a directory !)"
81     fi
82     # else
83     # echo ""; echo -n " -- skip \"$xx\" (excluded)"
84     fi
85     done
86    
87 jmc 1.16 if test -x $SCRIPT ; then
88     if test $CLEAN = 1 ; then
89     echo "clean output from script '$SCRIPT' for experiment in:"
90     else
91     echo "run script '$SCRIPT' for experiment in:"
92     fi
93     echo " $LIST"
94     echo ""
95     yy=`echo $SCRIPT | grep -c '^\/'`
96     if test $yy = 0 ; then SCRIPT="../../$SCRIPT" ; fi
97     else
98     echo "ERROR: script '$SCRIPT' not found or not executable"
99     exit
100     fi
101 jmc 1.1 #------------------------
102 jmc 1.16
103 jmc 1.1 if test $CLEAN = 1 ; then
104     for xx in $LIST
105     do
106     listD='run '`(cd $xx/results ; ls output.*.txt 2> /dev/null | sed 's/^output\./tr_run./g' | sed 's/\.txt$//g' )`
107     for yy in $listD
108     do
109 jmc 1.2 if test -r $xx/$yy/data.tst ; then
110 jmc 1.1 echo "clean dir:" $xx/$yy
111 jmc 1.2 cd $xx/$yy
112 jmc 1.12 echo ' ' >> $LOGFILE
113     echo $SCRIPT 4 >> $LOGFILE
114     $SCRIPT 4 >> $LOGFILE 2>&1
115 jmc 1.1 cd $here
116     fi
117     done
118     done
119     exit
120     fi
121     #------------------------
122     # Create a uniquely named directory to store results
123 jmc 1.10 CMDLINE=$0
124     for xx in "$@" ; do nw=`echo $xx | wc -w`
125     if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
126     else CMDLINE="$CMDLINE '$xx'" ; fi
127     done
128     #for xx in "$@" ; do CMDLINE="$CMDLINE '$xx'" ; done
129 jmc 1.14 DATE=''
130     if test -f tr_out.txt ; then
131     # try to use the date corresponding to 'Start time:' in file "tr_out.txt" :
132     sTime=`grep '^Start time: ' tr_out.txt 2>/dev/null | sed 's/Start time: //'`
133     if test "x$sTime" != x ; then DATE=`date -d "$sTime" "+%Y%m%d" 2>/dev/null` ; fi
134     fi
135     # otherwise, use current date:
136     if test "x$DATE" = x ; then DATE=`date +%Y%m%d`; fi
137 jmc 1.1 BASE="rs_"$OUTDIR"_"$DATE"_"
138     xx=0
139     DRESULTS="$BASE$xx"
140     while test -e $DRESULTS ; do
141     xx=$(( $xx + 1 ))
142     DRESULTS="$BASE$xx"
143     done
144     mkdir $DRESULTS
145     out=$?
146     if test "x$out" != x0 ; then
147     echo "ERROR: Can't create results directory \"./$DRESULTS\""
148     exit 1
149     fi
150     SUMMARY="$DRESULTS/summary.txt"
151     OPTFILE=
152    
153     printf "Start time: " > $SUMMARY
154     date >> $SUMMARY
155 jmc 1.10 echo 'run:' $CMDLINE >> $SUMMARY
156 jmc 1.1 if test -f tr_out.txt ; then
157     echo ' using output from:' >> $SUMMARY
158 jmc 1.11 sed -n '2,/^ OPTFILE=/ p' tr_out.txt >> $SUMMARY
159 jmc 1.1 echo >> $SUMMARY
160     fi
161     echo 'test 2+2=4 summary :' >> $SUMMARY
162     echo >> $SUMMARY
163     echo 'P. Run Result experiment' >> $SUMMARY
164     echo ' 1 2 3' >> $SUMMARY
165    
166 jmc 1.3 #-- For MPI test:
167 jmc 1.10 LOC_MFILE='tr_mpi_mfile'
168 jmc 1.3 RUNOUTP="output.txt"
169     if [ $mpi -ge 1 ] ; then
170     SCRIPT="$SCRIPT -mpi"
171     RUNOUTP="STDOUT.0000"
172     fi
173    
174 jmc 1.1 for xx in $LIST
175     do
176 jmc 1.15 echo '------------------------------------------------------------------------------'
177 jmc 1.10 if [ $mpi -le 0 ] ; then
178     rCommand=$COMMAND
179     else
180     LOC_NPROC=2
181 jmc 1.8 mpi_size=$xx/build/SIZE.h.mpi
182     if test -f $mpi_size ; then
183     px=`grep '^ & *nPx *=' $mpi_size | sed 's/^ & *nPx *= *//' | sed 's/, *$//'`
184     py=`grep '^ & *nPy *=' $mpi_size | sed 's/^ & *nPy *= *//' | sed 's/, *$//'`
185     pp=`expr $px \* $py` > /dev/null 2>&1 ; out=$?
186 jmc 1.10 if test "x$out" = x0 ; then LOC_NPROC=$pp ; fi
187     fi
188     rCommand=`echo $COMMAND | sed "s/ TR_NPROC / $LOC_NPROC /"`
189     if test "x$MPI_MFILE" != x ; then
190     #- create new MPI machine-file with the right number of Procs
191     rm -f $LOC_MFILE
192     cat $MPI_MFILE | sort | uniq | head -$LOC_NPROC > $LOC_MFILE
193     nl=`wc -l $LOC_MFILE | awk '{print $1}'`
194     if [ $nl -lt $LOC_NPROC ] ; then
195     rm -f $LOC_MFILE
196     cat $MPI_MFILE | head -$LOC_NPROC > $LOC_MFILE
197     fi
198     rCommand=`echo $rCommand | sed "s/ TR_MFILE / ..\/..\/$LOC_MFILE /"`
199 jmc 1.8 fi
200     fi
201 jmc 1.10
202 jmc 1.1 listD='run '`(cd $xx/results ; ls output.*.txt 2> /dev/null | sed 's/^output\./tr_run./g' | sed 's/\.txt$//g' )`
203     for yy in $listD
204     do
205 jmc 1.3 if test -f $xx/$yy/$RUNOUTP ; then
206 jmc 1.1 if test "x$OPTFILE" = x -a -f $xx/build/Makefile ; then
207     comm=`grep '^# OPTFILE=' $xx/build/Makefile 2>/dev/null | head -1 | sed 's/^# //'`
208     echo "from '$xx/build/Makefile', extract:" > $DRESULTS/genmake_state
209 jmc 1.6 sed -n '/^# executed by:/,+1 p' $xx/build/Makefile >> $DRESULTS/genmake_state
210 jmc 1.7 echo " $comm" >> $DRESULTS/genmake_state
211 jmc 1.1 eval $comm
212 jmc 1.7 gmkLog=$xx/build/genmake.log
213     grep '^Get compiler version using:' $gmkLog > /dev/null 2>&1
214     out=$?
215     if test "x$out" = x0 ; then
216     echo "from '$gmkLog', extract compiler version:" >> $DRESULTS/genmake_state
217     sed -n '/Get compiler version/,/<-- compiler version/p' $gmkLog \
218     | grep -v '^... compiler version ' > tr_vers.tmp_log
219     sed -n '1,/^$/p' tr_vers.tmp_log | sed '/^$/d' | sed 's/^./ &/' \
220     >> $DRESULTS/genmake_state
221     rm -f tr_vers.tmp_log
222     fi
223 jmc 1.1 fi
224 jmc 1.2 if test $yy = 'run' ; then nam=$xx
225 jmc 1.1 else nam=$xx`echo $yy | sed 's/tr_run//'` ; fi
226     echo -n "Entering $xx/$yy :"
227     cd $xx/$yy
228 jmc 1.12 pwd > $LOGFILE
229 jmc 1.3 if test "x$COMMAND" = x ; then
230 jmc 1.12 echo $SCRIPT $scrArg >> $LOGFILE ; echo ' ' >> $LOGFILE
231     $SCRIPT $scrArg >> $LOGFILE 2>&1
232 jmc 1.3 out=$?
233     else
234 jmc 1.12 echo "$SCRIPT $scrArg -command \"$rCommand\"" >> $LOGFILE
235     echo ' ' >> $LOGFILE
236     $SCRIPT $scrArg -command "$rCommand" >> $LOGFILE 2>&1
237 jmc 1.3 out=$?
238     fi
239 jmc 1.1 case $out in
240     0 ) echo ' pass test 2+2=4'
241     echo "Y Y Y Y pass <- $nam" >> ../../$SUMMARY ;;
242     4|5) echo "Y Y Y Y FAIL ($out) - $nam" >> ../../$SUMMARY ;;
243     3 ) echo "Y Y Y N FAIL ($out) - $nam" >> ../../$SUMMARY ;;
244     2 ) echo "Y Y N N FAIL ($out) - $nam" >> ../../$SUMMARY ;;
245     1 ) echo "Y N N N FAIL ($out) - $nam" >> ../../$SUMMARY ;;
246     * ) echo "N N N N FAIL ($out) - $nam" >> ../../$SUMMARY ;;
247     esac
248 jmc 1.2 if test $out != '0' ; then
249 jmc 1.1 echo " test 2+2=4 FAIL (exit $out)"
250     echo " "
251 jmc 1.12 tail -5 $LOGFILE
252 jmc 1.1 echo " "
253 jmc 1.12 cp -p $LOGFILE ../../$DRESULTS/$nam.log
254 jmc 1.2 elif test $SAVELOG = 1 ; then
255 jmc 1.12 cp -p $LOGFILE ../../$DRESULTS/$nam.log
256 jmc 1.1 fi
257     cd $here
258     fi
259     done
260 jmc 1.10 if test "x$mpi" != x0 -a "x$MPI_MFILE" != x ; then rm -f $LOC_MFILE ; fi
261 jmc 1.1 done
262     printf "End time: " >> $SUMMARY
263     date >> $SUMMARY
264    
265 jmc 1.17 # If address was supplied, then send email using Send-Command or mpack.
266 jmc 1.1 if test "x$ADDRESS" != xNONE -a "x$ADDRESS" != x ; then
267 jmc 1.17 if test "x$SENDCMD" = x ; then
268     # if Send-Command is empty and mpack exist, then send email using mpack.
269     if test -x $MPACK ; then SENDCMD=$MPACK
270     else
271     echo "Warning: $MPACK is not executable => no email was sent"
272     echo
273     fi
274     fi
275     if test "x$SENDCMD" != x ; then
276     #echo " run: $SENDCMD -s MITgcm-test -m 3555000 ${SAVDIR}/${DRESULTS}".tar.gz" $ADDRESS"
277     tar -cf ${SAVDIR}/${DRESULTS}".tar" $DRESULTS > /dev/null 2>&1 \
278     && gzip ${SAVDIR}/${DRESULTS}".tar" \
279     && $SENDCMD -s MITgcm-test -m 3555000 ${SAVDIR}/${DRESULTS}".tar.gz" $ADDRESS
280 jmc 1.1 out=$?
281     if test "x$out" != x0 ; then
282     echo
283     echo "Warning: The tar, gzip, & mpack step failed. Please send email"
284     echo " to <MITgcm-support@mitgcm.org> for help. You may copy the "
285     echo " summary of results from the directory \"$DRESULTS\"."
286     echo
287     else
288     echo
289     echo "An email containing results was sent to the following address:"
290     echo " \"$ADDRESS\""
291     echo
292     fi
293 jmc 1.17 test -f ${SAVDIR}/${DRESULTS}".tar" && rm -f ${SAVDIR}/${DRESULTS}".tar"
294     test -f ${SAVDIR}/${DRESULTS}".tar.gz" && rm -f ${SAVDIR}/${DRESULTS}".tar.gz"
295 jmc 1.1 fi
296     fi
297    
298     # save output and remove output Dir (if no address was provided)
299     # note: to keep the output Dir without sending email, use option "-a NONE"
300     if test -f tst_2+2_out.txt ; then mv -f tst_2+2_out.txt tst_2+2_out.old ; fi
301     cp -p $SUMMARY tst_2+2_out.txt
302     if test "x$ADDRESS" = x ; then
303     rm -rf $DRESULTS
304     fi

  ViewVC Help
Powered by ViewVC 1.1.22