ENH: streamLine.C: removed const_cast
[OpenFOAM-2.0.x.git] / bin / mpirunDebug
bloba7a0cb32b0965d88704fdcf8e88186e3a90ea092
1 #!/bin/bash
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 usage()
44 cat<<USAGE
46 Usage: ${0##*/} -np <dd> <executable> <args>
48 * This will run like mpirun but with each process in an XTerm
50 USAGE
51 exit 1
54 unset nProcs exec args
56 while [ "$1" != "" ]
58 echo "$1"
59 case $1 in
60 -np)
61 nProcs=$2
62 shift
65 if [ ! "$exec" ]
66 then
67 exec=$1
68 elif [ ! "$args" ]
69 then
70 args="\"$1\""
71 else
72 args="$args \"$1\""
75 esac
76 shift
77 done
79 echo "nProcs=$nProcs"
80 echo "exec=$exec"
81 echo "args=$args"
83 [ "$nProcs" ] || usage
84 [ "$args" ] || usage
85 [ "$exec" ] || usage
87 exec=`which $exec`
88 if [ ! -x "$exec" ]
89 then
90 echo "Cannot find executable $exec or is not executable"
91 usage
94 if [ ! "$PWD" ]
95 then
96 PWD=`pwd`
99 echo "run $args" > $PWD/gdbCommands
100 echo "where" >> $PWD/gdbCommands
101 echo "Constructed gdb initialization file $PWD/gdbCommands"
103 $ECHO "Choose running method: 0)normal 1)gdb+xterm 2)gdb 3)log 4)log+xterm 5)xterm+valgrind: \c"
104 read method
105 case "$method" in
106 0 | 1 | 2 | 3 | 4 | 5 )
107 # okay
110 usage
112 esac
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 ]
117 then
118 usage
122 # check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
123 # check ~/.$WM_PROJECT/
124 # check <installedProject>/etc/
125 if [ "$WM_PROJECT" ]
126 then
128 for i in \
129 $HOME/.WM_PROJECT/$WM_PROJECT_VERSION \
130 $HOME/.WM_PROJECT \
131 $WM_PROJECT_DIR/etc \
134 if [ -f "$i/bashrc" ]
135 then
136 sourceFoam="$i/bashrc"
137 break
139 done
142 # Construct test string for remote execution.
143 # Source OpenFOAM settings if OpenFOAM environment not set.
144 # attempt to preserve the installation directory 'FOAM_INST_DIR'
145 # use FOAM_SETTINGS to pass command-line settings
146 if [ "$FOAM_INST_DIR" ]
147 then
148 sourceFoam="FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam $FOAM_SETTINGS"
149 else
150 sourceFoam=". $sourceFoam $FOAM_SETTINGS"
153 echo "**sourceFoam:$sourceFoam"
155 rm -f $PWD/mpirun.schema
156 touch $PWD/mpirun.schema
158 proc=0
159 xpos=0
160 ypos=0
161 for ((proc=0; proc<$nProcs; proc++))
163 procCmdFile="$PWD/processor${proc}.sh"
164 procLog="processor${proc}.log"
165 geom="-geometry 120x15+$xpos+$ypos"
167 case "$WM_MPLIB" in
168 *OPENMPI)
169 node="-np 1 "
172 node=""
173 esac
175 echo "#!/bin/bash" > $procCmdFile
176 case "$method" in
178 echo "$sourceFoam; cd $PWD; $exec $args | tee $procLog" >> $procCmdFile
179 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
182 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec 2>&1 | tee $procLog; read dummy" >> $procCmdFile
183 #echo "$sourceFoam; cd $PWD; $exec $args; read dummy" >> $procCmdFile
184 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
187 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec > $procLog 2>&1" >> $procCmdFile
188 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
191 echo "$sourceFoam; cd $PWD; $exec $args > $procLog 2>&1" >> $procCmdFile
192 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
195 echo "$sourceFoam; cd $PWD; $exec $args 2>&1 | tee $procLog; read dummy" >> $procCmdFile
196 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
199 echo "$sourceFoam; cd $PWD; valgrind $exec $args; read dummy" >> $procCmdFile
200 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
202 esac
204 chmod +x $procCmdFile
206 let column=proc%6
207 if [ $proc -ne 0 -a $column -eq 0 ]
208 then
209 ((xpos+=600))
210 ((ypos=0))
211 else
212 ((ypos+=200))
214 done
216 for ((proc=0; proc<$nProcs; proc++))
218 procLog="processor${proc}.log"
219 echo " tail -f $procLog"
220 done
222 unset cmd
224 case "$WM_MPLIB" in
225 *OPENMPI)
226 cmd="mpirun -app $PWD/mpirun.schema </dev/null"
228 MPICH)
229 cmd="mpiexec"
230 for ((proc=0; proc<$nProcs; proc++))
232 read procCmd
234 procXtermCmdFile="$PWD/processor${proc}Xterm.sh"
235 echo "#!/bin/sh" > $procXtermCmdFile
236 echo "$procCmd" >> $procXtermCmdFile
237 chmod +x $procXtermCmdFile
238 if [ $proc -ne 0 ]
239 then
240 cmd="${cmd} :"
242 cmd="${cmd} -n 1 ${procXtermCmdFile}"
243 done < $PWD/mpirun.schema
246 echo
247 echo "Unsupported WM_MPLIB setting : $WM_MPLIB"
248 printUsage
249 exit 1
250 esac
252 echo "Constructed $PWD/mpirun.schema file."
253 echo ""
254 echo " $cmd"
255 echo ""
256 $ECHO "Press return to execute.\c"
257 read dummy
258 exec $cmd
260 #------------------------------------------------------------------------------