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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2458 - (show annotations)
Wed Jun 3 06:18:21 2009 UTC (10 years, 3 months ago) by jfenwick
File size: 13674 byte(s)
Various numarray erasures

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

  ViewVC Help
Powered by ViewVC 1.1.26