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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2359 - (show 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 #!/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 #set to 1 if performing this is a standalone build and /packages contains the relevant tools
10 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
27 #Begin finding ESCRIPT_ROOT
28 if [ $STDLOCATION != 0 ]
29 then
30 ESCRIPT_ROOT=/usr/lib/escript
31 else
32 #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 fi
58 ##### End finding ESCRIPT_ROOT ########
59
60 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
61 PYTHON_CMD=python
62
63 # if possible please express paths relative to $ESCRIPT_ROOT unless
64 # they are in an unrelated location
65
66 EXTRA_DYLD_LIBRARY_PATH=""
67 EXTRA_PATH=$ESCRIPT_ROOT/bin
68 EXTRA_PYTHONPATH=$ESCRIPT_ROOT
69 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
70
71 if [ $STANDALONE == 1 ]
72 then
73 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 fi
79
80
81
82 HELP_TEXT="
83 Usage: escript [options] script.py [arguments...]
84 -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 -b do not invoke python (run non-python programs)
92 -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 script.py Your python script
97 arguments... The optional command-line arguments to your script
98 "
99
100 if [ "$1" = "--help" ]; then
101 echo "$HELP_TEXT"
102 exit 0
103 fi
104 #=======================================================================================
105
106 # Avoid bug in hybrid runs with MPT MPI
107
108
109 # Parse the command-line options
110 # option e should not be followed by a :
111 while getopts 'bn:p:t:f:h:ecVviox' option
112 do
113 case "$option" in
114 "b") DOBINARY=yes
115 ;;
116 "n") ESCRIPT_NUM_NODES=$OPTARG
117 ;;
118 "p") ESCRIPT_NUM_PROCS=$OPTARG
119 ;;
120 "t") ESCRIPT_NUM_THREADS=$OPTARG
121 ;;
122 "f") ESCRIPT_HOSTFILE=$OPTARG
123 ;;
124 "c") cat $ESCRIPT_ROOT/lib/buildvars
125 exit 0
126 ;;
127 "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 "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 if [ `uname` == Darwin ]
139 then
140 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
141 fi
142 exit 0
143 ;;
144 "o") ESCRIPT_CREATESTDFILES="yes"
145 ;;
146 "v") ESCRIPT_VERBOSE="yes"
147 ;;
148 "x") echo "-x not implemented yet"
149 exit 1
150 ;;
151 ?) echo "$HELP_TEXT"
152 exit 1
153 ;;
154 esac
155 done
156 shift `expr $OPTIND - 1`
157 #==============================================
158 #
159 # Read the MPI_FLAVOUR from the buildvars
160 #
161 MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
162
163 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 if [ ! -z $ESCRIPT_VERBOSE ] && [ ! -z $ESCRIPT_WITH_OPENMP ]; then echo "OpenMP enabled."; fi
175 #
176 # extend path variables
177 #
178 export PATH=$EXTRA_PATH:$PATH
179 export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
180 export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
181 EXPORT_ENV="PATH, LD_LIBRARY_PATH, PYTHONPATH"
182 if [ `uname` == Darwin ]
183 then
184 export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
185 EXPORT_ENV="$EXPORT_ENV, DYLD_LIBRARY_PATH"
186 fi
187 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 then
200 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 if [ ! -z $ESCRIPT_HOSTFILE ]
209 then
210 echo "Warning: MPI disabled but host file is given. Option ignored."
211 fi
212 ESCRIPT_NUM_NODES=1
213 ESCRIPT_NUM_PROCS=1
214 else
215 if [ ! -z $ESCRIPT_HOSTFILE ]
216 then
217 if [ -f $ESCRIPT_HOSTFILE ]
218 then
219 cat $ESCRIPT_HOSTFILE | sort -u > $HOSTFILE
220 NUM_HOSTS=`cat $HOSTFILE | wc -l`
221 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 ESCRIPT_NUM_NODES=$NUM_HOSTS
230 fi
231 else
232 echo "cannot find hostfile $ESCRIPT_HOSTFILE."
233 exit 1
234 fi
235 else
236 HOSTFILE=''
237 fi
238
239 if [ -z $ESCRIPT_NUM_NODES ]
240 then
241 ESCRIPT_NUM_NODES=1
242 fi
243
244 if [ -z $ESCRIPT_NUM_PROCS ]
245 then
246 ESCRIPT_NUM_PROCS=1
247 fi
248
249 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 fi
255
256 if [ ! -z $ESCRIPT_WITH_OPENMP ]
257 then
258 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 fi
267 else
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 # Test to ensure people aren't trying to combine interactive and multi-process
281 #
282 if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
283 then
284 echo "Interactive mode cannot be used with more than one process"
285 exit 1
286 fi
287 #=========================================================================================================
288 # 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 if [ ! -z $DOBINARY ]
300 then
301 EXEC_CMD="$@"
302 else
303 if [ $MPI_FLAVOUR == "none" ]
304 then
305 # Check to see if the python version we were compiled with matches the one of EXEC_CMD
306 # 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 EXEC_CMD="$PYTHON_CMD -i $@"
321 else
322 EXEC_CMD="$PYTHON_CMD $@"
323 fi
324 else
325 EXEC_CMD="$PYTHON_MPI $@"
326 fi
327 fi
328 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is $EXEC_CMD."; fi
329 #===============================================================================================
330 #
331 # now we start to spwan things:
332 #
333 if [ ! -z $ESCRIPT_WITH_OPENMP ]
334 then
335 export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
336 EXPORT_ENV="$EXPORT_ENV, OMP_NUM_THREADS"
337 fi
338
339 #=============== no MPI ===================================
340 if [ $MPI_FLAVOUR == "none" ]
341 then
342 echo $EXEC_CMD
343 $EXEC_CMD
344
345 #=============== OpenMPI ===================================
346 elif [ $MPI_FLAVOUR == "OPENMPI" ]
347 then
348 echo "OPENMPI not implemented yet."
349
350 #=============== Intel MPI ===================================
351 elif [ $MPI_FLAVOUR == "INTELMPI" ]
352 then
353 if [ ! -z $HOSTFILE ]
354 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 echo $CMD
367 $CMD
368 if [ ! -z $HOSTFILE ]
369 then
370 mpdallexit
371 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
372 fi
373 #=============== SGI's MPIMPT ===================================
374 elif [ $MPI_FLAVOUR == "MPT" ]
375 then
376 export MPI_NUM_MEMORY_REGIONS=0
377 EXPORT_ENV="$EXPORT_ENV, MPI_NUM_MEMORY_REGIONS"
378 if [ ! -z $HOSTFILE ]
379 then
380 HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
381 CMD="mpirun $HOST_LIST $ESCRIPT_NUM_PROCS $EXEC_CMD"
382 else
383 CMD="mpirun -np $TOTPROC $EXEC_CMD"
384 fi
385 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is $CMD."; fi
386 echo $CMD
387 $CMD
388 #=============== SGI's MPICH ===================================
389 elif [ $MPI_FLAVOUR == "MPICH" ]
390 then
391 echo "MPICH not implemented yet."
392 else
393 echo "unknown MPI falvour $MPI_FLAVOUR."
394 exit 1
395 fi
396 exit 0
397 # Using OpenMP?
398 #OMP_OPTIONS=''
399 #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
400 # EXEC_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
401 # ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
402 # OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"
403 #fi
404
405 # Using MPI?
406 #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
407 # EXEC_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
408 #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