/[escript]/trunk/scripts/finley_wrapper_template
ViewVC logotype

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2365 - (show annotations)
Mon Apr 6 01:25:25 2009 UTC (10 years, 5 months ago) by gross
File size: 11765 byte(s)
all tests passed under scons on 4 mpi processes with  openmpi on shake34
1 #!/bin/bash
2
3 # Escript/Finley wrapper for python
4 # Sets LD_LIBRARY_PATH and PYTHONPATH and then runs either python or the MPI launcher
5
6 #Extra paths can be configured about a page further down
7 #Search for EXTRA_PATH=""
8
9 #set to 1 if performing this is a standalone build and /packages contains the relevant tools
10 STANDALONE=0
11
12 #set to 1 if this is part of a packaged build (.deb) and files will be installed in standard locations
13 #rather than everything in a single directory
14 #Do not use this together with $STANDALONE
15 STDLOCATION=0
16
17 #Now we find the location of this script
18 #Note that this location should be absolute but does not need to be unique
19 scriptdir=""
20 CURDIR=`pwd`
21
22 #Environment vars which control operations:
23 # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROCS, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_CREATESTDFILES
24
25 HOSTFILE=/tmp/escript.$$
26
27 #Begin finding ESCRIPT_ROOT
28 if [ $STDLOCATION != 0 ]
29 then
30 ESCRIPT_ROOT=/usr/lib/escript
31 else
32 #We don't know the escript root so we need to work it out from the invocation
33 #Need to match if the name contains /
34 if [[ $0 =~ / ]]
35 then
36 # We are not using the PATH to find the script
37 cd `dirname $0`
38 scriptdir=`pwd`
39 cd $CURDIR
40 else
41 # name does not contain / therefore we are using
42 tscriptdir=`which $0`
43 if [ $? != 0 ]
44 then
45 echo "Error unable to determine script directory. Exiting."
46 exit 1
47 fi
48 scriptdir=`dirname $tscriptdir`
49 fi
50
51 cd $scriptdir/..
52 ESCRIPT_ROOT=`pwd`
53 cd ..
54 ESCRIPT_PARENT=`pwd`
55 cd $CURDIR
56
57 fi
58 ##### End finding ESCRIPT_ROOT ########
59
60 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
61 PYTHON_CMD=python
62
63 # if possible please express paths relative to $ESCRIPT_ROOT unless
64 # they are in an unrelated location
65
66 EXTRA_DYLD_LIBRARY_PATH=""
67 EXTRA_PATH=$ESCRIPT_ROOT/bin
68 EXTRA_PYTHONPATH=$ESCRIPT_ROOT
69 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
70
71 if [ $STANDALONE == 1 ]
72 then
73 EXTRA_PATH=$ESCRIPT_PARENT/packages/python/bin:$EXTRA_PATH
74 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/boost/lib:$ESCRIPT_PARENT/packages/netcdf/lib/:$EXTRA_LD_LIBRARY_PATH
75 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/vtk/lib/vtk-5.2:$ESCRIPT_PARENT/packages/mesa/lib:$EXTRA_LD_LIBRARY_PATH
76 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/python/lib:$EXTRA_LD_LIBRARY_PATH
77 EXTRA_PYTHONPATH=$ESCRIPT_PARENT/packages/numarray/lib:$ESCRIPT_PARENT/packages/vtk/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
78 fi
79
80
81
82 HELP_TEXT="
83 Usage: escript [options] script.py [arguments...]
84 -n nn number of nodes to use
85 -p np number of MPI processes to spawn
86 -t nt number of OpenMP threads to use
87 -f file name of MPI hostfile
88 -c print compile information for escript and exit
89 -V print escript version and exit
90 -i interactive mode
91 -b do not invoke python (run non-python programs)
92 -e print export statements for environment and exit
93 -o redirect output from MPI to files
94 -v print diagnostics
95 -x ..reserved for future use ..
96 script.py Your python script
97 arguments... The optional command-line arguments to your script
98 "
99
100 if [ "$1" = "--help" ]; then
101 echo "$HELP_TEXT"
102 exit 0
103 fi
104 #=======================================================================================
105
106 # Avoid bug in hybrid runs with MPT MPI
107
108
109 # Parse the command-line options
110 # option e should not be followed by a :
111 while getopts 'bn:p:t:f:h:ecVviox' option
112 do
113 case "$option" in
114 "b") DOBINARY=yes
115 ;;
116 "n") ESCRIPT_NUM_NODES=$OPTARG
117 ;;
118 "p") ESCRIPT_NUM_PROCS=$OPTARG
119 ;;
120 "t") ESCRIPT_NUM_THREADS=$OPTARG
121 ;;
122 "f") ESCRIPT_HOSTFILE=$OPTARG
123 ;;
124 "c") cat $ESCRIPT_ROOT/lib/buildvars
125 exit 0
126 ;;
127 "V") echo "escript-pre2.0(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"
128 exit 0
129 ;;
130 "h") echo "$HELPTEXT"
131 exit 0
132 ;;
133 "i") DOINTERACTIVE=yes
134 ;;
135 "e") echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
136 echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
137 echo "export PATH=$EXTRA_PATH:\$PATH"
138 if [ `uname` == Darwin ]
139 then
140 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
141 fi
142 exit 0
143 ;;
144 "o") ESCRIPT_CREATESTDFILES="yes"
145 ;;
146 "v") ESCRIPT_VERBOSE="yes"
147 ;;
148 "x") echo "-x not implemented yet"
149 exit 1
150 ;;
151 ?) echo "$HELP_TEXT"
152 exit 1
153 ;;
154 esac
155 done
156 shift `expr $OPTIND - 1`
157 #==============================================
158 #
159 # Read the MPI_FLAVOUR from the buildvars
160 #
161 MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
162 WITH_OPENMP=`grep useopenmp $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
163
164 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI flavor is $MPI_FLAVOUR."; fi
165 if [ ! -z $ESCRIPT_VERBOSE ] && [ $WITH_OPENMP == "y" ]; then echo "OpenMP enabled."; fi
166 #
167 # extend path variables
168 #
169 export PATH=$EXTRA_PATH:$PATH
170 export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
171 export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
172 EXPORT_ENV="PATH, LD_LIBRARY_PATH, PYTHONPATH"
173 if [ `uname` == Darwin ]
174 then
175 export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
176 EXPORT_ENV="$EXPORT_ENV, DYLD_LIBRARY_PATH"
177 fi
178 if [ ! -z $ESCRIPT_VERBOSE ]
179 then
180 echo "PATH = $PATH "
181 echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
182 echo "PYTHONPATH = $PYTHONPATH "
183 if [ ! -z $DYLD_LIBRARY_PATH ]; then echo "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH "; fi
184 fi
185 #==============================================
186 #
187 # Ensure the variables have sensible values
188 #
189 if [ $MPI_FLAVOUR == "none" ]
190 then
191 if [ ! -z $ESCRIPT_NUM_NODES ]
192 then
193 echo "Warning: MPI disabled but number of nodes set. Option ignored."
194 fi
195 if [ ! -z $ESCRIPT_NUM_PROCS ]
196 then
197 echo "Warning: MPI disabled but number of processors per node set. Option ignored."
198 fi
199 if [ ! -z $ESCRIPT_HOSTFILE ]
200 then
201 echo "Warning: MPI disabled but host file is given. Option ignored."
202 fi
203 ESCRIPT_NUM_NODES=1
204 ESCRIPT_NUM_PROCS=1
205 else
206 if [ ! -z $ESCRIPT_HOSTFILE ]
207 then
208 if [ -f $ESCRIPT_HOSTFILE ]
209 then
210 cat $ESCRIPT_HOSTFILE | sort -u > $HOSTFILE
211 NUM_HOSTS=`cat $HOSTFILE | wc -l`
212 if [ ! -z $ESCRIPT_NUM_NODES ]
213 then
214 if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]
215 then
216 echo "number of hosts selected in the host file $ESCRIPT_HOSTFILE needs to match the requested number of nodes $ESCRIPT_NUM_NODES."
217 exit 1
218 fi
219 else
220 ESCRIPT_NUM_NODES=$NUM_HOSTS
221 fi
222 else
223 echo "cannot find hostfile $ESCRIPT_HOSTFILE."
224 exit 1
225 fi
226 else
227 HOSTFILE=''
228 fi
229
230 if [ -z $ESCRIPT_NUM_NODES ]
231 then
232 ESCRIPT_NUM_NODES=1
233 fi
234
235 if [ -z $ESCRIPT_NUM_PROCS ]
236 then
237 ESCRIPT_NUM_PROCS=1
238 fi
239
240 if [ ! -z $ESCRIPT_VERBOSE ]
241 then
242 echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
243 echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
244 fi
245 fi
246
247 if [ $WITH_OPENMP == "y" ]
248 then
249 if [ -z $ESCRIPT_NUM_THREADS ]
250 then
251 ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
252 if [ -z $ESCRIPT_NUM_THREADS ]
253 then
254 ESCRIPT_NUM_THREADS=1
255 fi
256 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Number of threads is $ESCRIPT_NUM_THREADS."; fi
257 fi
258 else
259 ESCRIPT_NUM_THREADS=1
260 fi
261 #
262 # Now we compute total number of Processes
263 #
264 (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
265 if [ $? -ne 0 ] #Some compute error
266 then #This could happen if the args were not a number
267 echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."
268 exit 1
269 fi
270 #
271 # Test to ensure people aren't trying to combine interactive and multi-process
272 #
273 if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
274 then
275 echo "Interactive mode cannot be used with more than one process"
276 exit 1
277 fi
278 #=========================================================================================================
279 # Must have at least one command-line arg: the python script
280 if [ $# -eq 0 ]
281 then
282 if [ ! -z $DOBINARY ]
283 then
284 echo "No program to run was specified. Exiting."
285 exit 1
286 fi
287 fi
288
289 #=========================================================================================================
290 if [ ! -z $DOBINARY ]
291 then
292 EXEC_CMD="$@"
293 else
294 if [ $MPI_FLAVOUR == "none" ]
295 then
296 # Check to see if the python version we were compiled with matches the one of EXEC_CMD
297 # We should only do this check if they are running a python script
298 if [ -f $ESCRIPT_ROOT/lib/pyversion ]
299 then
300 compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
301 intversion=`$PYTHON_CMD -V 2>&1`
302 if [ "$compversion" != "$intversion" ]
303 then
304 echo "Python versions do not match. Escript was compiled for "$compversion"."
305 echo "Current version of Python appears to be "$intversion"."
306 exit 1
307 fi
308 fi
309 if [ ! -z $DOINTERACTIVE ]
310 then
311 EXEC_CMD="$PYTHON_CMD -i $@"
312 else
313 EXEC_CMD="$PYTHON_CMD $@"
314 fi
315 else
316 EXEC_CMD="$PYTHON_MPI $@"
317 fi
318 fi
319 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is \"$EXEC_CMD\"."; fi
320 #===============================================================================================
321 #
322 # now we start to spwan things:
323 #
324 if [ $WITH_OPENMP == "y" ]
325 then
326 export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
327 EXPORT_ENV="$EXPORT_ENV, OMP_NUM_THREADS"
328 fi
329 EXIT_CODE=1
330 #=============== no MPI ===================================
331 if [ $MPI_FLAVOUR == "none" ]
332 then
333 $EXEC_CMD
334 EXIT_CODE=$?
335 #=============== OpenMPI ===================================
336 elif [ $MPI_FLAVOUR == "OPENMPI" ]
337 then
338 if [ ! -z $HOSTFILE ]
339 then
340 HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
341 CMD="mpirun --bynode -np $TOTPROC --host $HOST_LIST $EXEC_CMD"
342 else
343 CMD="mpirun -np $TOTPROC $EXEC_CMD"
344 fi
345 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
346 $CMD
347 EXIT_CODE=$?
348
349 #=============== Intel MPI ===================================
350 elif [ $MPI_FLAVOUR == "INTELMPI" ]
351 then
352 if [ ! -z $HOSTFILE ]
353 then
354 mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE
355 if [ $? -ne 0 ]
356 then
357 echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."
358 exit 1
359 else
360 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi
361 fi
362 fi
363 CMD="mpiexec -perhost $ESCRIPT_NUM_PROCS -envall -n $TOTPROC $EXEC_CMD"
364 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
365 $CMD
366 EXIT_CODE=$?
367 if [ ! -z $HOSTFILE ]
368 then
369 mpdallexit
370 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
371 fi
372 #=============== SGI's MPIMPT ===================================
373 elif [ $MPI_FLAVOUR == "MPT" ]
374 then
375 export MPI_NUM_MEMORY_REGIONS=0
376 EXPORT_ENV="$EXPORT_ENV, MPI_NUM_MEMORY_REGIONS"
377 if [ ! -z $HOSTFILE ]
378 then
379 HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
380 CMD="mpirun $HOST_LIST $ESCRIPT_NUM_PROCS $EXEC_CMD"
381 else
382 CMD="mpirun -np $TOTPROC $EXEC_CMD"
383 fi
384 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
385 $CMD
386 EXIT_CODE=$?
387 #=============== SGI's MPICH ===================================
388 elif [ $MPI_FLAVOUR == "MPICH" ]
389 then
390 echo "MPICH not implemented yet."
391 else
392 echo "unknown MPI falvour $MPI_FLAVOUR."
393 fi
394 exit $EXIT_CODE

  ViewVC Help
Powered by ViewVC 1.1.26