/[escript]/trunk/bin/run-escript
ViewVC logotype

Contents of /trunk/bin/run-escript

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3162 - (show annotations)
Tue Sep 7 05:29:32 2010 UTC (9 years, 1 month ago) by jfenwick
File size: 14964 byte(s)
Changes to match packages in the debian repo.
Also got rid of lib/pyversion

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 ../../pkg 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.$USER.$$
26 HOSTFILE2=/tmp/escript2.$USER.$$
27
28 #Begin finding ESCRIPT_ROOT
29 if [ $STDLOCATION -ne 0 ]
30 then
31 ESCRIPT_ROOT=/usr/lib/escript
32 else
33 #We don't know the escript root so we need to work it out from the invocation
34 #Need to match if the name contains /
35 if [[ $0 =~ / ]]
36 then
37 # We are not using the PATH to find the script
38 cd `dirname $0`
39 scriptdir=`pwd`
40 cd $CURDIR
41 else
42 # name does not contain / therefore we are using
43 tscriptdir=`which $0`
44 if [ $? -ne 0 ]
45 then
46 echo "Error! Unable to determine script directory. Exiting."
47 exit 1
48 fi
49 scriptdir=`dirname $tscriptdir`
50 fi
51
52 cd $scriptdir/..
53 ESCRIPT_ROOT=`pwd`
54 cd ..
55 ESCRIPT_PARENT=`pwd`
56 cd $CURDIR
57
58 fi
59 ##### End finding ESCRIPT_ROOT ########
60
61 if [ ! -r $ESCRIPT_ROOT/lib/buildvars ]; then
62 echo "Error! Unable to read escript build information. Exiting."
63 exit 1
64 fi
65
66 PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"
67 PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"
68 PYTHON_CMD=python
69
70 # if possible please express paths relative to $ESCRIPT_ROOT unless
71 # they are in an unrelated location
72
73 EXTRA_DYLD_LIBRARY_PATH=""
74 EXTRA_PATH=$ESCRIPT_ROOT/bin
75 EXTRA_PYTHONPATH=$ESCRIPT_ROOT
76 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
77
78 if [ $STANDALONE -eq 1 ]
79 then
80 EXTRA_PATH=$ESCRIPT_PARENT/pkg/python/bin:$EXTRA_PATH
81 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/pkg/boost/lib:$ESCRIPT_PARENT/pkg/netcdf/lib/:$EXTRA_LD_LIBRARY_PATH
82 EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH
83 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/pkg/python/lib:$EXTRA_LD_LIBRARY_PATH
84 EXTRA_PYTHONPATH=$ESCRIPT_PARENT/pkg/numpy/lib/python2.6/site-packages:$ESCRIPT_PARENT/pkg/matplotlib/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
85 fi
86
87 #
88 # Add VisIt paths if required
89 #
90 WITH_VISIT=`grep usevisit $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
91 if [ "$WITH_VISIT" = "y" ]; then
92 VISIT_BIN=`which visit`
93 if [ $? -eq 0 ]; then
94 VISIT_PY_PATH=`$VISIT_BIN -env | grep LIBPATH | cut -d= -f2`
95 EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH
96 EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$VISIT_PY_PATH
97 elif [ ! -z $ESCRIPT_VERBOSE ]; then
98 echo "VisIt module enabled but VisIt not in path!"
99 fi
100 fi
101
102 HELP_TEXT="
103 Usage: escript [options] script.py [arguments...]
104 -n nn number of nodes to use
105 -p np number of MPI processes to spawn
106 -t nt number of OpenMP threads to use
107 -f file name of MPI hostfile
108 -c print compile information for escript and exit
109 -V print escript version and exit
110 -i interactive mode
111 -b do not invoke python (run non-python programs)
112 -e print export statements for environment and exit
113 -o redirect output from MPI to files
114 -v print diagnostics
115 -x ..reserved for future use ..
116 script.py Your python script
117 arguments... The optional command-line arguments to your script
118 "
119
120 if [ "$1" = "--help" ]; then
121 echo "$HELP_TEXT"
122 exit 0
123 fi
124 #=======================================================================================
125
126 # Avoid bug in hybrid runs with MPT MPI
127
128
129 # Parse the command-line options
130 # option e should not be followed by a :
131 while getopts 'bn:p:t:f:h:ecVviox' option
132 do
133 case "$option" in
134 "b") DOBINARY=yes
135 ;;
136 "n") ESCRIPT_NUM_NODES=$OPTARG
137 ;;
138 "p") ESCRIPT_NUM_PROCS=$OPTARG
139 ;;
140 "t") ESCRIPT_NUM_THREADS=$OPTARG
141 ;;
142 "f") ESCRIPT_HOSTFILE=$OPTARG
143 ;;
144 "c") cat $ESCRIPT_ROOT/lib/buildvars
145 exit 0
146 ;;
147 "V") echo "escript-development(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"
148 exit 0
149 ;;
150 "h") echo "$HELPTEXT"
151 exit 0
152 ;;
153 "i") DOINTERACTIVE=yes
154 ;;
155 "e") echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
156 echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
157 echo "export PATH=$EXTRA_PATH:\$PATH"
158 if [ "`uname`" = "Darwin" ]
159 then
160 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
161 fi
162 exit 0
163 ;;
164 "o") ESCRIPT_CREATESTDFILES="yes"
165 ;;
166 "v") ESCRIPT_VERBOSE="yes"
167 ;;
168 "x") echo "-x not implemented yet"
169 exit 1
170 ;;
171 ?) echo "$HELP_TEXT"
172 exit 1
173 ;;
174 esac
175 done
176 shift `expr $OPTIND - 1`
177 #==============================================
178 #
179 # Read the MPI_FLAVOUR from the buildvars
180 #
181 MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
182 WITH_OPENMP=`grep useopenmp $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
183
184 if [ ! -z $ESCRIPT_VERBOSE ]; then
185 echo "MPI flavour is $MPI_FLAVOUR."
186 if [ "$WITH_OPENMP" = "y" ]; then echo "OpenMP enabled."; fi
187 fi
188
189 #
190 # extend path variables
191 #
192 export PATH=$EXTRA_PATH:$PATH
193 export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
194 export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
195 EXPORT_ENV="PATH,LD_LIBRARY_PATH,PYTHONPATH"
196 if [ "`uname`" = "Darwin" ]
197 then
198 export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
199 EXPORT_ENV="$EXPORT_ENV,DYLD_LIBRARY_PATH"
200 fi
201 if [ ! -z $ESCRIPT_VERBOSE ]
202 then
203 echo "PATH = $PATH "
204 echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
205 echo "PYTHONPATH = $PYTHONPATH "
206 if [ ! -z $DYLD_LIBRARY_PATH ]; then echo "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH "; fi
207 fi
208 #==============================================
209 #
210 # Ensure the variables have sensible values
211 #
212 if [ "$MPI_FLAVOUR" = "none" ]
213 then
214 if [ ! -z $ESCRIPT_NUM_NODES ]
215 then
216 echo "Warning: MPI disabled but number of nodes set. Option ignored."
217 fi
218 if [ ! -z $ESCRIPT_NUM_PROCS ]
219 then
220 echo "Warning: MPI disabled but number of processors per node set. Option ignored."
221 fi
222 if [ ! -z $ESCRIPT_HOSTFILE ]
223 then
224 echo "Warning: MPI disabled but host file is given. Option ignored."
225 fi
226 ESCRIPT_NUM_NODES=1
227 ESCRIPT_NUM_PROCS=1
228 else
229 # use the PBS_NODEFILE if not otherwise specified
230 if [[ ( ! -z $PBS_NODEFILE ) && ( -z $ESCRIPT_HOSTFILE ) ]]
231 then
232 ESCRIPT_HOSTFILE=$PBS_NODEFILE
233
234 fi
235
236 if [ ! -z $ESCRIPT_HOSTFILE ]
237 then
238 if [ -f $ESCRIPT_HOSTFILE ]
239 then
240 cat $ESCRIPT_HOSTFILE | sort -u > $HOSTFILE
241 NUM_HOSTS=`cat $HOSTFILE | wc -l`
242 if [ ! -z $ESCRIPT_NUM_NODES ]
243 then
244 if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]
245 then
246 echo "number of hosts selected in the host file $ESCRIPT_HOSTFILE needs to match the requested number of nodes $ESCRIPT_NUM_NODES."
247 exit 1
248 fi
249 else
250 ESCRIPT_NUM_NODES=$NUM_HOSTS
251 fi
252 else
253 echo "cannot find hostfile $ESCRIPT_HOSTFILE."
254 exit 1
255 fi
256 else
257 HOSTFILE=''
258 fi
259
260 if [ -z $ESCRIPT_NUM_NODES ]
261 then
262 ESCRIPT_NUM_NODES=1
263 fi
264
265 if [ -z $ESCRIPT_NUM_PROCS ]
266 then
267 ESCRIPT_NUM_PROCS=1
268 fi
269
270 if [ ! -z $ESCRIPT_VERBOSE ]
271 then
272 echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
273 echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
274 fi
275 fi
276
277 if [ "$WITH_OPENMP" = "y" ]
278 then
279 if [ -z $ESCRIPT_NUM_THREADS ]
280 then
281 ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
282 if [ -z $ESCRIPT_NUM_THREADS ]
283 then
284 ESCRIPT_NUM_THREADS=1
285 fi
286 fi
287 if [ ! -z $ESCRIPT_VERBOSE ]
288 then
289 echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."
290 fi
291 else
292 if [[ ( ! -z $ESCRIPT_NUM_THREADS ) && ( $ESCRIPT_NUM_THREADS != 1 ) ]]
293 then
294 echo "Warning: OpenMP is disabled but number of threads requested is $ESCRIPT_NUM_THREADS!=1. Running without threads."
295 fi
296 ESCRIPT_NUM_THREADS=1
297 fi
298 #
299 # Now we compute total number of Processes
300 #
301 (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
302 if [ $? -ne 0 ] #Some compute error
303 then #This could happen if the args were not a number
304 echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."
305 exit 1
306 fi
307
308 #
309 # Test to ensure people aren't trying to combine interactive and multi-process
310 #
311 if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
312 then
313 echo "Interactive mode cannot be used with more than one process"
314 exit 1
315 fi
316
317 if [ $TOTPROC -gt 1 ]
318 then
319 if [ "$ESCRIPT_CREATESTDFILES" = "yes" ]
320 then
321 PYTHON_MPI=$PYTHON_MPI_REDIRECT
322 else
323 PYTHON_MPI=$PYTHON_MPI_NULL
324 fi
325 else
326 PYTHON_MPI=$PYTHON_MPI_NULL
327 fi
328 #=========================================================================================================
329 # Must have at least one command-line arg: the python script
330 if [ $# -eq 0 ]
331 then
332 if [ ! -z $DOBINARY ]
333 then
334 echo "No program to run was specified. Exiting."
335 exit 1
336 else
337 DOINTERACTIVE="yes"
338 fi
339 fi
340
341 #=========================================================================================================
342 if [ ! -z $DOBINARY ]
343 then
344 EXEC_CMD="$@"
345 else
346 if [ "$MPI_FLAVOUR" = "none" ]
347 then
348 # Check to see if the python version we were compiled with matches the one of EXEC_CMD
349 # We should only do this check if they are running a python script
350 if [ -f $ESCRIPT_ROOT/lib/pyversion ]
351 then
352 compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
353 intversion=`$PYTHON_CMD -c 'import sys;print "%d.%d.%d"%(sys.version_info[0], sys.version_info[1], sys.version_info[2])'`
354 if [ "$compversion" != "$intversion" ]
355 then
356 echo "Python versions do not match. Escript was compiled for "$compversion"."
357 echo "Current version of Python appears to be "$intversion"."
358 exit 1
359 fi
360 fi
361 if [ ! -z $DOINTERACTIVE ]
362 then
363 EXEC_CMD="$PYTHON_CMD -i $@"
364 else
365 EXEC_CMD="$PYTHON_CMD $@"
366 fi
367 else
368 if [ ! -z $DOINTERACTIVE ]
369 then
370 EXEC_CMD="$PYTHON_MPI -i $@"
371 else
372 EXEC_CMD="$PYTHON_MPI $@"
373 fi
374 fi
375 fi
376 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is \"$EXEC_CMD\"."; fi
377 #===============================================================================================
378 #
379 # now we start to spwan things:
380 #
381 if [ "$WITH_OPENMP" = "y" ]
382 then
383 export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
384 EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"
385 fi
386 EXIT_CODE=1
387 #=============== no MPI ===================================
388 if [ "$MPI_FLAVOUR" = "none" ]
389 then
390 $EXEC_CMD
391 EXIT_CODE=$?
392 #=============== OpenMPI ===================================
393 elif [ "$MPI_FLAVOUR" = "OPENMPI" ]
394 then
395 if [ ! -z $HOSTFILE ]
396 then
397 HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
398 CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } --bynode -np $TOTPROC --host $HOST_LIST $EXEC_CMD"
399 else
400 CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } -np $TOTPROC $EXEC_CMD"
401 fi
402 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
403 $CMD
404 EXIT_CODE=$?
405
406 #=============== Intel MPI ===================================
407 elif [ "$MPI_FLAVOUR" = "INTELMPI" ]
408 then
409
410 if [ "$WITH_OPENMP" = "y" ]
411 then
412 export I_MPI_PIN_DOMAIN=omp
413 EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"
414 fi
415
416 if [ ! -z $HOSTFILE ]
417 then
418 mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE
419 if [ $? -ne 0 ]
420 then
421 echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."
422 exit 1
423 else
424 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi
425 fi
426 else
427 mpdboot -n 1 -r ssh
428 if [ $? -ne 0 ]
429 then
430 echo "mpdboot failed."
431 exit 1
432 else
433 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi
434 fi
435 fi
436 CMD="mpiexec -perhost $ESCRIPT_NUM_PROCS -envall -n $TOTPROC $EXEC_CMD"
437 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
438 $CMD
439 EXIT_CODE=$?
440 mpdallexit
441 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
442 #=============== SGI's MPIMPT ===================================
443 elif [ "$MPI_FLAVOUR" = "MPT" ]
444 then
445 export MPI_NUM_MEMORY_REGIONS=0
446 EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"
447 if [ ! -z $HOSTFILE ]
448 then
449 HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
450 CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"
451 else
452 CMD="mpirun -np $TOTPROC $EXEC_CMD"
453 fi
454 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
455 $CMD
456 EXIT_CODE=$?
457 #=============== MPICH ===================================
458 elif [ "$MPI_FLAVOUR" = "MPICH" ]
459 then
460 if [ ! -z $HOSTFILE ]
461 then
462 touch $HOSTFILE2
463 for (( i=1;i<=$ESCRIPT_NUM_PROCS;i+=1 )) ; do cat $HOSTFILE >> $HOSTFILE2 ; done
464 CMD="mpirun -machinefile $HOSTFILE2 -np $TOTPROC $EXEC_CMD"
465 else
466 CMD="mpirun -np $TOTPROC $EXEC_CMD"
467 fi
468 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
469 $CMD
470 EXIT_CODE=$?
471 #=============== MPICH2 ===================================
472 elif [ "$MPI_FLAVOUR" = "MPICH2" ]
473 then
474 if [ ! -z $HOSTFILE ]
475 then
476 mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE
477 if [ $? -ne 0 ]
478 then
479 echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."
480 exit 1
481 else
482 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi
483 fi
484 else
485 mpdboot -n 1 -r ssh
486 if [ $? -ne 0 ]
487 then
488 echo "mpdboot failed."
489 exit 1
490 else
491 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi
492 fi
493 fi
494 CMD="mpiexec -genvlist $EXPORT_ENV -np $TOTPROC $EXEC_CMD"
495 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
496 $CMD
497 EXIT_CODE=$?
498 mpdallexit
499 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
500 else
501 echo "unknown MPI flavour '$MPI_FLAVOUR'."
502 fi
503 exit $EXIT_CODE

Properties

Name Value
svn:executable *
svn:mergeinfo /branches/lapack2681/bin/escript:2682-2741 /branches/restext/bin/escript:2610-2624 /branches/stage3.0/bin/escript:2569-2590 /release/3.0/bin/escript:2591-2601

  ViewVC Help
Powered by ViewVC 1.1.26