No EXECUTABLE_PREFIX for apps, install into libexec instead
[freefoam.git] / bin / freefoam-job.in
blob1ca65e1307c80f1b9010c37ff2b0f0ef87ae4e20
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2009 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 the
14 # Free Software Foundation; either version 2 of the License, or (at your
15 # 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, write to the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 # Script
27 # foamJob
29 # Description
31 #------------------------------------------------------------------------------
33 . @FF_DATA_DIR@/shellFunctions/jobControlFunctions
35 usage() {
36 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
37 cat<<USAGE
39 usage: ${0##*/} [OPTION] <application> ...
41 options:
42 -case dir specify case directory
43 -s also sends output to screen
44 -p parallel run of processors
45 -hosts hostfile specify file with host names
46 -log logfile specify logfile name for output, defaults to 'log'
47 -fg run the job in the foreground (i.e. don't background it)
48 this option is ignored if -s is specified
49 -help this usage
51 * run an FreeFOAM job in background.
52 Redirects the output to 'log' in the case directory
54 USAGE
55 exit 1
58 # grep for $1
59 getPID() {
60 ps -u $LOGNAME -o 'pid,args' | fgrep "$1 " | fgrep -v grep | head -1 | awk '{ print $1 }'
64 consultGuide() {
65 cat<<EOF
67 Please consult the User Guide for details of parallel running
68 EOF
71 # MAIN SCRIPT
72 #~~~~~~~~~~~~
73 SCREEN=no
74 PARALLEL=no
75 HOSTFILE=
76 LOGFILE=log
77 APPNAME=
78 FG=no
81 # parse options
82 while [ "$#" -gt 0 ]
84 case "$1" in
85 -h | -help)
86 usage
88 -case)
89 [ "$#" -ge 2 ] || usage "'-case' option requires an argument"
90 caseDir=$2
91 shift 2
92 cd "$caseDir" 2>/dev/null || usage "directory does not exist: '$caseDir'"
94 -s)
95 SCREEN=yes
96 shift
98 -p)
99 PARALLEL=yes
100 shift
102 -hosts)
103 [ "$#" -ge 2 ] || usage "'-hosts' options requires an argument"
104 HOSTFILE="-hostfile $2"
105 shift 2
107 -log)
108 [ "$#" -ge 2 ] || usage "'-log' options requires an argument"
109 LOGFILE=$2
110 shift 2
112 -fg)
113 FG=yes
114 shift
117 shift
118 break
121 usage "invalid option '$1'"
124 APPNAME=$1
125 shift
126 break
128 esac
129 done
131 if [ -z "$APPNAME" ]; then
132 usage "No application specified"
135 if [ "${APPNAME##*/}" = "$APPNAME" ]; then
136 FOAMEXEC=@FF_BIN_DIR@/freefoam
137 else
138 FOAMEXEC=
141 if [ "$PARALLEL" = no ]; then
143 # RUN ON SINGLE PROCESSOR
145 if [ "$SCREEN" = no ]; then
146 if [ "$FG" = no ]; then
147 echo "Executing: $FOAMEXEC $APPNAME $@ > $LOGFILE 2>&1 &"
148 $FOAMEXEC $APPNAME $@ > $LOGFILE 2>&1 &
149 else
150 echo "Executing: $FOAMEXEC $APPNAME $@ > $LOGFILE 2>&1"
151 $FOAMEXEC $APPNAME $@ > $LOGFILE 2>&1
153 else
154 echo "Executing: $FOAMEXEC $APPNAME $@ | tee $LOGFILE &"
155 $FOAMEXEC $APPNAME $@ | tee $LOGFILE &
156 wait $!
158 else
161 # IS THE CASE DECOMPOSED?
163 if [ -r "processor0" ] ; then
164 NPROCS="`/bin/ls -1d processor* | wc -l`"
165 NPROCS="${NPROCS// /}"
166 else
167 echo "Case is not currently decomposed"
168 if [ -r system/decomposeParDict ] ; then
169 echo "system/decomposeParDict exists"
170 echo "Try decomposing with \"freefoam decomposePar\""
171 exit 1
172 else
173 echo "Cannot find system/decomposeParDict file required to decompose the case for parallel running."
174 consultGuide
175 exit 1
179 # LOCATE MPIRUN
181 controlDict=`findControlDict`
182 mpirun=`getEntry $controlDict parRunTemplate`
183 mpirun=`echo $mpirun | sed -e "s|\\\${NPROCS}|$NPROCS|g" \
184 -e "s|\\\${PAROPTS}|$HOSTFILE|g" \
185 -e "s|\\\${APPLICATION}|$FOAMEXEC $APPNAME|g" \
186 -e "s|\\\${ARGS}|$@|"`
190 # RUN IN PARALLEL
192 if [ "$SCREEN" = no ] ; then
193 if [ "FG" = no ]; then
194 echo "Executing: $mpirun > $LOGFILE 2>&1 &"
195 $mpirun > $LOGFILE 2>&1 &
196 else
197 echo "Executing: $mpirun > $LOGFILE 2>&1"
198 $mpirun > $LOGFILE 2>&1
200 else
201 echo "Executing: $mpirun | tee $LOGFILE"
202 $mpirun | tee $LOGFILE
206 #------------------------------------------------------------------------------