forked from OpenFOAM/OpenFOAM-2.3.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpirunDebug
executable file
·265 lines (233 loc) · 6.52 KB
/
mpirunDebug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# mpirunDebug
#
# Description
# Driver script to run mpi jobs with the processes in separate
# windows or to separate log files.
# Requires bash on all processors.
#------------------------------------------------------------------------------
if [ `uname -s` = Linux ]
then
ECHO='echo -e'
else
ECHO='echo'
fi
usage()
{
cat<<USAGE
Usage: ${0##*/} -np <dd> <executable> <args>
* This will run like mpirun but with each process in an XTerm
USAGE
exit 1
}
unset nProcs exec args
while [ "$1" != "" ]
do
echo "$1"
case $1 in
-np)
nProcs=$2
shift
;;
*)
if [ ! "$exec" ]
then
exec=$1
elif [ ! "$args" ]
then
args="\"$1\""
else
args="$args \"$1\""
fi
;;
esac
shift
done
echo "nProcs=$nProcs"
echo "exec=$exec"
echo "args=$args"
[ "$nProcs" ] || usage
[ "$args" ] || usage
[ "$exec" ] || usage
exec=`which $exec`
if [ ! -x "$exec" ]
then
echo "Cannot find executable $exec or is not executable"
usage
fi
if [ ! "$PWD" ]
then
PWD=`pwd`
fi
echo "run $args" > $PWD/gdbCommands
echo "where" >> $PWD/gdbCommands
echo "Constructed gdb initialization file $PWD/gdbCommands"
$ECHO "Choose running method: 0)normal 1)gdb+xterm 2)gdb 3)log 4)log+xterm 5)xterm+valgrind 6)gperftools(callgrind): \c"
read method
case "$method" in
0 | 1 | 2 | 3 | 4 | 5 | 6)
# okay
;;
*)
usage
;;
esac
$ECHO "Run all processes local or distributed? 1)local 2)remote: \c"
read spawn
if [ "$spawn" -ne 1 -a "$spawn" -ne 2 ]
then
usage
fi
# check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
# check ~/.$WM_PROJECT/
# check <installedProject>/etc/
if [ "$WM_PROJECT" ]
then
for i in \
$HOME/.$WM_PROJECT/$WM_PROJECT_VERSION \
$HOME/.$WM_PROJECT \
$WM_PROJECT_DIR/etc \
;
do
if [ -f "$i/bashrc" ]
then
sourceFoam="$i/bashrc"
break
fi
done
fi
# Construct test string for remote execution.
# Source OpenFOAM settings if OpenFOAM environment not set.
# attempt to preserve the installation directory 'FOAM_INST_DIR'
# use FOAM_SETTINGS to pass command-line settings
if [ "$FOAM_INST_DIR" ]
then
sourceFoam="FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam $FOAM_SETTINGS"
else
sourceFoam=". $sourceFoam $FOAM_SETTINGS"
fi
echo "**sourceFoam:$sourceFoam"
rm -f $PWD/mpirun.schema
touch $PWD/mpirun.schema
proc=0
xpos=0
ypos=0
for ((proc=0; proc<$nProcs; proc++))
do
procCmdFile="$PWD/processor${proc}.sh"
procLog="processor${proc}.log"
geom="-geometry 120x15+$xpos+$ypos"
case "$WM_MPLIB" in
*OPENMPI)
node="-np 1 "
;;
*)
node=""
esac
echo "#!/bin/bash" > $procCmdFile
case "$method" in
0)
echo "$sourceFoam; cd $PWD; $exec $args | tee $procLog" >> $procCmdFile
echo "${node}$procCmdFile" >> $PWD/mpirun.schema
;;
1)
echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec 2>&1 | tee $procLog; read dummy" >> $procCmdFile
#echo "$sourceFoam; cd $PWD; $exec $args; read dummy" >> $procCmdFile
echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
;;
2)
echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec > $procLog 2>&1" >> $procCmdFile
echo "${node}$procCmdFile" >> $PWD/mpirun.schema
;;
3)
echo "$sourceFoam; cd $PWD; $exec $args > $procLog 2>&1" >> $procCmdFile
echo "${node}$procCmdFile" >> $PWD/mpirun.schema
;;
4)
echo "$sourceFoam; cd $PWD; $exec $args 2>&1 | tee $procLog; read dummy" >> $procCmdFile
echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
;;
5)
echo "$sourceFoam; cd $PWD; valgrind --leak-check=full --show-reachable=yes $exec $args 2>&1 | tee $procLog; read dummy" >> $procCmdFile
echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
;;
6)
echo "$sourceFoam; cd $PWD; CPUPROFILE=log.profiler_$proc $exec $args; \
pprof --callgrind $exec log.profiler_$proc > log.profiler_$proc.callgrind;" >> $procCmdFile
echo "${node}$procCmdFile" >> $PWD/mpirun.schema
;;
esac
chmod +x $procCmdFile
let column=proc%6
if [ $proc -ne 0 -a $column -eq 0 ]
then
((xpos+=600))
((ypos=0))
else
((ypos+=200))
fi
done
for ((proc=0; proc<$nProcs; proc++))
do
procLog="processor${proc}.log"
echo " tail -f $procLog"
done
unset cmd
case "$WM_MPLIB" in
*OPENMPI)
cmd="mpirun -app $PWD/mpirun.schema </dev/null"
;;
MPICH)
cmd="mpiexec"
for ((proc=0; proc<$nProcs; proc++))
do
read procCmd
procXtermCmdFile="$PWD/processor${proc}Xterm.sh"
echo "#!/bin/sh" > $procXtermCmdFile
echo "$procCmd" >> $procXtermCmdFile
chmod +x $procXtermCmdFile
if [ $proc -ne 0 ]
then
cmd="${cmd} :"
fi
cmd="${cmd} -n 1 ${procXtermCmdFile}"
done < $PWD/mpirun.schema
;;
*)
echo
echo "Unsupported WM_MPLIB setting : $WM_MPLIB"
printUsage
exit 1
esac
echo "Constructed $PWD/mpirun.schema file."
echo ""
echo " $cmd"
echo ""
$ECHO "Press return to execute.\c"
read dummy
exec $cmd
#------------------------------------------------------------------------------