twoPhaseEulerFoam:frictionalStressModel/Schaeffer: Correct mut on processor boundaries
[OpenFOAM-1.7.x.git] / bin / mpirunDebug
blobb719b10b74c011bacbe3da5851704fee91d43aa8
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"
161 case "$WM_MPLIB" in
162 *OPENMPI)
163 node="-np 1 "
166 node=""
167 esac
169 echo "#!/bin/sh" > $procCmdFile
170 if [ "$method" -eq 0 ]; then
171 echo "$sourceFoam; cd $PWD; $exec $args | tee $procLog" >> $procCmdFile
172 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
173 elif [ "$method" -eq 1 ]; then
174 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec 2>&1 | tee $procLog; read dummy" >> $procCmdFile
175 #echo "$sourceFoam; cd $PWD; $exec $args; read dummy" >> $procCmdFile
176 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
177 elif [ "$method" -eq 2 ]; then
178 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec > $procLog 2>&1" >> $procCmdFile
179 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
180 elif [ "$method" -eq 3 ]; then
181 echo "$sourceFoam; cd $PWD; $exec $args > $procLog 2>&1" >> $procCmdFile
182 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
183 elif [ "$method" -eq 4 ]; then
184 echo "$sourceFoam; cd $PWD; $exec $args 2>&1 | tee $procLog; read dummy" >> $procCmdFile
185 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
186 elif [ "$method" -eq 5 ]; then
187 echo "$sourceFoam; cd $PWD; valgrind $exec $args; read dummy" >> $procCmdFile
188 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
191 chmod +x $procCmdFile
193 let column=proc%6
194 if [ $proc -ne 0 -a $column -eq 0 ]; then
195 ((xpos+=600))
196 ((ypos=0))
197 else
198 ((ypos+=200))
200 done
202 for ((proc=0; proc<$nProcs; proc++))
204 procLog="processor${proc}.log"
205 echo " tail -f $procLog"
206 done
208 cmd=""
209 case "$WM_MPLIB" in
210 *OPENMPI)
211 cmd="mpirun -app $PWD/mpirun.schema </dev/null"
213 MPICH)
214 cmd="mpiexec"
215 for ((proc=0; proc<$nProcs; proc++))
217 read procCmd
219 procXtermCmdFile="$PWD/processor${proc}Xterm.sh"
220 echo "#!/bin/sh" > $procXtermCmdFile
221 echo "$procCmd" >> $procXtermCmdFile
222 chmod +x $procXtermCmdFile
223 if [ $proc -ne 0 ]; then
224 cmd="${cmd} :"
226 cmd="${cmd} -n 1 ${procXtermCmdFile}"
227 done < $PWD/mpirun.schema
230 echo
231 echo "Unsupported WM_MPLIB setting : $WM_MPLIB"
232 printUsage
233 exit 1
234 esac
236 echo "Constructed $PWD/mpirun.schema file."
237 echo ""
238 echo " $cmd"
239 echo ""
240 $ECHO "Press return to execute.\c"
241 read dummy
242 exec $cmd
244 #------------------------------------------------------------------------------