intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / bin / mpirunDebug
blob8d0be2375c4beda9ca56943fef8f2308e8816448
1 #!/bin/sh
3 # Driver script to run mpi jobs with the processes in separate
4 # windows or to separate log files.
5 # Requires bash on all processors.
8 PROGNAME=`basename $0`
9 PROGDIR=`dirname $0`
11 if [ `uname -s` = 'Linux' ]; then
12 ECHO='echo -e'
13 else
14 ECHO='echo'
18 printUsage() {
19 echo ""
20 echo "Usage: $PROGNAME -np <dd> <executable> <args>"
21 echo ""
22 echo "This will run like mpirun but with each process in an xterm"
25 nProcs=''
26 exec=''
27 args=''
29 while [ "$1" != "" ]; do
30 echo "$1"
31 case $1 in
32 -np)
33 nProcs=$2;shift
36 if [ ! "$exec" ]; then
37 exec=$1
38 elif [ ! "$args" ]; then
39 args="\"$1\""
40 else
41 args="$args \"$1\""
45 esac
46 shift
47 done
49 echo "nProcs=$nProcs"
50 echo "exec=$exec"
51 echo "args=$args"
53 if [ ! "$nProcs" ]; then
54 printUsage
55 exit 1
57 if [ ! "$args" ]; then
58 printUsage
59 exit 1
61 if [ ! "$exec" ]; then
62 printUsage
63 exit 1
66 exec=`which $exec`
67 if [ ! -x "$exec" ]; then
68 echo "Cannot find executable $exec or is not executable"
69 printUsage
70 exit 1
73 if [ ! "$PWD" ]; then
74 PWD=`pwd`
77 echo "run $args" > $PWD/gdbCommands
78 echo "where" >> $PWD/gdbCommands
79 echo "Constructed gdb initialization file $PWD/gdbCommands"
81 $ECHO "Choose running method: 0)normal 1)gdb+xterm 2)gdb 3)log 4)log+xterm 5)xterm+valgrind: \c"
82 read method
83 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
84 printUsage
85 exit 1
88 $ECHO "Run all processes local or distributed? 1)local 2)remote: \c"
89 read spawn
90 if [ "$spawn" -ne 1 -a "$spawn" -ne 2 ]; then
91 printUsage
92 exit 1
95 # check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
96 # check ~/.$WM_PROJECT/
97 # check <installedProject>/etc/
98 if [ "$WM_PROJECT" ]; then
100 for i in \
101 $HOME/.WM_PROJECT/$WM_PROJECT_VERSION \
102 $HOME/.WM_PROJECT \
103 $WM_PROJECT_DIR/etc \
106 if [ -f "$i/bashrc" ]; then
107 sourceFoam="$i/bashrc"
108 break
110 done
113 # Construct test string for remote execution.
114 # Source OpenFOAM settings if OpenFOAM environment not set.
115 # attempt to preserve the installation directory 'FOAM_INST_DIR'
116 if [ "$FOAM_INST_DIR" ]; then
117 sourceFoam='[ "$WM_PROJECT" ] || '"FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam"
118 else
119 sourceFoam='[ "$WM_PROJECT" ] || '". $sourceFoam"
122 echo "**sourceFoam:$sourceFoam"
124 rm -f $PWD/mpirun.schema
125 touch $PWD/mpirun.schema
127 proc=0
128 xpos=0
129 ypos=0
130 for ((proc=0; proc<$nProcs; proc++))
132 procCmdFile="$PWD/processor${proc}.sh"
133 procLog="processor${proc}.log"
134 geom="-geometry 120x20+$xpos+$ypos"
135 node=""
137 if [ .$WM_MPLIB = .OPENMPI ]; then
138 node="-np 1 "
139 elif [ .$WM_MPLIB = .LAM ]; then
140 if [ "$spawn" -eq 2 ]; then
141 node="c${proc} "
145 echo "#!/bin/sh" > $procCmdFile
146 if [ "$method" -eq 0 ]; then
147 echo "$sourceFoam; cd $PWD; $exec $args | tee $procLog" >> $procCmdFile
148 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
149 elif [ "$method" -eq 1 ]; then
150 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec 2>&1 | tee $procLog; read dummy" >> $procCmdFile
151 #echo "$sourceFoam; cd $PWD; $exec $args; read dummy" >> $procCmdFile
152 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
153 elif [ "$method" -eq 2 ]; then
154 echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands >& $procLog" >> $procCmdFile
155 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
156 elif [ "$method" -eq 3 ]; then
157 echo "$sourceFoam; cd $PWD; $exec $args >& $procLog" >> $procCmdFile
158 echo "${node}$procCmdFile" >> $PWD/mpirun.schema
159 elif [ "$method" -eq 4 ]; then
160 echo "$sourceFoam; cd $PWD; $exec $args 2>&1 | tee $procLog; read dummy" >> $procCmdFile
161 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
162 elif [ "$method" -eq 5 ]; then
163 echo "$sourceFoam; cd $PWD; valgrind $exec $args; read dummy" >> $procCmdFile
164 echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
167 chmod +x $procCmdFile
169 let column=proc%6
170 if [ $proc -ne 0 -a $column -eq 0 ]; then
171 ((xpos+=600))
172 ((ypos=0))
173 else
174 ((ypos+=200))
176 done
178 for ((proc=0; proc<$nProcs; proc++))
180 procLog="processor${proc}.log"
181 echo " tail -f $procLog"
182 done
184 cmd=""
185 if [ .$WM_MPLIB = .OPENMPI ]; then
186 cmd="mpirun -app $PWD/mpirun.schema </dev/null"
187 elif [ .$WM_MPLIB = .LAM ]; then
188 cmd="mpirun $PWD/mpirun.schema </dev/null"
191 echo "Constructed $PWD/mpirun.schema file."
192 echo ""
193 echo " $cmd"
194 echo ""
195 $ECHO "Press return to execute.\c"
196 read dummy
197 exec $cmd