STYLE: updated license version in header
[OpenFOAM-1.7.x.git] / bin / mpirunDebug
blob402560b29fd7c4f7a186b0eb0b60f5b88f0620ef
1 #!/bin/bash
2 #---------------------------------*- sh -*-------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
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
20 # for more details.
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/>.
25 # Script
26 # mpirunDebug
28 # Description
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 ]
35 then
36 ECHO='echo -e'
37 else
38 ECHO='echo'
42 printUsage() {
43 echo ""
44 echo "Usage: ${0##*/} -np <dd> <executable> <args>"
45 echo ""
46 echo "This will run like mpirun but with each process in an xterm"
49 nProcs=''
50 exec=''
51 args=''
53 while [ "$1" != "" ]; do
54 echo "$1"
55 case $1 in
56 -np)
57 nProcs=$2
58 shift
61 if [ ! "$exec" ]; then
62 exec=$1
63 elif [ ! "$args" ]; then
64 args="\"$1\""
65 else
66 args="$args \"$1\""
70 esac
71 shift
72 done
74 echo "nProcs=$nProcs"
75 echo "exec=$exec"
76 echo "args=$args"
78 if [ ! "$nProcs" ]; then
79 printUsage
80 exit 1
82 if [ ! "$args" ]; then
83 printUsage
84 exit 1
86 if [ ! "$exec" ]; then
87 printUsage
88 exit 1
91 exec=`which $exec`
92 if [ ! -x "$exec" ]; then
93 echo "Cannot find executable $exec or is not executable"
94 printUsage
95 exit 1
98 if [ ! "$PWD" ]; then
99 PWD=`pwd`
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"
107 read method
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
109 printUsage
110 exit 1
113 $ECHO "Run all processes local or distributed? 1)local 2)remote: \c"
114 read spawn
115 if [ "$spawn" -ne 1 -a "$spawn" -ne 2 ]; then
116 printUsage
117 exit 1
120 # check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
121 # check ~/.$WM_PROJECT/
122 # check <installedProject>/etc/
123 if [ "$WM_PROJECT" ]; then
125 for i in \
126 $HOME/.WM_PROJECT/$WM_PROJECT_VERSION \
127 $HOME/.WM_PROJECT \
128 $WM_PROJECT_DIR/etc \
131 if [ -f "$i/bashrc" ]; then
132 sourceFoam="$i/bashrc"
133 break
135 done
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"
143 else
144 sourceFoam='[ "$WM_PROJECT" ] || '". $sourceFoam"
147 echo "**sourceFoam:$sourceFoam"
149 rm -f $PWD/mpirun.schema
150 touch $PWD/mpirun.schema
152 proc=0
153 xpos=0
154 ypos=0
155 for ((proc=0; proc<$nProcs; proc++))
157 procCmdFile="$PWD/processor${proc}.sh"
158 procLog="processor${proc}.log"
159 geom="-geometry 120x20+$xpos+$ypos"
160 node=""
162 if [ .$WM_MPLIB = .OPENMPI ]; then
163 node="-np 1 "
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
190 let column=proc%6
191 if [ $proc -ne 0 -a $column -eq 0 ]; then
192 ((xpos+=600))
193 ((ypos=0))
194 else
195 ((ypos+=200))
197 done
199 for ((proc=0; proc<$nProcs; proc++))
201 procLog="processor${proc}.log"
202 echo " tail -f $procLog"
203 done
205 cmd=""
206 if [ .$WM_MPLIB = .OPENMPI ]; then
207 cmd="mpirun -app $PWD/mpirun.schema </dev/null"
208 elif [ .$WM_MPLIB = .MPICH ]; then
209 cmd="mpiexec"
210 for ((proc=0; proc<$nProcs; proc++))
212 read procCmd
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
219 cmd="${cmd} :"
221 cmd="${cmd} -n 1 ${procXtermCmdFile}"
222 done < $PWD/mpirun.schema
225 echo "Constructed $PWD/mpirun.schema file."
226 echo ""
227 echo " $cmd"
228 echo ""
229 $ECHO "Press return to execute.\c"
230 read dummy
231 exec $cmd
233 #------------------------------------------------------------------------------