/[escript]/branches/py3_attempt2/bin/run-escript
ViewVC logotype

Annotation of /branches/py3_attempt2/bin/run-escript

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3047 - (hide annotations)
Thu Jun 24 00:33:05 2010 UTC (8 years, 4 months ago) by jfenwick
Original Path: trunk/bin/run-escript
File size: 14332 byte(s)
Adding user name to tmpfiles.
Changing name of cluster options file to savanna from service0

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