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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2343 - (show annotations)
Mon Mar 30 01:34:45 2009 UTC (10 years, 5 months ago) by jfenwick
File size: 6784 byte(s)
Added -b option to wrapper script. For the running of non-python 
binaries.

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 #Now we find the location of this script
13 #Note that this location should be absolute but does not need to be unique
14 scriptdir=""
15 CURDIR=`pwd`
16
17 #Environment vars which control operations:
18 # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROC, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_STDFILES
19
20
21 #Need to match if the name contains /
22 if [[ $0 =~ / ]]
23 then
24 # We are not using the PATH to find the script
25 cd `dirname $0`
26 scriptdir=`pwd`
27 cd $CURDIR
28 else
29 # name does not contain / therefore we are using
30 tscriptdir=`which $0`
31 if [ $? != 0 ]
32 then
33 echo "Error unable to determine script directory. Exiting."
34 exit 1
35 fi
36 scriptdir=`dirname $tscriptdir`
37 fi
38
39 cd $scriptdir/..
40 ESCRIPT_ROOT=`pwd`
41 cd ..
42 ESCRIPT_PARENT=`pwd`
43 cd $CURDIR
44
45 ##### End finding ESCRIPT_ROOT ########
46
47 # if possible please express paths relative to $ESCRIPT_ROOT unless
48 # they are in an unrelated location
49
50 EXTRA_PATH=""
51 EXTRA_LD_LIBRARY_PATH=""
52 EXTRA_DYLD_LIBRARY_PATH=""
53 EXTRA_PYTHONPATH=""
54
55 if [ $STANDALONE == 1 ]
56 then
57 EXTRA_PATH=$ESCRIPT_PARENT/packages/python/bin:$EXTRA_PATH
58 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/boost/lib:$ESCRIPT_PARENT/packages/netcdf/lib/:$EXTRA_LD_LIBRARY_PATH
59 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/vtk/lib/vtk-5.2:$ESCRIPT_PARENT/packages/mesa/lib:$EXTRA_LD_LIBRARY_PATH
60 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/python/lib:$EXTRA_LD_LIBRARY_PATH
61 EXTRA_PYTHONPATH=$ESCRIPT_PARENT/packages/numarray/lib:$ESCRIPT_PARENT/packages/vtk/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
62 fi
63
64 # For stand-alone builds this will need to be changed
65 PYTHON_CMD=python
66
67 EXTRA_PYTHONPATH=$ESCRIPT_ROOT:$EXTRA_PYTHONPATH
68 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib:$EXTRA_LD_LIBRARY_PATH
69
70
71 HELP_TEXT="
72 Usage: escript [options] script.py [arguments...]
73 -n nn number of nodes to use
74 -p np number of MPI processes to spawn
75 -t nt number of OpenMP threads to use
76 -f file name of MPI hostfile
77 -c print compile information for escript and exit
78 -V print escript version and exit
79 -i interactive mode
80 -b do not invoke python (run non-python programs)
81 -e print export statements for environment and exit
82 -o redirect output from MPI to files
83 -v print diagnostics
84 -x ..reserved for future use ..
85 script.py Your python script
86 arguments... The optional command-line arguments to your script
87 "
88
89 if [ "$1" = "--help" ]; then
90 echo "$HELP_TEXT"
91 exit 0
92 fi
93
94
95
96 # Avoid bug in hybrid runs with MPT MPI
97 export MPI_NUM_MEMORY_REGIONS=0
98
99 # Try to guess the MPI launcher (mpirun unless in PBS batch job in which case mpiexec)
100 mpi_launcher='mpirun -np'
101 if [ $?PBS_ENVIRONMENT ]; then
102 if [ "X_$PBS_ENVIRONMENT" = "X_PBS_BATCH" ]; then
103 mpi_launcher='mpiexec -n'
104 fi
105 fi
106
107 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
108 OMP_NUM_THREADS=1
109 MPI_NUM_PROCS=1
110
111 # Parse the command-line options
112 # option e should not be followed by a :
113 while getopts 'bn:p:t:f:h:ecVviox' option
114 do
115 case "$option" in
116 "b") DOBINARY=yes
117 ;;
118 "n") ESCRIPT_NUM_NODES=$OPTARG
119 ;;
120 "p") ESCRIPT_NUM_PROC=$OPTARG
121 ;;
122 "t") ESCRIPT_NUM_THREADS=$OPTARG
123 ;;
124 "f") ESCRIPT_HOSTFILE=$OPTARG
125 ;;
126 "c") cat $ESCRIPT_ROOT/lib/buildvars
127 exit 0
128 ;;
129 "V") echo "escript-pre2.0(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"
130 exit 0
131 ;;
132 "h") echo "$HELPTEXT"
133 exit 0
134 ;;
135 "i") DOINTERACTIVE=yes
136 ;;
137 "e") echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
138 echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
139 echo "export PATH=$EXTRA_PATH:\$PATH"
140 if [ `uname` == Darwin ]
141 then
142 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
143 fi
144 exit 0
145 ;;
146 "o") ESCRIPT_STDFILES="yes"
147 ;;
148 "v") echo "Diagnostics:"
149 exit 0
150 ;;
151 "x") echo "-x not implemented yet"
152 exit 1
153 ;;
154 ?) echo "$HELP_TEXT"
155 exit 1
156 ;;
157 esac
158 done
159 shift `expr $OPTIND - 1`
160
161 #Read the MPI_FLAVOUR from the buildvars
162 MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
163
164 export PATH=$EXTRA_PATH:$PATH
165 export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
166 export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
167 if [ `uname` == Darwin ]
168 then
169 export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
170 fi
171
172 if [ ! -z $DOBINARY ]
173 then
174 PYTHON_CMD=''
175 fi
176
177
178 # Check to see if the python version we were compiled with matches the one of PYTHON_CMD
179 # We should only do this check if they are running a python script
180 if [[ (! -z $PYTHON_CMD ) && -f $ESCRIPT_ROOT/lib/pyversion ]]
181 then
182 compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
183 intversion=`$PYTHON_CMD --version 2>&1`
184 if [ "$compversion" != "$intversion" ]
185 then
186 echo "Python versions do not match. Escript was compiled for "$compversion"."
187 echo "Current version of Python appears to be "$intversion"."
188 exit 1
189 fi
190 fi
191
192 # Must have at least one command-line arg: the python script
193 if [ $# -eq 0 ]; then
194 if [ ! -z $DOBINARY ]
195 then
196 echo "No program to run was specified. Exiting."
197 exit 1
198 else
199 echo "No python script specified. Starting python interpreter."
200 fi
201 fi
202
203 #Ensure the variables have sensible values
204 if [ -z $ESCRIPT_NUM_NODES ]
205 then
206 ESCRIPT_NUM_NODES=1
207 fi
208
209 if [ -z $ESCRIPT_NUM_PROCS ]
210 then
211 ESCRIPT_NUM_PROCS=1
212 fi
213
214 if [ -z $ESCRIPT_NUM_THREADS ]
215 then
216 ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
217 if [ -z $ESCRIPT_NUM_THREADS ]
218 then
219 ESCRIPT_NUM_THREADS=1
220 fi
221 fi
222
223 #Now we compute total number of Processes
224 (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
225 if [ $? -ne 0 ] #Some compute error
226 then #This could happen if the args were not a number
227 ESCRIPT_NUM_NODES=1
228 ESCRIPT_NUM_PROCS=1
229 fi
230
231 # Test to ensure people aren't trying to combine interactive and multi-process
232
233 if [[ ( ( -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
234 then
235 echo "Interactive mode cannot be used with more than one process"
236 exit 1
237 fi
238
239 # Using OpenMP?
240 OMP_OPTIONS=''
241 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
242 # PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
243 OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"
244 fi
245
246 # Using MPI?
247 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
248 PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
249 else
250 if [ "$TOTPROC" -ne 1 ]; then
251 echo "Escript/Finley was not compiled for MPI. You can not use the -n and -p options."
252 exit 1
253 fi
254 fi
255
256 set -x
257 $OMP_OPTIONS $PYTHON_CMD "$@"
258

  ViewVC Help
Powered by ViewVC 1.1.26