initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / bin / mpirunDebug
blob57df760873478f36ba49b44ac000ec76d7be37d0
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2009 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 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
20 # for more details.
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
26 # Script
27 # mpirunDebug
29 # Description
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 ]
36 then
37 ECHO='echo -e'
38 else
39 ECHO='echo'
43 printUsage() {
44 echo ""
45 echo "Usage: ${0##*/} -np <dd> <executable> <args>"
46 echo ""
47 echo "This will run like mpirun but with each process in an xterm"
50 nProcs=''
51 exec=''
52 args=''
54 while [ "$1" != "" ]; do
55 echo "$1"
56 case $1 in
57 -np)
58 nProcs=$2
59 shift
62 if [ ! "$exec" ]; then
63 exec=$1
64 elif [ ! "$args" ]; then
65 args="\"$1\""
66 else
67 args="$args \"$1\""
71 esac
72 shift
73 done
75 echo "nProcs=$nProcs"
76 echo "exec=$exec"
77 echo "args=$args"
79 if [ ! "$nProcs" ]; then
80 printUsage
81 exit 1
83 if [ ! "$args" ]; then
84 printUsage
85 exit 1
87 if [ ! "$exec" ]; then
88 printUsage
89 exit 1
92 exec=`which $exec`
93 if [ ! -x "$exec" ]; then
94 echo "Cannot find executable $exec or is not executable"
95 printUsage
96 exit 1
99 if [ ! "$PWD" ]; then
100 PWD=`pwd`
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"
108 read method
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
110 printUsage
111 exit 1
114 $ECHO "Run all processes local or distributed? 1)local 2)remote: \c"
115 read spawn
116 if [ "$spawn" -ne 1 -a "$spawn" -ne 2 ]; then
117 printUsage
118 exit 1
121 # check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
122 # check ~/.$WM_PROJECT/
123 # check <installedProject>/etc/
124 if [ "$WM_PROJECT" ]; then
126 for i in \
127 $HOME/.WM_PROJECT/$WM_PROJECT_VERSION \
128 $HOME/.WM_PROJECT \
129 $WM_PROJECT_DIR/etc \
132 if [ -f "$i/bashrc" ]; then
133 sourceFoam="$i/bashrc"
134 break
136 done
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"
144 else
145 sourceFoam='[ "$WM_PROJECT" ] || '". $sourceFoam"
148 echo "**sourceFoam:$sourceFoam"
150 rm -f $PWD/mpirun.schema
151 touch $PWD/mpirun.schema
153 proc=0
154 xpos=0
155 ypos=0
156 for ((proc=0; proc<$nProcs; proc++))
158 procCmdFile="$PWD/processor${proc}.sh"
159 procLog="processor${proc}.log"
160 geom="-geometry 120x20+$xpos+$ypos"
161 node=""
163 if [ .$WM_MPLIB = .OPENMPI ]; then
164 node="-np 1 "
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
191 let column=proc%6
192 if [ $proc -ne 0 -a $column -eq 0 ]; then
193 ((xpos+=600))
194 ((ypos=0))
195 else
196 ((ypos+=200))
198 done
200 for ((proc=0; proc<$nProcs; proc++))
202 procLog="processor${proc}.log"
203 echo " tail -f $procLog"
204 done
206 cmd=""
207 if [ .$WM_MPLIB = .OPENMPI ]; then
208 cmd="mpirun -app $PWD/mpirun.schema </dev/null"
211 echo "Constructed $PWD/mpirun.schema file."
212 echo ""
213 echo " $cmd"
214 echo ""
215 $ECHO "Press return to execute.\c"
216 read dummy
217 exec $cmd
219 #------------------------------------------------------------------------------