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

Annotation of /trunk/bin/run-escript

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2568 - (hide annotations)
Fri Jul 31 05:37:41 2009 UTC (9 years, 6 months ago) by jfenwick
Original Path: trunk/bin/escript
File size: 13547 byte(s)
Updated install guide to include the correct version of python.
Updated Mac build instructions not to use numarray or frameworks.
Removed (commented out) references to MacPorts in the Mac instructions.
- These need to be updated and Artak isn't here.

Removed (commented out) references to windows in the install guide.
CSIRO won't have a windows release ready yet. 


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26