2 #------------------------------------------------------------------------------
4 # \\ / F ield | foam-extend: Open Source CFD
6 # \\ / A nd | For copyright notice see file Copyright
8 #------------------------------------------------------------------------------
10 # This file is part of foam-extend.
12 # foam-extend 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 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
30 #------------------------------------------------------------------------------
32 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
35 usage: ${0##*/} [OPTION] <application> ...
38 -case dir specify case directory
39 -s also sends output to screen
40 -p parallel run of processors
41 -v ver specify OpenFOAM version
44 * run an OpenFOAM job in background.
45 Redirects the output to 'log' in the case directory
53 # replacement for possibly buggy 'which'
68 # echo "testing: $d/$1" 1>&2
69 if [ -x "$d/$1" -a ! -d "$d/$1" ] ; then
70 # echo "Found exec: $d/$1" 1>&2
83 ps
-u $LOGNAME -o 'pid,args' | fgrep
"$1 " | fgrep
-v grep |
head -1 |
awk '{ print $1 }'
90 Please consult the User Guide for details of parallel running
108 [ "$#" -ge 2 ] || usage
"'-case' option requires an argument"
111 cd "$caseDir" 2>/dev
/null || usage
"directory does not exist: '$caseDir'"
131 usage
"invalid option '$1'"
139 if [ "$#" -lt 1 ]; then
140 usage
"No application specified"
143 # use foamExec for a specified version and for remote (parallel) runs
144 if [ -n "$version" -o "$PARALLEL" = yes ]; then
145 APPLICATION
=`findExec foamExec`
146 if [ $?
-ne 0 ]; then
147 usage
"'foamExec' not found"
149 if [ -n "$version" ]; then
150 APPLICATION
="$APPLICATION -v $version"
153 APPLICATION
=`findExec $1`
154 if [ $?
-ne 0 ]; then
155 usage
"Application '$1' executable not found"
157 echo "Application : $1"
161 if [ "$PARALLEL" = no
]; then
163 # RUN ON SINGLE PROCESSOR
165 if [ "$SCREEN" = no
]; then
166 echo "Executing: $APPLICATION $@ > log 2>&1 &"
167 $APPLICATION $@
> log
2>&1 &
169 echo "Executing: $APPLICATION $@ | tee log &"
170 $APPLICATION $@ |
tee log
&
176 # IS THE CASE DECOMPOSED?
178 if [ -r "processor0" ] ; then
179 NPROCS
="`/bin/ls -1d processor* | wc -l`"
181 echo "Case is not currently decomposed"
182 if [ -r system
/decomposeParDict
] ; then
183 echo "system/decomposeParDict exists"
184 echo "Try decomposing with \"foamJob decomposePar\""
187 echo "Cannot find system/decomposeParDict file required to decompose the case for parallel running."
195 mpirun
=`findExec mpirun`
196 if [ $?
-ne 0 ]; then
197 usage
"'mpirun' not found"
199 mpiopts
="-np $NPROCS"
202 # IS THE MACHINE READY TO RUN PARALLEL?
204 echo "Parallel processing using $WM_MPLIB with $NPROCS processors"
215 if [ -r $hostfile ]; then
216 mpiopts
="$mpiopts -hostfile $hostfile"
226 if [ "$SCREEN" = no
] ; then
227 echo "Executing: mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1"
228 $mpirun $mpiopts $APPLICATION $@
-parallel > log
2>&1 &
230 echo "Executing: mpirun $mpiopts $APPLICATION $@ -parallel | tee log"
231 $mpirun $mpiopts $APPLICATION $@
-parallel |
tee log
235 #------------------------------------------------------------------------------