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

Annotation of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2359 - (hide annotations)
Thu Apr 2 03:50:33 2009 UTC (10 years, 5 months ago) by jfenwick
File size: 12153 byte(s)
Moved man page for easier testing.
Modified the wrapper script to take into account debian packaging.
This setting is recorded in the escript wrapper automatically by the package building script.
1 jfenwick 2299 #!/bin/bash
2 ksteube 1756
3 ksteube 1824 # Escript/Finley wrapper for python
4     # Sets LD_LIBRARY_PATH and PYTHONPATH and then runs either python or the MPI launcher
5    
6 jfenwick 2298 #Extra paths can be configured about a page further down
7     #Search for EXTRA_PATH=""
8 jfenwick 2297
9 jfenwick 2299 #set to 1 if performing this is a standalone build and /packages contains the relevant tools
10     STANDALONE=0
11 jfenwick 2297
12 jfenwick 2359 #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 jfenwick 2296 #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 jfenwick 2332 #Environment vars which control operations:
23 gross 2357 # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROCS, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_CREATESTDFILES
24 jfenwick 2332
25 gross 2350 HOSTFILE=/tmp/escript.$$
26 jfenwick 2332
27 jfenwick 2359 #Begin finding ESCRIPT_ROOT
28     if [ $STDLOCATION != 0 ]
29 jfenwick 2296 then
30 jfenwick 2359 ESCRIPT_ROOT=/usr/lib/escript
31 jfenwick 2296 else
32 jfenwick 2359 #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 jfenwick 2296 fi
58 jfenwick 2298 ##### End finding ESCRIPT_ROOT ########
59    
60 gross 2349 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
61 gross 2350 PYTHON_CMD=python
62 gross 2349
63 jfenwick 2298 # if possible please express paths relative to $ESCRIPT_ROOT unless
64     # they are in an unrelated location
65    
66     EXTRA_DYLD_LIBRARY_PATH=""
67 gross 2349 EXTRA_PATH=$ESCRIPT_ROOT/bin
68     EXTRA_PYTHONPATH=$ESCRIPT_ROOT
69     EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
70 jfenwick 2298
71 jfenwick 2299 if [ $STANDALONE == 1 ]
72     then
73 jfenwick 2312 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 jfenwick 2299 fi
79    
80 ksteube 1756
81 jfenwick 2298
82     HELP_TEXT="
83     Usage: escript [options] script.py [arguments...]
84 jfenwick 2332 -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 jfenwick 2343 -b do not invoke python (run non-python programs)
92 jfenwick 2332 -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 jfenwick 2298 script.py Your python script
97 jfenwick 2332 arguments... The optional command-line arguments to your script
98 jfenwick 2298 "
99    
100     if [ "$1" = "--help" ]; then
101     echo "$HELP_TEXT"
102     exit 0
103     fi
104 gross 2349 #=======================================================================================
105 jfenwick 2298
106 ksteube 1909 # Avoid bug in hybrid runs with MPT MPI
107    
108 ksteube 1756
109     # Parse the command-line options
110 jfenwick 2296 # option e should not be followed by a :
111 jfenwick 2343 while getopts 'bn:p:t:f:h:ecVviox' option
112 ksteube 1756 do
113     case "$option" in
114 jfenwick 2343 "b") DOBINARY=yes
115     ;;
116 jfenwick 2332 "n") ESCRIPT_NUM_NODES=$OPTARG
117 ksteube 1756 ;;
118 gross 2357 "p") ESCRIPT_NUM_PROCS=$OPTARG
119 ksteube 1756 ;;
120 jfenwick 2332 "t") ESCRIPT_NUM_THREADS=$OPTARG
121 ksteube 1756 ;;
122 jfenwick 2332 "f") ESCRIPT_HOSTFILE=$OPTARG
123 ksteube 1756 ;;
124 jfenwick 2332 "c") cat $ESCRIPT_ROOT/lib/buildvars
125     exit 0
126 ksteube 1756 ;;
127 jfenwick 2332 "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 jfenwick 2298 "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 jfenwick 2296 if [ `uname` == Darwin ]
139     then
140 jfenwick 2298 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
141 jfenwick 2296 fi
142     exit 0
143     ;;
144 gross 2349 "o") ESCRIPT_CREATESTDFILES="yes"
145 jfenwick 2332 ;;
146 gross 2349 "v") ESCRIPT_VERBOSE="yes"
147 jfenwick 2332 ;;
148     "x") echo "-x not implemented yet"
149     exit 1
150     ;;
151 ksteube 1756 ?) echo "$HELP_TEXT"
152     exit 1
153     ;;
154     esac
155     done
156     shift `expr $OPTIND - 1`
157 gross 2349 #==============================================
158     #
159     # Read the MPI_FLAVOUR from the buildvars
160     #
161 jfenwick 2338 MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
162 jfenwick 2332
163 gross 2349 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ] && [ $MPI_FLAVOUR == "none" ]
164     then
165     echo "compiled with MPI but no MPI flavour specified."
166     exit 1
167     fi
168    
169     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI flavor is $MPI_FLAVOUR."; fi
170     if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ];
171     then
172     ESCRIPT_WITH_OPENMP="yes"
173     fi
174 jfenwick 2359 if [ ! -z $ESCRIPT_VERBOSE ] && [ ! -z $ESCRIPT_WITH_OPENMP ]; then echo "OpenMP enabled."; fi
175 gross 2349 #
176     # extend path variables
177     #
178 jfenwick 2298 export PATH=$EXTRA_PATH:$PATH
179     export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
180     export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
181 gross 2349 EXPORT_ENV="PATH, LD_LIBRARY_PATH, PYTHONPATH"
182 jfenwick 2298 if [ `uname` == Darwin ]
183     then
184     export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
185 gross 2349 EXPORT_ENV="$EXPORT_ENV, DYLD_LIBRARY_PATH"
186 jfenwick 2298 fi
187 gross 2349 if [ ! -z $ESCRIPT_VERBOSE ]
188     then
189     echo "PATH = $PATH "
190     echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
191     echo "PYTHONPATH = $PYTHONPATH "
192     if [ ! -z $DYLD_LIBRARY_PATH ]; then echo "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH "; fi
193     fi
194     #==============================================
195     #
196     # Ensure the variables have sensible values
197     #
198     if [ $MPI_FLAVOUR == "none" ]
199 jfenwick 2343 then
200 gross 2349 if [ ! -z $ESCRIPT_NUM_NODES ]
201     then
202     echo "Warning: MPI disabled but number of nodes set. Option ignored."
203     fi
204     if [ ! -z $ESCRIPT_NUM_PROCS ]
205     then
206     echo "Warning: MPI disabled but number of processors per node set. Option ignored."
207     fi
208 gross 2350 if [ ! -z $ESCRIPT_HOSTFILE ]
209     then
210     echo "Warning: MPI disabled but host file is given. Option ignored."
211     fi
212 gross 2349 ESCRIPT_NUM_NODES=1
213     ESCRIPT_NUM_PROCS=1
214     else
215 gross 2350 if [ ! -z $ESCRIPT_HOSTFILE ]
216     then
217     if [ -f $ESCRIPT_HOSTFILE ]
218     then
219     cat $ESCRIPT_HOSTFILE | sort -u > $HOSTFILE
220 gross 2357 NUM_HOSTS=`cat $HOSTFILE | wc -l`
221 gross 2350 if [ ! -z $ESCRIPT_NUM_NODES ]
222     then
223     if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]
224     then
225     echo "number of hosts selected in the host file $ESCRIPT_HOSTFILE needs to match the requested number of nodes $ESCRIPT_NUM_NODES."
226     exit 1
227     fi
228     else
229 gross 2357 ESCRIPT_NUM_NODES=$NUM_HOSTS
230 gross 2350 fi
231     else
232     echo "cannot find hostfile $ESCRIPT_HOSTFILE."
233     exit 1
234     fi
235     else
236     HOSTFILE=''
237     fi
238    
239 gross 2349 if [ -z $ESCRIPT_NUM_NODES ]
240     then
241     ESCRIPT_NUM_NODES=1
242     fi
243 gross 2350
244 gross 2349 if [ -z $ESCRIPT_NUM_PROCS ]
245     then
246     ESCRIPT_NUM_PROCS=1
247     fi
248 gross 2350
249 gross 2349 if [ ! -z $ESCRIPT_VERBOSE ]
250     then
251     echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
252     echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
253     fi
254 jfenwick 2343 fi
255 gross 2350
256 gross 2349 if [ ! -z $ESCRIPT_WITH_OPENMP ]
257 jfenwick 2299 then
258 gross 2349 if [ -z $ESCRIPT_NUM_THREADS ]
259     then
260     ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
261     if [ -z $ESCRIPT_NUM_THREADS ]
262     then
263     ESCRIPT_NUM_THREADS=1
264     fi
265     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Number of threads is $ESCRIPT_NUM_THREADS."; fi
266 jfenwick 2299 fi
267 gross 2349 else
268     ESCRIPT_NUM_THREADS=1
269 jfenwick 2299 fi
270 gross 2349 #
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     # Test to ensure people aren't trying to combine interactive and multi-process
281     #
282 gross 2357 if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
283 gross 2349 then
284     echo "Interactive mode cannot be used with more than one process"
285     exit 1
286     fi
287     #=========================================================================================================
288 gross 2350 # Must have at least one command-line arg: the python script
289     if [ $# -eq 0 ]
290     then
291     if [ ! -z $DOBINARY ]
292     then
293     echo "No program to run was specified. Exiting."
294     exit 1
295     fi
296     fi
297    
298     #=========================================================================================================
299 gross 2349 if [ ! -z $DOBINARY ]
300     then
301 gross 2350 EXEC_CMD="$@"
302 gross 2349 else
303 gross 2350 if [ $MPI_FLAVOUR == "none" ]
304 gross 2349 then
305 gross 2350 # Check to see if the python version we were compiled with matches the one of EXEC_CMD
306 gross 2349 # We should only do this check if they are running a python script
307     if [ -f $ESCRIPT_ROOT/lib/pyversion ]
308     then
309     compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
310     intversion=`$PYTHON_CMD --version 2>&1`
311     if [ "$compversion" != "$intversion" ]
312     then
313     echo "Python versions do not match. Escript was compiled for "$compversion"."
314     echo "Current version of Python appears to be "$intversion"."
315     exit 1
316     fi
317     fi
318     if [ ! -z $DOINTERACTIVE ]
319     then
320 gross 2350 EXEC_CMD="$PYTHON_CMD -i $@"
321 gross 2349 else
322 gross 2350 EXEC_CMD="$PYTHON_CMD $@"
323 gross 2349 fi
324 gross 2350 else
325 gross 2357 EXEC_CMD="$PYTHON_MPI $@"
326 gross 2349 fi
327     fi
328 gross 2350 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is $EXEC_CMD."; fi
329 gross 2349 #===============================================================================================
330     #
331     # now we start to spwan things:
332     #
333     if [ ! -z $ESCRIPT_WITH_OPENMP ]
334 jfenwick 2332 then
335 gross 2349 export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
336     EXPORT_ENV="$EXPORT_ENV, OMP_NUM_THREADS"
337 jfenwick 2332 fi
338    
339 gross 2355 #=============== no MPI ===================================
340 gross 2349 if [ $MPI_FLAVOUR == "none" ]
341 jfenwick 2332 then
342 jfenwick 2359 echo $EXEC_CMD
343 gross 2350 $EXEC_CMD
344 gross 2355
345     #=============== OpenMPI ===================================
346 gross 2349 elif [ $MPI_FLAVOUR == "OPENMPI" ]
347     then
348     echo "OPENMPI not implemented yet."
349 jfenwick 2332
350 gross 2355 #=============== Intel MPI ===================================
351 gross 2357 elif [ $MPI_FLAVOUR == "INTELMPI" ]
352 gross 2355 then
353 gross 2357 if [ ! -z $HOSTFILE ]
354 gross 2355 then
355     mpdboot -n $ESCRIPT_NUM_PROCS -r ssh -f $HOSTFILE
356     if [ $? -ne 0 ]
357     then
358     echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_PROCS nodes failed."
359     exit 1
360     else
361     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_PROCS nodes."; fi
362     fi
363     fi
364     $CMD="mpiexec -n $ESCRIPT_NUM_PROCS -perhost $ESCRIPT_NUM_PROCS -envall -$EXEC_CMD"
365     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is $CMD."; fi
366 jfenwick 2359 echo $CMD
367 gross 2355 $CMD
368 gross 2357 if [ ! -z $HOSTFILE ]
369 gross 2355 then
370     mpdallexit
371     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
372     fi
373     #=============== SGI's MPIMPT ===================================
374 gross 2357 elif [ $MPI_FLAVOUR == "MPT" ]
375 jfenwick 2332 then
376 gross 2349 export MPI_NUM_MEMORY_REGIONS=0
377 gross 2350 EXPORT_ENV="$EXPORT_ENV, MPI_NUM_MEMORY_REGIONS"
378 gross 2357 if [ ! -z $HOSTFILE ]
379 gross 2350 then
380     HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
381 gross 2357 CMD="mpirun $HOST_LIST $ESCRIPT_NUM_PROCS $EXEC_CMD"
382 gross 2350 else
383 gross 2357 CMD="mpirun -np $TOTPROC $EXEC_CMD"
384 gross 2350 fi
385     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is $CMD."; fi
386 jfenwick 2359 echo $CMD
387 gross 2350 $CMD
388 gross 2355 #=============== SGI's MPICH ===================================
389 gross 2357 elif [ $MPI_FLAVOUR == "MPICH" ]
390 jfenwick 2332 then
391 gross 2349 echo "MPICH not implemented yet."
392     else
393 gross 2357 echo "unknown MPI falvour $MPI_FLAVOUR."
394 gross 2349 exit 1
395 jfenwick 2332 fi
396 gross 2349 exit 0
397 ksteube 1756 # Using OpenMP?
398 gross 2349 #OMP_OPTIONS=''
399     #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
400 gross 2350 # EXEC_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
401 gross 2349 # ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
402     # OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"
403     #fi
404 ksteube 1756
405     # Using MPI?
406 gross 2349 #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
407 gross 2350 # EXEC_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
408 gross 2349 #else
409     # if [ "$TOTPROC" -ne 1 ]; then
410     # echo "Escript/Finley was not compiled for MPI. You can not use the -n and -p options."
411     # exit 1
412     # fi
413     #fi

  ViewVC Help
Powered by ViewVC 1.1.26