2 #---------------------------------*- sh -*-------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 # Driver script to run mpi jobs with the processes in separate
30 # windows or to separate log files.
31 # Requires bash on all processors.
32 #------------------------------------------------------------------------------
34 if [ `uname -s` = Linux
]
44 echo "Usage: ${0##*/} -np <dd> <executable> <args>"
46 echo "This will run like mpirun but with each process in an xterm"
53 while [ "$1" != "" ]; do
61 if [ ! "$exec" ]; then
63 elif [ ! "$args" ]; then
78 if [ ! "$nProcs" ]; then
82 if [ ! "$args" ]; then
86 if [ ! "$exec" ]; then
92 if [ ! -x "$exec" ]; then
93 echo "Cannot find executable $exec or is not executable"
102 echo "run $args" > $PWD/gdbCommands
103 echo "where" >> $PWD/gdbCommands
104 echo "Constructed gdb initialization file $PWD/gdbCommands"
106 $ECHO "Choose running method: 0)normal 1)gdb+xterm 2)gdb 3)log 4)log+xterm 5)xterm+valgrind: \c"
108 if [ "$method" -ne 0 -a "$method" -ne 1 -a "$method" -ne 2 -a "$method" -ne 3 -a "$method" -ne 4 -a "$method" -ne 5 ]; then
113 $ECHO "Run all processes local or distributed? 1)local 2)remote: \c"
115 if [ "$spawn" -ne 1 -a "$spawn" -ne 2 ]; then
120 # check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
121 # check ~/.$WM_PROJECT/
122 # check <installedProject>/etc/
123 if [ "$WM_PROJECT" ]; then
126 $HOME/.WM_PROJECT
/$WM_PROJECT_VERSION \
128 $WM_PROJECT_DIR/etc \
131 if [ -f "$i/bashrc" ]; then
132 sourceFoam
="$i/bashrc"
138 # Construct test string for remote execution.
139 # Source OpenFOAM settings if OpenFOAM environment not set.
140 # attempt to preserve the installation directory 'FOAM_INST_DIR'
141 if [ "$FOAM_INST_DIR" ]; then
142 sourceFoam
='[ "$WM_PROJECT" ] || '"FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam"
144 sourceFoam
='[ "$WM_PROJECT" ] || '". $sourceFoam"
147 echo "**sourceFoam:$sourceFoam"
149 rm -f $PWD/mpirun.schema
150 touch $PWD/mpirun.schema
155 for ((proc
=0; proc
<$nProcs; proc
++))
157 procCmdFile
="$PWD/processor${proc}.sh"
158 procLog
="processor${proc}.log"
159 geom
="-geometry 120x20+$xpos+$ypos"
162 if [ .
$WM_MPLIB = .OPENMPI
]; then
166 echo "#!/bin/sh" > $procCmdFile
167 if [ "$method" -eq 0 ]; then
168 echo "$sourceFoam; cd $PWD; $exec $args | tee $procLog" >> $procCmdFile
169 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
170 elif [ "$method" -eq 1 ]; then
171 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec 2>&1 | tee $procLog; read dummy" >> $procCmdFile
172 #echo "$sourceFoam; cd $PWD; $exec $args; read dummy" >> $procCmdFile
173 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
174 elif [ "$method" -eq 2 ]; then
175 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands >& $procLog" >> $procCmdFile
176 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
177 elif [ "$method" -eq 3 ]; then
178 echo "$sourceFoam; cd $PWD; $exec $args >& $procLog" >> $procCmdFile
179 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
180 elif [ "$method" -eq 4 ]; then
181 echo "$sourceFoam; cd $PWD; $exec $args 2>&1 | tee $procLog; read dummy" >> $procCmdFile
182 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
183 elif [ "$method" -eq 5 ]; then
184 echo "$sourceFoam; cd $PWD; valgrind $exec $args; read dummy" >> $procCmdFile
185 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
188 chmod +x
$procCmdFile
191 if [ $proc -ne 0 -a $column -eq 0 ]; then
199 for ((proc
=0; proc
<$nProcs; proc
++))
201 procLog
="processor${proc}.log"
202 echo " tail -f $procLog"
206 if [ .
$WM_MPLIB = .OPENMPI
]; then
207 cmd
="mpirun -app $PWD/mpirun.schema </dev/null"
208 elif [ .
$WM_MPLIB = .MPICH
]; then
210 for ((proc
=0; proc
<$nProcs; proc
++))
214 procXtermCmdFile
="$PWD/processor${proc}Xterm.sh"
215 echo "#!/bin/sh" > $procXtermCmdFile
216 echo "$procCmd" >> $procXtermCmdFile
217 chmod +x
$procXtermCmdFile
218 if [ $proc -ne 0 ]; then
221 cmd
="${cmd} -n 1 ${procXtermCmdFile}"
222 done < $PWD/mpirun.schema
225 echo "Constructed $PWD/mpirun.schema file."
229 $ECHO "Press return to execute.\c"
233 #------------------------------------------------------------------------------