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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2296 - (show annotations)
Thu Mar 5 05:47:34 2009 UTC (10 years, 7 months ago) by jfenwick
File size: 3281 byte(s)
The escript wrapper now determines ESCRIPT_ROOT based on the position of the 
script rather than the value inserted at compile time.
This is one step towards making binary releases less tied to a known location.

SConstruct now keeps escript root at the front of LD_LIBRARY_PATH and PYTHONPATH

The wrapper script now accepts a -e arguement.
This doesn't actually run anything but outputs a set of exports which one can 
eval to give you the same environment as the wrapper.


1 #!/bin/sh
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 HELP_TEXT="
7 Usage: escript [options] script.py [arguments...]
8 -O N Use N OpenMP threads (OMP_NUM_THREADS=N)
9 -M K Use K MPI processes
10 -l 'launcher' MPI launcher, usually -l 'mpirun -np' or -l 'mpiexec -n'
11 -L /path Prepend /path to library search path
12 -P /path Prepend /path to python module search path
13 -e Print export statements for environment and exit
14 script.py Your python script
15 arguments... The optional command-line arguments to your python script
16 "
17
18 if [ "$1" = "--help" ]; then
19 echo "$HELP_TEXT"
20 exit 0
21 fi
22
23 #Now we find the location of this script
24 #Note that this location should be absolute but does not need to be unique
25 scriptdir=""
26 CURDIR=`pwd`
27
28 #Need to match if the name contains /
29 if [[ $0 =~ / ]]
30 then
31 # We are not using the PATH to find the script
32 cd `dirname $0`
33 scriptdir=`pwd`
34 cd $CURDIR
35 else
36 # name does not contain / therefore we are using
37 tscriptdir=`which $0`
38 if [ $? != 0 ]
39 then
40 echo "Error unable to determine script directory. Exiting."
41 exit 1
42 fi
43 scriptdir=`dirname $tscriptdir`
44 fi
45
46 cd $scriptname/..
47 ESCRIPT_ROOT=`pwd`
48 cd $CURDIR
49
50 PYTHON_CMD="@@PYTHON_CMD@@"
51
52 #ESCRIPT_ROOT="@@ESCRIPT_ROOT@@"
53
54 export PATH="@@PATH@@"
55
56 export LD_LIBRARY_PATH="@@LD_LIBRARY_PATH@@"
57
58 if [ `uname` == Darwin ]
59 then
60 export DYLD_LIBRARY_PATH="@@LD_LIBRARY_PATH@@"
61 fi
62
63 export PYTHONPATH="@@PYTHONPATH@@"
64
65 # Avoid bug in hybrid runs with MPT MPI
66 export MPI_NUM_MEMORY_REGIONS=0
67
68 # Try to guess the MPI launcher (mpirun unless in PBS batch job in which case mpiexec)
69 mpi_launcher='mpirun -np'
70 if [ $?PBS_ENVIRONMENT ]; then
71 if [ "X_$PBS_ENVIRONMENT" = "X_PBS_BATCH" ]; then
72 mpi_launcher='mpiexec -n'
73 fi
74 fi
75
76 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
77 OMP_NUM_THREADS=1
78 MPI_NUM_PROCS=1
79
80 # Parse the command-line options
81 # option e should not be followed by a :
82 while getopts 'L:P:O:M:l:e' option
83 do
84 case "$option" in
85 "L") export LD_LIBRARY_PATH="$OPTARG:$LD_LIBRARY_PATH"
86 ;;
87 "P") export PYTHONPATH="$OPTARG:$PYTHONPATH"
88 ;;
89 "O") OMP_NUM_THREADS="$OPTARG"
90 ;;
91 "M") MPI_NUM_PROCS="$OPTARG"
92 ;;
93 "l") mpi_launcher="$OPTARG"
94 ;;
95 "e") echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
96 echo "export PYTHONPATH=$PYTHONPATH"
97 echo "export PATH=$PATH"
98 if [ `uname` == Darwin ]
99 then
100 echo "export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
101 fi
102 exit 0
103 ;;
104 ?) echo "$HELP_TEXT"
105 exit 1
106 ;;
107 esac
108 done
109 shift `expr $OPTIND - 1`
110
111 # Must have at least one command-line arg: the python script
112 if [ $# -eq 0 ]; then
113 echo "No python script specified. Starting python interpreter."
114 # echo "Missing python script"
115 # echo "$HELP_TEXT"
116 # exit 1
117 fi
118
119 # Using OpenMP?
120 OMP_OPTIONS=''
121 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
122 # PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
123 OMP_OPTIONS="env OMP_NUM_THREADS=$OMP_NUM_THREADS"
124 fi
125
126 # Using MPI?
127 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
128 PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
129 else
130 if [ "$MPI_NUM_PROCS" -ne 1 ]; then
131 echo "Escript/Finley was not compiled for MPI so you must use -M 1"
132 exit 1
133 fi
134 fi
135
136 set -x
137 $OMP_OPTIONS $PYTHON_CMD "$@"
138

  ViewVC Help
Powered by ViewVC 1.1.26