2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 1991-2009 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 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
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
30 # Driver script to run mpi jobs with the processes in separate
31 # windows or to separate log files.
32 # Requires bash on all processors.
33 #------------------------------------------------------------------------------
35 if [ `uname -s` = Linux
]
45 echo "Usage: ${0##*/} -np <dd> <executable> <args>"
47 echo "This will run like mpirun but with each process in an xterm"
54 while [ "$1" != "" ]; do
62 if [ ! "$exec" ]; then
64 elif [ ! "$args" ]; then
79 if [ ! "$nProcs" ]; then
83 if [ ! "$args" ]; then
87 if [ ! "$exec" ]; then
93 if [ ! -x "$exec" ]; then
94 echo "Cannot find executable $exec or is not executable"
103 echo "run $args" > $PWD/gdbCommands
104 echo "where" >> $PWD/gdbCommands
105 echo "Constructed gdb initialization file $PWD/gdbCommands"
107 $ECHO "Choose running method: 0)normal 1)gdb+xterm 2)gdb 3)log 4)log+xterm 5)xterm+valgrind: \c"
109 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
114 $ECHO "Run all processes local or distributed? 1)local 2)remote: \c"
116 if [ "$spawn" -ne 1 -a "$spawn" -ne 2 ]; then
121 # check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
122 # check ~/.$WM_PROJECT/
123 # check <installedProject>/etc/
124 if [ "$WM_PROJECT" ]; then
127 $HOME/.WM_PROJECT
/$WM_PROJECT_VERSION \
129 $WM_PROJECT_DIR/etc \
132 if [ -f "$i/bashrc" ]; then
133 sourceFoam
="$i/bashrc"
139 # Construct test string for remote execution.
140 # Source OpenFOAM settings if OpenFOAM environment not set.
141 # attempt to preserve the installation directory 'FOAM_INST_DIR'
142 if [ "$FOAM_INST_DIR" ]; then
143 sourceFoam
='[ "$WM_PROJECT" ] || '"FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam"
145 sourceFoam
='[ "$WM_PROJECT" ] || '". $sourceFoam"
148 echo "**sourceFoam:$sourceFoam"
150 rm -f $PWD/mpirun.schema
151 touch $PWD/mpirun.schema
156 for ((proc
=0; proc
<$nProcs; proc
++))
158 procCmdFile
="$PWD/processor${proc}.sh"
159 procLog
="processor${proc}.log"
160 geom
="-geometry 120x20+$xpos+$ypos"
163 if [ .
$WM_MPLIB = .OPENMPI
]; then
167 echo "#!/bin/sh" > $procCmdFile
168 if [ "$method" -eq 0 ]; then
169 echo "$sourceFoam; cd $PWD; $exec $args | tee $procLog" >> $procCmdFile
170 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
171 elif [ "$method" -eq 1 ]; then
172 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec 2>&1 | tee $procLog; read dummy" >> $procCmdFile
173 #echo "$sourceFoam; cd $PWD; $exec $args; read dummy" >> $procCmdFile
174 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
175 elif [ "$method" -eq 2 ]; then
176 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands >& $procLog" >> $procCmdFile
177 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
178 elif [ "$method" -eq 3 ]; then
179 echo "$sourceFoam; cd $PWD; $exec $args >& $procLog" >> $procCmdFile
180 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
181 elif [ "$method" -eq 4 ]; then
182 echo "$sourceFoam; cd $PWD; $exec $args 2>&1 | tee $procLog; read dummy" >> $procCmdFile
183 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
184 elif [ "$method" -eq 5 ]; then
185 echo "$sourceFoam; cd $PWD; valgrind $exec $args; read dummy" >> $procCmdFile
186 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
189 chmod +x
$procCmdFile
192 if [ $proc -ne 0 -a $column -eq 0 ]; then
200 for ((proc
=0; proc
<$nProcs; proc
++))
202 procLog
="processor${proc}.log"
203 echo " tail -f $procLog"
207 if [ .
$WM_MPLIB = .OPENMPI
]; then
208 cmd
="mpirun -app $PWD/mpirun.schema </dev/null"
211 echo "Constructed $PWD/mpirun.schema file."
215 $ECHO "Press return to execute.\c"
219 #------------------------------------------------------------------------------