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/>.
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 6)nemiver: \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 -a "$method" -ne 6 ]; 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
186 elif [ "$method" -eq 6 ]; then
187 ## maybe one could use nemiver sessions for reloading breakpoints --session=<N> or --last
188 # echo "$sourceFoam; cd $PWD; nemiver --last $exec $args; read dummy" >> $procCmdFile
189 echo "$sourceFoam; cd $PWD; nemiver $exec $args; read dummy" >> $procCmdFile
190 # echo "$sourceFoam; cd $PWD; ddd --args $exec $args; read dummy" >> $procCmdFile
191 echo "${node} $procCmdFile" >> $PWD/mpirun.schema
194 chmod +x
$procCmdFile
197 if [ $proc -ne 0 -a $column -eq 0 ]; then
205 for ((proc
=0; proc
<$nProcs; proc
++))
207 procLog
="processor${proc}.log"
208 echo " tail -f $procLog"
212 if [ .
$WM_MPLIB = .OPENMPI
]; then
213 cmd
="mpirun -app $PWD/mpirun.schema </dev/null"
214 elif [ .
$WM_MPLIB = .MPICH
]; then
216 for ((proc
=0; proc
<$nProcs; proc
++))
220 procXtermCmdFile
="$PWD/processor${proc}Xterm.sh"
221 echo "#!/bin/sh" > $procXtermCmdFile
222 echo "$procCmd" >> $procXtermCmdFile
223 chmod +x
$procXtermCmdFile
224 if [ $proc -ne 0 ]; then
227 cmd
="${cmd} -n 1 ${procXtermCmdFile}"
228 done < $PWD/mpirun.schema
231 echo "Constructed $PWD/mpirun.schema file."
235 $ECHO "Press return to execute.\c"
239 #------------------------------------------------------------------------------