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