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

Annotation of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2365 - (hide annotations)
Mon Apr 6 01:25:25 2009 UTC (10 years, 5 months ago) by gross
File size: 11765 byte(s)
all tests passed under scons on 4 mpi processes with  openmpi on shake34
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 gross 2362 WITH_OPENMP=`grep useopenmp $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
163 jfenwick 2332
164 gross 2349 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI flavor is $MPI_FLAVOUR."; fi
165 gross 2362 if [ ! -z $ESCRIPT_VERBOSE ] && [ $WITH_OPENMP == "y" ]; then echo "OpenMP enabled."; fi
166 gross 2349 #
167     # extend path variables
168     #
169 jfenwick 2298 export PATH=$EXTRA_PATH:$PATH
170     export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
171     export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
172 gross 2349 EXPORT_ENV="PATH, LD_LIBRARY_PATH, PYTHONPATH"
173 jfenwick 2298 if [ `uname` == Darwin ]
174     then
175     export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
176 gross 2349 EXPORT_ENV="$EXPORT_ENV, DYLD_LIBRARY_PATH"
177 jfenwick 2298 fi
178 gross 2349 if [ ! -z $ESCRIPT_VERBOSE ]
179     then
180     echo "PATH = $PATH "
181     echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
182     echo "PYTHONPATH = $PYTHONPATH "
183     if [ ! -z $DYLD_LIBRARY_PATH ]; then echo "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH "; fi
184     fi
185     #==============================================
186     #
187     # Ensure the variables have sensible values
188     #
189     if [ $MPI_FLAVOUR == "none" ]
190 jfenwick 2343 then
191 gross 2349 if [ ! -z $ESCRIPT_NUM_NODES ]
192     then
193     echo "Warning: MPI disabled but number of nodes set. Option ignored."
194     fi
195     if [ ! -z $ESCRIPT_NUM_PROCS ]
196     then
197     echo "Warning: MPI disabled but number of processors per node set. Option ignored."
198     fi
199 gross 2350 if [ ! -z $ESCRIPT_HOSTFILE ]
200     then
201     echo "Warning: MPI disabled but host file is given. Option ignored."
202     fi
203 gross 2349 ESCRIPT_NUM_NODES=1
204     ESCRIPT_NUM_PROCS=1
205     else
206 gross 2350 if [ ! -z $ESCRIPT_HOSTFILE ]
207     then
208     if [ -f $ESCRIPT_HOSTFILE ]
209     then
210     cat $ESCRIPT_HOSTFILE | sort -u > $HOSTFILE
211 gross 2357 NUM_HOSTS=`cat $HOSTFILE | wc -l`
212 gross 2350 if [ ! -z $ESCRIPT_NUM_NODES ]
213     then
214     if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]
215     then
216     echo "number of hosts selected in the host file $ESCRIPT_HOSTFILE needs to match the requested number of nodes $ESCRIPT_NUM_NODES."
217     exit 1
218     fi
219     else
220 gross 2357 ESCRIPT_NUM_NODES=$NUM_HOSTS
221 gross 2350 fi
222     else
223     echo "cannot find hostfile $ESCRIPT_HOSTFILE."
224     exit 1
225     fi
226     else
227     HOSTFILE=''
228     fi
229    
230 gross 2349 if [ -z $ESCRIPT_NUM_NODES ]
231     then
232     ESCRIPT_NUM_NODES=1
233     fi
234 gross 2350
235 gross 2349 if [ -z $ESCRIPT_NUM_PROCS ]
236     then
237     ESCRIPT_NUM_PROCS=1
238     fi
239 gross 2350
240 gross 2349 if [ ! -z $ESCRIPT_VERBOSE ]
241     then
242     echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
243     echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
244     fi
245 jfenwick 2343 fi
246 gross 2350
247 gross 2362 if [ $WITH_OPENMP == "y" ]
248 jfenwick 2299 then
249 gross 2349 if [ -z $ESCRIPT_NUM_THREADS ]
250     then
251     ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
252     if [ -z $ESCRIPT_NUM_THREADS ]
253     then
254     ESCRIPT_NUM_THREADS=1
255     fi
256     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Number of threads is $ESCRIPT_NUM_THREADS."; fi
257 jfenwick 2299 fi
258 gross 2349 else
259     ESCRIPT_NUM_THREADS=1
260 jfenwick 2299 fi
261 gross 2349 #
262     # Now we compute total number of Processes
263     #
264     (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
265     if [ $? -ne 0 ] #Some compute error
266     then #This could happen if the args were not a number
267     echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."
268     exit 1
269     fi
270     #
271     # Test to ensure people aren't trying to combine interactive and multi-process
272     #
273 gross 2357 if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
274 gross 2349 then
275     echo "Interactive mode cannot be used with more than one process"
276     exit 1
277     fi
278     #=========================================================================================================
279 gross 2350 # Must have at least one command-line arg: the python script
280     if [ $# -eq 0 ]
281     then
282     if [ ! -z $DOBINARY ]
283     then
284     echo "No program to run was specified. Exiting."
285     exit 1
286     fi
287     fi
288    
289     #=========================================================================================================
290 gross 2349 if [ ! -z $DOBINARY ]
291     then
292 gross 2350 EXEC_CMD="$@"
293 gross 2349 else
294 gross 2350 if [ $MPI_FLAVOUR == "none" ]
295 gross 2349 then
296 gross 2350 # Check to see if the python version we were compiled with matches the one of EXEC_CMD
297 gross 2349 # We should only do this check if they are running a python script
298     if [ -f $ESCRIPT_ROOT/lib/pyversion ]
299     then
300     compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
301 gross 2364 intversion=`$PYTHON_CMD -V 2>&1`
302 gross 2349 if [ "$compversion" != "$intversion" ]
303     then
304     echo "Python versions do not match. Escript was compiled for "$compversion"."
305     echo "Current version of Python appears to be "$intversion"."
306     exit 1
307     fi
308     fi
309     if [ ! -z $DOINTERACTIVE ]
310     then
311 gross 2350 EXEC_CMD="$PYTHON_CMD -i $@"
312 gross 2349 else
313 gross 2350 EXEC_CMD="$PYTHON_CMD $@"
314 gross 2349 fi
315 gross 2350 else
316 gross 2357 EXEC_CMD="$PYTHON_MPI $@"
317 gross 2349 fi
318     fi
319 gross 2362 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is \"$EXEC_CMD\"."; fi
320 gross 2349 #===============================================================================================
321     #
322     # now we start to spwan things:
323     #
324 gross 2362 if [ $WITH_OPENMP == "y" ]
325 jfenwick 2332 then
326 gross 2349 export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
327     EXPORT_ENV="$EXPORT_ENV, OMP_NUM_THREADS"
328 jfenwick 2332 fi
329 gross 2362 EXIT_CODE=1
330 gross 2355 #=============== no MPI ===================================
331 gross 2349 if [ $MPI_FLAVOUR == "none" ]
332 jfenwick 2332 then
333 gross 2350 $EXEC_CMD
334 gross 2362 EXIT_CODE=$?
335 gross 2355 #=============== OpenMPI ===================================
336 gross 2349 elif [ $MPI_FLAVOUR == "OPENMPI" ]
337     then
338 gross 2365 if [ ! -z $HOSTFILE ]
339     then
340     HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
341     CMD="mpirun --bynode -np $TOTPROC --host $HOST_LIST $EXEC_CMD"
342     else
343     CMD="mpirun -np $TOTPROC $EXEC_CMD"
344     fi
345     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
346     $CMD
347     EXIT_CODE=$?
348 jfenwick 2332
349 gross 2355 #=============== Intel MPI ===================================
350 gross 2357 elif [ $MPI_FLAVOUR == "INTELMPI" ]
351 gross 2355 then
352 gross 2357 if [ ! -z $HOSTFILE ]
353 gross 2355 then
354 gross 2364 mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE
355 gross 2355 if [ $? -ne 0 ]
356     then
357 gross 2364 echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."
358 gross 2355 exit 1
359     else
360 gross 2364 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi
361 gross 2355 fi
362     fi
363 gross 2364 CMD="mpiexec -perhost $ESCRIPT_NUM_PROCS -envall -n $TOTPROC $EXEC_CMD"
364 gross 2362 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
365 gross 2355 $CMD
366 gross 2362 EXIT_CODE=$?
367 gross 2357 if [ ! -z $HOSTFILE ]
368 gross 2355 then
369     mpdallexit
370     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
371     fi
372     #=============== SGI's MPIMPT ===================================
373 gross 2357 elif [ $MPI_FLAVOUR == "MPT" ]
374 jfenwick 2332 then
375 gross 2349 export MPI_NUM_MEMORY_REGIONS=0
376 gross 2350 EXPORT_ENV="$EXPORT_ENV, MPI_NUM_MEMORY_REGIONS"
377 gross 2357 if [ ! -z $HOSTFILE ]
378 gross 2350 then
379     HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
380 gross 2357 CMD="mpirun $HOST_LIST $ESCRIPT_NUM_PROCS $EXEC_CMD"
381 gross 2350 else
382 gross 2357 CMD="mpirun -np $TOTPROC $EXEC_CMD"
383 gross 2350 fi
384 gross 2362 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
385 gross 2350 $CMD
386 gross 2362 EXIT_CODE=$?
387 gross 2355 #=============== SGI's MPICH ===================================
388 gross 2357 elif [ $MPI_FLAVOUR == "MPICH" ]
389 jfenwick 2332 then
390 gross 2349 echo "MPICH not implemented yet."
391     else
392 gross 2357 echo "unknown MPI falvour $MPI_FLAVOUR."
393 jfenwick 2332 fi
394 gross 2362 exit $EXIT_CODE

  ViewVC Help
Powered by ViewVC 1.1.26