Warning, /tools/do_tst_2+2 is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit 1e25bc25 on 2021-02-16 20:56:47 UTC
7b2766af35 Jean*0001 #! /usr/bin/env bash
afbc98f124 Jean*0002
0003 usage()
0004 {
0005 echo "Usage: `basename $0` [OPTIONS]"
0006 echo " -> perform test 2+2=4 for several experiments"
0007 echo ""
0008 echo "where possible OPTIONS are:"
0009 echo " -help : print usage"
0010 echo " -t LIST_EXP : only check experiments in LIST_EXP"
0011 echo " -skd LIST_EXP : skip experiments in LIST_EXP"
828ecdcdfe Jean*0012 echo " -exe COMMAND : use COMMAND to run the tests"
0013 echo " -mpi : run the tests using MPI"
e6cdfd97b6 Jean*0014 echo " -mf STRING :(MPI) file with list of possible machines to run on"
7b2766af35 Jean*0015 echo " -o STRING : used to build output directory name"
afbc98f124 Jean*0016 echo " (DEF=\"hostname\")"
7b2766af35 Jean*0017 echo " -a,-A STRING : email address to send output to"
afbc98f124 Jean*0018 echo " (DEF=\"\" no email is sent)"
7b2766af35 Jean*0019 echo " (-A: + save each log file)"
de5f6fb872 Jean*0020 echo " -send STRING : sending command (instead of using mpack)"
0021 echo " -sd STRING : location to save output tar file to send (DEF='$SAVDIR')"
afbc98f124 Jean*0022 echo " -clean : clean output & reset"
0023 exit
0024 }
0025
0026 CLEAN=0
0027 TESTDIRS=
0028 SKIPDIRS=
828ecdcdfe Jean*0029 SCRIPT='../tools/tst_2+2'
724b6a1f2d Jean*0030 LOGFILE='tst_2+2_out.log'
d35b4aed40 Jean*0031 scrArg='All'
8fdca21f63 Jean*0032 bldDir='build'
828ecdcdfe Jean*0033 COMMAND=
0034 mpi=0
e6cdfd97b6 Jean*0035 MPI_MFILE=
f1bc470d99 Jean*0036 OUTDIR=`hostname -s | tr '[:upper:]' '[:lower:]'`
7b2766af35 Jean*0037 SAVELOG=0
afbc98f124 Jean*0038 ADDRESS=
0039 MPACK="../tools/mpack-1.6/mpack"
de5f6fb872 Jean*0040 SENDCMD=
0041 SAVDIR='.'
faf4966244 jm-c 0042 HERE=`pwd`
afbc98f124 Jean*0043 yy=
0044 for xx
0045 do
0046 if test -n "$yy"; then
0047 eval "$yy=\$xx"
0048 yy=
0049 else
0050 case $xx in
0051 -help ) usage ;;
0052 -clean) CLEAN=1 ;;
0053 -t ) yy=TESTDIRS ;;
0054 -skd ) yy=SKIPDIRS ;;
828ecdcdfe Jean*0055 -exe ) yy=COMMAND ;;
0056 -mpi ) mpi=1 ;;
e6cdfd97b6 Jean*0057 -mf ) yy=MPI_MFILE ;;
afbc98f124 Jean*0058 -a ) yy=ADDRESS ;;
7b2766af35 Jean*0059 -A ) yy=ADDRESS ; SAVELOG=1 ;;
de5f6fb872 Jean*0060 -send ) yy=SENDCMD ;;
0061 -sd ) yy=SAVDIR ;;
afbc98f124 Jean*0062 -o ) yy=OUTDIR ;;
0063 *) echo "Error: unrecognized option: "$xx ; usage ; exit ;;
0064 esac
0065 fi
0066 done
0067 #------------------------
0068
7b2766af35 Jean*0069 if test "x$TESTDIRS" = x ; then TESTDIRS=`ls ` ; fi
afbc98f124 Jean*0070 LIST=""
0071 for xx in $TESTDIRS
0072 do
0073 yy=`echo $SKIPDIRS | grep -c $xx`
0074 if test $yy = 0 ; then
7b2766af35 Jean*0075 if test -f $xx/results/output.txt ; then
afbc98f124 Jean*0076 LIST=${LIST}" "$xx
0077 # else
0078 # echo ""; echo -n " -- skip \"$xx\" (not a directory !)"
0079 fi
0080 # else
0081 # echo ""; echo -n " -- skip \"$xx\" (excluded)"
0082 fi
0083 done
0084
1f58d1a977 Jean*0085 if test -x $SCRIPT ; then
0086 if test $CLEAN = 1 ; then
0087 echo "clean output from script '$SCRIPT' for experiment in:"
0088 else
0089 echo "run script '$SCRIPT' for experiment in:"
0090 fi
1af1b89a55 Jean*0091 echo " $LIST"
0092 echo ""
1f58d1a977 Jean*0093 yy=`echo $SCRIPT | grep -c '^\/'`
0094 if test $yy = 0 ; then SCRIPT="../../$SCRIPT" ; fi
0095 else
0096 echo "ERROR: script '$SCRIPT' not found or not executable"
0097 exit
0098 fi
0099 #------------------------
0100
0101 if test $CLEAN = 1 ; then
afbc98f124 Jean*0102 for xx in $LIST
0103 do
0104 listD='run '`(cd $xx/results ; ls output.*.txt 2> /dev/null | sed 's/^output\./tr_run./g' | sed 's/\.txt$//g' )`
0105 for yy in $listD
0106 do
7b2766af35 Jean*0107 if test -r $xx/$yy/data.tst ; then
afbc98f124 Jean*0108 echo "clean dir:" $xx/$yy
faf4966244 jm-c 0109 ( cd $xx/$yy
0110 echo ' ' >> $LOGFILE
0111 echo $SCRIPT 4 >> $LOGFILE
0112 $SCRIPT 4 >> $LOGFILE 2>&1
0113 )
afbc98f124 Jean*0114 fi
0115 done
0116 done
0117 exit
0118 fi
0119 #------------------------
0120 # Create a uniquely named directory to store results
e6cdfd97b6 Jean*0121 CMDLINE=$0
0122 for xx in "$@" ; do nw=`echo $xx | wc -w`
0123 if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
0124 else CMDLINE="$CMDLINE '$xx'" ; fi
0125 done
1f1cc94330 Jean*0126 DATE=''
0127 if test -f tr_out.txt ; then
0128 # try to use the date corresponding to 'Start time:' in file "tr_out.txt" :
0129 sTime=`grep '^Start time: ' tr_out.txt 2>/dev/null | sed 's/Start time: //'`
0130 if test "x$sTime" != x ; then DATE=`date -d "$sTime" "+%Y%m%d" 2>/dev/null` ; fi
0131 fi
0132 # otherwise, use current date:
0133 if test "x$DATE" = x ; then DATE=`date +%Y%m%d`; fi
afbc98f124 Jean*0134 BASE="rs_"$OUTDIR"_"$DATE"_"
0135 xx=0
0136 DRESULTS="$BASE$xx"
0137 while test -e $DRESULTS ; do
0138 xx=$(( $xx + 1 ))
0139 DRESULTS="$BASE$xx"
0140 done
0141 mkdir $DRESULTS
0142 out=$?
0143 if test "x$out" != x0 ; then
0144 echo "ERROR: Can't create results directory \"./$DRESULTS\""
0145 exit 1
0146 fi
0147 SUMMARY="$DRESULTS/summary.txt"
0148 OPTFILE=
0149
0150 printf "Start time: " > $SUMMARY
0151 date >> $SUMMARY
e6cdfd97b6 Jean*0152 echo 'run:' $CMDLINE >> $SUMMARY
afbc98f124 Jean*0153 if test -f tr_out.txt ; then
0154 echo ' using output from:' >> $SUMMARY
cbc5a38a4b Jean*0155 sed -n '2,/^ OPTFILE=/ p' tr_out.txt >> $SUMMARY
afbc98f124 Jean*0156 echo >> $SUMMARY
0157 fi
0158 echo 'test 2+2=4 summary :' >> $SUMMARY
0159 echo >> $SUMMARY
0160 echo 'P. Run Result experiment' >> $SUMMARY
0161 echo ' 1 2 3' >> $SUMMARY
0162
828ecdcdfe Jean*0163 #-- For MPI test:
e6cdfd97b6 Jean*0164 LOC_MFILE='tr_mpi_mfile'
828ecdcdfe Jean*0165 RUNOUTP="output.txt"
0166 if [ $mpi -ge 1 ] ; then
0167 SCRIPT="$SCRIPT -mpi"
0168 RUNOUTP="STDOUT.0000"
1e25bc2551 Jean*0169 if test "x$COMMAND" = x ; then COMMAND="mpirun -np TR_NPROC ./mitgcmuv" ; fi
828ecdcdfe Jean*0170 fi
0171
afbc98f124 Jean*0172 for xx in $LIST
0173 do
1af1b89a55 Jean*0174 echo '------------------------------------------------------------------------------'
e6cdfd97b6 Jean*0175 if [ $mpi -le 0 ] ; then
0176 rCommand=$COMMAND
0177 else
0178 LOC_NPROC=2
8fdca21f63 Jean*0179 mpi_size=$xx/$bldDir/SIZE.h.mpi
8d24b8817c Jean*0180 if test -f $mpi_size ; then
0181 px=`grep '^ & *nPx *=' $mpi_size | sed 's/^ & *nPx *= *//' | sed 's/, *$//'`
0182 py=`grep '^ & *nPy *=' $mpi_size | sed 's/^ & *nPy *= *//' | sed 's/, *$//'`
0183 pp=`expr $px \* $py` > /dev/null 2>&1 ; out=$?
e6cdfd97b6 Jean*0184 if test "x$out" = x0 ; then LOC_NPROC=$pp ; fi
0185 fi
0186 rCommand=`echo $COMMAND | sed "s/ TR_NPROC / $LOC_NPROC /"`
0187 if test "x$MPI_MFILE" != x ; then
0188 #- create new MPI machine-file with the right number of Procs
0189 rm -f $LOC_MFILE
0190 cat $MPI_MFILE | sort | uniq | head -$LOC_NPROC > $LOC_MFILE
0191 nl=`wc -l $LOC_MFILE | awk '{print $1}'`
0192 if [ $nl -lt $LOC_NPROC ] ; then
0193 rm -f $LOC_MFILE
0194 cat $MPI_MFILE | head -$LOC_NPROC > $LOC_MFILE
0195 fi
0196 rCommand=`echo $rCommand | sed "s/ TR_MFILE / ..\/..\/$LOC_MFILE /"`
8d24b8817c Jean*0197 fi
0198 fi
e6cdfd97b6 Jean*0199
afbc98f124 Jean*0200 listD='run '`(cd $xx/results ; ls output.*.txt 2> /dev/null | sed 's/^output\./tr_run./g' | sed 's/\.txt$//g' )`
0201 for yy in $listD
0202 do
828ecdcdfe Jean*0203 if test -f $xx/$yy/$RUNOUTP ; then
8fdca21f63 Jean*0204 if test "x$OPTFILE" = x -a -f $xx/$bldDir/Makefile ; then
0205 comm=`grep '^# OPTFILE=' $xx/$bldDir/Makefile 2>/dev/null | head -1 | sed 's/^# //'`
0206 echo "from '$xx/$bldDir/Makefile', extract:" > $DRESULTS/genmake_state
935bc2f03a Jean*0207 awk "/^# executed by:/ {print;getline;print}" $xx/$bldDir/Makefile >> $DRESULTS/genmake_state
d6e8ae063a Jean*0208 echo " $comm" >> $DRESULTS/genmake_state
afbc98f124 Jean*0209 eval $comm
8fdca21f63 Jean*0210 gmkLog=$xx/$bldDir/genmake.log
d6e8ae063a Jean*0211 grep '^Get compiler version using:' $gmkLog > /dev/null 2>&1
0212 out=$?
0213 if test "x$out" = x0 ; then
0214 echo "from '$gmkLog', extract compiler version:" >> $DRESULTS/genmake_state
0215 sed -n '/Get compiler version/,/<-- compiler version/p' $gmkLog \
0216 | grep -v '^... compiler version ' > tr_vers.tmp_log
0217 sed -n '1,/^$/p' tr_vers.tmp_log | sed '/^$/d' | sed 's/^./ &/' \
0218 >> $DRESULTS/genmake_state
0219 rm -f tr_vers.tmp_log
0220 fi
afbc98f124 Jean*0221 fi
7b2766af35 Jean*0222 if test $yy = 'run' ; then nam=$xx
afbc98f124 Jean*0223 else nam=$xx`echo $yy | sed 's/tr_run//'` ; fi
0224 echo -n "Entering $xx/$yy :"
faf4966244 jm-c 0225 ( cd $xx/$yy
0226 pwd > $LOGFILE
0227 if test "x$COMMAND" = x ; then
0228 echo $SCRIPT $scrArg >> $LOGFILE ; echo ' ' >> $LOGFILE
0229 $SCRIPT $scrArg >> $LOGFILE 2>&1
0230 out=$?
0231 else
0232 echo "$SCRIPT $scrArg -command \"$rCommand\"" >> $LOGFILE
0233 echo ' ' >> $LOGFILE
0234 $SCRIPT $scrArg -command "$rCommand" >> $LOGFILE 2>&1
0235 out=$?
0236 fi
0237 case $out in
0238 0 ) echo ' pass test 2+2=4'
0239 echo "Y Y Y Y pass <- $nam" >> $HERE/$SUMMARY ;;
0240 4|5) echo "Y Y Y Y FAIL ($out) - $nam" >> $HERE/$SUMMARY ;;
0241 3 ) echo "Y Y Y N FAIL ($out) - $nam" >> $HERE/$SUMMARY ;;
0242 2 ) echo "Y Y N N FAIL ($out) - $nam" >> $HERE/$SUMMARY ;;
0243 1 ) echo "Y N N N FAIL ($out) - $nam" >> $HERE/$SUMMARY ;;
0244 * ) echo "N N N N FAIL ($out) - $nam" >> $HERE/$SUMMARY ;;
0245 esac
0246 if test $out != '0' ; then
0247 echo " test 2+2=4 FAIL (exit $out)"
0248 echo " "
0249 tail -5 $LOGFILE
0250 echo " "
0251 cp -p $LOGFILE $HERE/$DRESULTS/$nam.log
0252 elif test $SAVELOG = 1 ; then
0253 cp -p $LOGFILE $HERE/$DRESULTS/$nam.log
0254 fi
0255 )
afbc98f124 Jean*0256 fi
0257 done
e6cdfd97b6 Jean*0258 if test "x$mpi" != x0 -a "x$MPI_MFILE" != x ; then rm -f $LOC_MFILE ; fi
afbc98f124 Jean*0259 done
0260 printf "End time: " >> $SUMMARY
0261 date >> $SUMMARY
0262
de5f6fb872 Jean*0263 # If address was supplied, then send email using Send-Command or mpack.
afbc98f124 Jean*0264 if test "x$ADDRESS" != xNONE -a "x$ADDRESS" != x ; then
de5f6fb872 Jean*0265 if test "x$SENDCMD" = x ; then
0266 # if Send-Command is empty and mpack exist, then send email using mpack.
0267 if test -x $MPACK ; then SENDCMD=$MPACK
0268 else
0269 echo
2004bde0df Jean*0270 echo "Warning: $MPACK is not executable => no email was sent"
de5f6fb872 Jean*0271 fi
0272 fi
0273 if test "x$SENDCMD" != x ; then
7b0da9764a Jean*0274 SendOpt='' ; headCMD=`echo $SENDCMD | awk '{print $1}'`
0275 if test $headCMD != 'scp' ; then SendOpt='-s MITgcm-test -m 3555000' ; fi
0276 #echo " run: $SENDCMD $SendOpt ${SAVDIR}/${DRESULTS}".tar.gz" $ADDRESSES"
de5f6fb872 Jean*0277 tar -cf ${SAVDIR}/${DRESULTS}".tar" $DRESULTS > /dev/null 2>&1 \
0278 && gzip ${SAVDIR}/${DRESULTS}".tar" \
7b0da9764a Jean*0279 && $SENDCMD $SendOpt ${SAVDIR}/${DRESULTS}".tar.gz" $ADDRESS
afbc98f124 Jean*0280 out=$?
0281 if test "x$out" != x0 ; then
0282 echo
0283 echo "Warning: The tar, gzip, & mpack step failed. Please send email"
0284 echo " to <MITgcm-support@mitgcm.org> for help. You may copy the "
0285 echo " summary of results from the directory \"$DRESULTS\"."
0286 else
0287 echo
0288 echo "An email containing results was sent to the following address:"
0289 echo " \"$ADDRESS\""
a47eaf280c Jean*0290 test -f ${SAVDIR}/${DRESULTS}".tar" && rm -f ${SAVDIR}/${DRESULTS}".tar"
0291 test -f ${SAVDIR}/${DRESULTS}".tar.gz" && rm -f ${SAVDIR}/${DRESULTS}".tar.gz"
afbc98f124 Jean*0292 fi
0293 fi
0294 fi
2004bde0df Jean*0295 echo '' ; echo '===== Summary (tst_2+2_out.txt): ======'
0296 cat $SUMMARY
afbc98f124 Jean*0297
0298 # save output and remove output Dir (if no address was provided)
0299 # note: to keep the output Dir without sending email, use option "-a NONE"
0300 if test -f tst_2+2_out.txt ; then mv -f tst_2+2_out.txt tst_2+2_out.old ; fi
0301 cp -p $SUMMARY tst_2+2_out.txt
0302 if test "x$ADDRESS" = x ; then
0303 rm -rf $DRESULTS
0304 fi