Merge commit 'b5be6201e00421a59e574a07b3d28cde5defff84'
[foam-extend-4.0.git] / bin / mpirunDebug
blob700a5c50e5de597fbc02eeeac2577bd72673759d
1 #!/bin/bash
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration | Version: 4.0
6 # \\ / A nd | Web: http://www.foam-extend.org
7 # \\/ M anipulation | For copyright notice see file Copyright
8 #------------------------------------------------------------------------------
9 # License
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/>.
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 6)nemiver: \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 -a "$method" -ne 6 ]; 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 --tool=memcheck --leak-check=full $exec $args | tee $procLog; 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
196 let column=proc%6
197 if [ $proc -ne 0 -a $column -eq 0 ]; then
198 ((xpos+=600))
199 ((ypos=0))
200 else
201 ((ypos+=200))
203 done
205 for ((proc=0; proc<$nProcs; proc++))
207 procLog="processor${proc}.log"
208 echo " tail -f $procLog"
209 done
211 cmd=""
212 if [ .$WM_MPLIB = .OPENMPI ]; then
213 cmd="mpirun -app $PWD/mpirun.schema </dev/null"
214 elif [ .$WM_MPLIB = .MPICH ]; then
215 cmd="mpiexec"
216 for ((proc=0; proc<$nProcs; proc++))
218 read procCmd
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
225 cmd="${cmd} :"
227 cmd="${cmd} -n 1 ${procXtermCmdFile}"
228 done < $PWD/mpirun.schema
231 echo "Constructed $PWD/mpirun.schema file."
232 echo ""
233 echo " $cmd"
234 echo ""
235 $ECHO "Press return to execute.\c"
236 read dummy
237 exec $cmd
239 #------------------------------------------------------------------------------