twoPhaseEulerFoam:frictionalStressModel/Schaeffer: Correct mut on processor boundaries
[OpenFOAM-1.7.x.git] / bin / foamPrintJobs
blobd6ade3fa48a25f60d61960302969bee8346a0fe4
1 #!/bin/sh
2 #---------------------------------*- sh -*-------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamPrintJobs
28 # Description
29 # Uses finishedJobs/ and runningJobs/ and stateFile to print job info
31 #------------------------------------------------------------------------------
33 PROGNAME=`basename $0`
34 TMPFILE=/tmp/${PROGNAME}$$.tmp
35 TMPFILE2=/tmp/${PROGNAME}$$.tmp2
36 JOBSTRING='%4s %8s %20s %10s %8s %4s %12s %12s %20s\n'
37 DEFSTATEFILE=$HOME/.OpenFOAM/foamCheckJobs.out
40 #-------------------------------------------------------------------------------
42 # Functions
44 #-------------------------------------------------------------------------------
46 printUsage() {
47 cat << LABEL
48 Usage: $PROGNAME [stateFile]
50 This program prints a table of all the running and finished jobs.
52 It is normally used in conjunction with foamCheckJobs which outputs
53 a "stateFile" containing the actual process status of all jobs.
55 If stateFile is not supplied the default $DEFSTATEFILE
56 is used.
57 LABEL
61 # printJob stat user case machine pid ncpus start end code
62 printJob() {
63 printf "$JOBSTRING" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
67 # getRawEntry dictionary entry
68 # Prints value of dictionary entry
69 getRawEntry() {
70 grep -v '^//' $1 | grep "^[ \t]*$2 " | sed -e "s/^[ \t]*$2 [ ]*//"
73 # getEntry dictionary entry
74 # Like getRawEntry but strips " and ending ';'
75 getEntry() {
76 getRawEntry $1 $2 | sed -e 's/^"//' -e 's/;$//' -e 's/"$//'
80 # notEmpty directory
81 # Returns 0 if directory contains files/directories
82 notEmpty() {
83 if [ "`ls $1`" ]; then
84 return 0
85 else
86 return 1
90 # rightStr nChars string
91 # Prints rightmost nChars of string
92 rightStr() {
93 echo "$2" | sed -e "s/.*\(.\{$1\}\)\$/\1/"
96 leftStr() {
97 echo "$2" | sed -e "s/\(.\{$1\}\).*/\1/"
100 #-------------------------------------------------------------------------------
102 # Main
104 #-------------------------------------------------------------------------------
106 if [ ! "$FOAM_JOB_DIR" ]; then
107 echo "$PROGNAME : FOAM_JOB_DIR environment variable not set."
108 exit 1
111 if [ ! -d "$FOAM_JOB_DIR" ]; then
112 echo "$PROGNAME : directory does not exist."
113 echo " FOAM_JOB_DIR: $FOAM_JOB_DIR"
115 if [ ! -d "$FOAM_JOB_DIR/runningJobs" -o ! -d "$FOAM_JOB_DIR/finishedJobs" ]; then
116 echo "$PROGNAME : invalid directory."
117 echo " FOAM_JOB_DIR: $FOAM_JOB_DIR"
121 if [ $# -eq 1 ]; then
122 if [ "$1" = '-h' ]; then
123 printUsage
124 exit 1
125 else
126 STATEFILE=$1
128 elif [ $# -eq 0 ]; then
129 STATEFILE=${STATEFILE:-$DEFSTATEFILE}
130 else
131 printUsage
132 exit 1
136 if [ -f "$STATEFILE" ]; then
137 echo ""
138 echo "Using process information from"
139 echo " $STATEFILE"
140 echo "on jobs in"
141 echo " $FOAM_JOB_DIR"
142 echo ""
143 else
144 echo ""
145 echo "Cannot read $STATEFILE."
146 echo ""
147 STATEFILE=''
151 #-- print header
152 printJob 'stat' 'user' 'case' 'machine' 'pid' 'ncpu' 'start' 'end' 'code'
153 printJob '----' '----' '----' '-------' '---' '----' '-----' '---' '----'
157 #-- print submitted
160 #-- print running
161 echo "Running:"
162 if notEmpty $FOAM_JOB_DIR/runningJobs; then
163 for f in `ls -t $FOAM_JOB_DIR/runningJobs/*`
165 machinePid=`basename $f`
167 machine=`echo $machinePid | sed -e 's/\..*$//'`
168 machine=`rightStr 10 "$machine"`
170 pid=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
172 if [ "$STATEFILE" ]; then
173 stat=`getEntry $STATEFILE $machinePid`
175 stat=${stat:-'UNKN'}
177 case=`getEntry $f 'case'`
178 case=${case:-'---'}
179 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
180 case=`rightStr 20 "$case"`
182 start=`getEntry $f 'startDate'`
183 start=${start:-'---'}
184 start=`leftStr 12 "$start"`
186 end='---'
188 code=`getEntry $f 'code'`
189 if [ "$code" ]; then
190 code=`basename $code`
191 else
192 code='---'
194 code=`rightStr 20 "$code"`
196 nProcs=`getEntry $f 'nProcs'`
197 nProcs=${nProcs:-'1'}
198 if [ $nProcs -eq 1 ]; then
199 nProcs='---'
201 nProcs=`rightStr 3 "$nProcs"`
203 user=`getEntry $f 'username'`
204 user=${user:-'---'}
205 user=`leftStr 8 "$user"`
207 printJob "$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
208 done
212 #-- print finished
213 echo ""
214 echo "Finished:"
215 if notEmpty $FOAM_JOB_DIR/finishedJobs; then
216 for f in `ls -t $FOAM_JOB_DIR/finishedJobs/*`
218 machinePid=`basename $f`
220 machine=`echo $machinePid | sed -e 's/\..*$//'`
221 machine=`rightStr 10 "$machine"`
223 pid=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
225 end=`getEntry $f endDate`
226 end=${end:-'---'}
227 end=`leftStr 12 "$end"`
229 if [ "$STATEFILE" ]; then
230 stat=`getEntry $STATEFILE $machinePid`
232 stat=${stat:-'UNKN'}
234 case=`getEntry $f case`
235 case=`echo $case | sed -e 's!/.*!!'` #strip of processorXXX ending
236 case=${case:-'---'}
237 case=`rightStr 20 "$case"`
239 start=`getEntry $f startDate`
240 start=${start:-'---'}
241 start=`leftStr 12 "$start"`
243 code=`getEntry $f code`
244 if [ "$code" ]; then
245 code=`basename $code`
246 else
247 code='---'
249 code=`rightStr 20 "$code"`
251 nProcs=`getEntry $f 'nProcs'`
252 nProcs=${nProcs:-'1'}
253 if [ $nProcs -eq 1 ]; then
254 nProcs='---'
256 nProcs=`rightStr 3 "$nProcs"`
258 user=`getEntry $f 'username'`
259 user=${user:-'---'}
260 user=`leftStr 8 "$user"`
262 printJob "$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
263 done
266 #------------------------------------------------------------------------------