2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
8 #-------------------------------------------------------------------------------
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
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/>.
29 # Run an OpenFOAM job in background.
30 # Redirects the output to 'log' in the case directory.
32 #------------------------------------------------------------------------------
35 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
38 Usage: ${0##*/} [OPTION] <application> ...
40 -case <dir> specify alternative case directory, default is the cwd
41 -parallel parallel run of processors
42 -screen also sends output to screen
43 -version <ver> specify an alternative OpenFOAM version
46 * run an OpenFOAM job in background.
47 Redirects the output to 'log' in the case directory
55 # replacement for possibly buggy 'which'
71 # echo "testing: $d/$1" 1>&2
72 if [ -x "$d/$1" -a ! -d "$d/$1" ]
74 # echo "Found exec: $d/$1" 1>&2
89 unset parallelOpt screenOpt
100 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
101 cd "$2" 2>/dev
/null || usage
"directory does not exist: '$2'"
113 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
122 usage
"invalid option '$1'"
130 [ "$#" -ge 1 ] || usage
"No application specified"
133 # use foamExec for a specified version
134 # also need foamExec for remote (parallel) runs
135 if [ -n "$version" -o "$parallelOpt" = true
]
137 # when possible, determine if application even exists
140 findExec
$1 >/dev
/null || usage
"Application '$1' not found"
143 # use foamExec for dispatching
144 APPLICATION
=`findExec foamExec` || usage
"'foamExec' not found"
146 [ -n "$version" ] && APPLICATION
="$APPLICATION -version $version"
148 # attempt to preserve the installation directory 'FOAM_INST_DIR'
149 if [ -d "$FOAM_INST_DIR" ]
151 APPLICATION
="$APPLICATION -prefix $FOAM_INST_DIR"
155 APPLICATION
=`findExec $1` || usage
"Application '$1' not found"
156 echo "Application : $1"
161 if [ "$parallelOpt" = true
]
167 # is the case decomposed?
169 if [ -r "processor0" ]
171 NPROCS
="`/bin/ls -1d processor* | wc -l`"
173 echo "Case is not currently decomposed"
174 if [ -r system
/decomposeParDict
]
176 echo "system/decomposeParDict exists"
177 echo "Try decomposing with \"foamJob decomposePar\""
180 echo "Cannot find system/decomposeParDict file required to decompose the case for parallel running."
181 echo "Please consult the User Guide for details of parallel running"
189 mpirun
=`findExec mpirun` || usage
"'mpirun' not found"
190 mpiopts
="-np $NPROCS"
193 # is the machine ready to run parallel?
195 echo "Parallel processing using $WM_MPLIB with $NPROCS processors"
208 mpiopts
="$mpiopts -hostfile $hostfile"
218 if [ "$screenOpt" = true
]
220 echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel | tee log"
221 $mpirun $mpiopts $APPLICATION $@
-parallel |
tee log
223 echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1"
224 $mpirun $mpiopts $APPLICATION $@
-parallel > log
2>&1 &
229 # run (on single processor)
231 if [ "$screenOpt" = true
]
233 echo "Executing: $APPLICATION $@ | tee log &"
234 $APPLICATION $@ |
tee log
&
237 echo "Executing: $APPLICATION $@ > log 2>&1 &"
238 $APPLICATION $@
> log
2>&1 &
242 #------------------------------------------------------------------------------