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

Contents of /trunk/bin/run-escript

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3096 - (show annotations)
Thu Aug 19 01:40:52 2010 UTC (9 years, 2 months ago) by caltinay
File size: 14998 byte(s)
-New VisIt simulation control interface in weipa (uses VisIt's simv2)
-Rewrote restarts.py to be a more generic data manager for restarts and exports
-Removed weipa python file since the functionality is now handled by restarts.py

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

Properties

Name Value
svn:executable *
svn:mergeinfo /branches/lapack2681/bin/escript:2682-2741 /branches/restext/bin/escript:2610-2624 /branches/stage3.0/bin/escript:2569-2590 /release/3.0/bin/escript:2591-2601

  ViewVC Help
Powered by ViewVC 1.1.26