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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2349 - (show annotations)
Mon Mar 30 08:14:23 2009 UTC (13 years, 6 months ago) by gross
File size: 9362 byte(s)
first version of escript command: no MPI support yet.
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_CREATESTDFILES
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 ##### End finding ESCRIPT_ROOT ########
45
46 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
47
48 # if possible please express paths relative to $ESCRIPT_ROOT unless
49 # they are in an unrelated location
50
51 EXTRA_DYLD_LIBRARY_PATH=""
52 EXTRA_PATH=$ESCRIPT_ROOT/bin
53 EXTRA_PYTHONPATH=$ESCRIPT_ROOT
54 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
55
56 if [ $STANDALONE == 1 ]
57 then
58 EXTRA_PATH=$ESCRIPT_PARENT/packages/python/bin:$EXTRA_PATH
59 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/boost/lib:$ESCRIPT_PARENT/packages/netcdf/lib/:$EXTRA_LD_LIBRARY_PATH
60 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/vtk/lib/vtk-5.2:$ESCRIPT_PARENT/packages/mesa/lib:$EXTRA_LD_LIBRARY_PATH
61 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/python/lib:$EXTRA_LD_LIBRARY_PATH
62 EXTRA_PYTHONPATH=$ESCRIPT_PARENT/packages/numarray/lib:$ESCRIPT_PARENT/packages/vtk/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
63 fi
64
65
66
67 HELP_TEXT="
68 Usage: escript [options] script.py [arguments...]
69 -n nn number of nodes to use
70 -p np number of MPI processes to spawn
71 -t nt number of OpenMP threads to use
72 -f file name of MPI hostfile
73 -c print compile information for escript and exit
74 -V print escript version and exit
75 -i interactive mode
76 -b do not invoke python (run non-python programs)
77 -e print export statements for environment and exit
78 -o redirect output from MPI to files
79 -v print diagnostics
80 -x ..reserved for future use ..
81 script.py Your python script
82 arguments... The optional command-line arguments to your script
83 "
84
85 if [ "$1" = "--help" ]; then
86 echo "$HELP_TEXT"
87 exit 0
88 fi
89 #=======================================================================================
90
91 # Avoid bug in hybrid runs with MPT MPI
92
93
94 # Parse the command-line options
95 # option e should not be followed by a :
96 while getopts 'bn:p:t:f:h:ecVviox' option
97 do
98 case "$option" in
99 "b") DOBINARY=yes
100 ;;
101 "n") ESCRIPT_NUM_NODES=$OPTARG
102 ;;
103 "p") ESCRIPT_NUM_PROC=$OPTARG
104 ;;
105 "t") ESCRIPT_NUM_THREADS=$OPTARG
106 ;;
107 "f") ESCRIPT_HOSTFILE=$OPTARG
108 ;;
109 "c") cat $ESCRIPT_ROOT/lib/buildvars
110 exit 0
111 ;;
112 "V") echo "escript-pre2.0(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"
113 exit 0
114 ;;
115 "h") echo "$HELPTEXT"
116 exit 0
117 ;;
118 "i") DOINTERACTIVE=yes
119 ;;
120 "e") echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
121 echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
122 echo "export PATH=$EXTRA_PATH:\$PATH"
123 if [ `uname` == Darwin ]
124 then
125 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
126 fi
127 exit 0
128 ;;
129 "o") ESCRIPT_CREATESTDFILES="yes"
130 ;;
131 "v") ESCRIPT_VERBOSE="yes"
132 ;;
133 "x") echo "-x not implemented yet"
134 exit 1
135 ;;
136 ?) echo "$HELP_TEXT"
137 exit 1
138 ;;
139 esac
140 done
141 shift `expr $OPTIND - 1`
142 #==============================================
143 #
144 # Read the MPI_FLAVOUR from the buildvars
145 #
146 MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
147
148 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ] && [ $MPI_FLAVOUR == "none" ]
149 then
150 echo "compiled with MPI but no MPI flavour specified."
151 exit 1
152 fi
153
154 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI flavor is $MPI_FLAVOUR."; fi
155 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ];
156 then
157 ESCRIPT_WITH_OPENMP="yes"
158 fi
159 if [ ! -z $ESCRIPT_VERBOSE ] && [ ! -z $ESCRIPT_WITH_OPENMP ]; then echo "OpenMP enbaled."; fi
160 #
161 # extend path variables
162 #
163 export PATH=$EXTRA_PATH:$PATH
164 export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
165 export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
166 EXPORT_ENV="PATH, LD_LIBRARY_PATH, PYTHONPATH"
167 if [ `uname` == Darwin ]
168 then
169 export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
170 EXPORT_ENV="$EXPORT_ENV, DYLD_LIBRARY_PATH"
171 fi
172 if [ ! -z $ESCRIPT_VERBOSE ]
173 then
174 echo "PATH = $PATH "
175 echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
176 echo "PYTHONPATH = $PYTHONPATH "
177 if [ ! -z $DYLD_LIBRARY_PATH ]; then echo "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH "; fi
178 fi
179 #==============================================
180 #
181 # Ensure the variables have sensible values
182 #
183 if [ $MPI_FLAVOUR == "none" ]
184 then
185 if [ ! -z $ESCRIPT_NUM_NODES ]
186 then
187 echo "Warning: MPI disabled but number of nodes set. Option ignored."
188 fi
189 if [ ! -z $ESCRIPT_NUM_PROCS ]
190 then
191 echo "Warning: MPI disabled but number of processors per node set. Option ignored."
192 fi
193 ESCRIPT_NUM_NODES=1
194 ESCRIPT_NUM_PROCS=1
195 else
196 if [ -z $ESCRIPT_NUM_NODES ]
197 then
198 ESCRIPT_NUM_NODES=1
199 fi
200 if [ -z $ESCRIPT_NUM_PROCS ]
201 then
202 ESCRIPT_NUM_PROCS=1
203 fi
204 if [ ! -z $ESCRIPT_VERBOSE ]
205 then
206 echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
207 echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
208 fi
209 fi
210 if [ ! -z $ESCRIPT_WITH_OPENMP ]
211 then
212 if [ -z $ESCRIPT_NUM_THREADS ]
213 then
214 ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
215 if [ -z $ESCRIPT_NUM_THREADS ]
216 then
217 ESCRIPT_NUM_THREADS=1
218 fi
219 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Number of threads is $ESCRIPT_NUM_THREADS."; fi
220 fi
221 else
222 ESCRIPT_NUM_THREADS=1
223 fi
224 #
225 # Now we compute total number of Processes
226 #
227 (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
228 if [ $? -ne 0 ] #Some compute error
229 then #This could happen if the args were not a number
230 echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."
231 exit 1
232 fi
233 #
234 # Test to ensure people aren't trying to combine interactive and multi-process
235 #
236 if [[ ( ( -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
237 then
238 echo "Interactive mode cannot be used with more than one process"
239 exit 1
240 fi
241 #=========================================================================================================
242 if [ ! -z $DOBINARY ]
243 then
244 PYTHON_CMD=""
245 else
246 PYTHON_CMD=python
247 if [ $TOTPROC -gt 1 ]
248 then
249 PYTHON_CMD="$PYTHONMPI $@"
250 else
251 # Check to see if the python version we were compiled with matches the one of PYTHON_CMD
252 # We should only do this check if they are running a python script
253 if [ -f $ESCRIPT_ROOT/lib/pyversion ]
254 then
255 compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
256 intversion=`$PYTHON_CMD --version 2>&1`
257 if [ "$compversion" != "$intversion" ]
258 then
259 echo "Python versions do not match. Escript was compiled for "$compversion"."
260 echo "Current version of Python appears to be "$intversion"."
261 exit 1
262 fi
263 fi
264 if [ ! -z $DOINTERACTIVE ]
265 then
266 PYTHON_CMD="python -i $@"
267 else
268 PYTHON_CMD="python $@"
269 fi
270 fi
271 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Python command is $PYTHON_CMD."; fi
272 fi
273 #=========================================================================================================
274 # Must have at least one command-line arg: the python script
275 if [ $# -eq 0 ]
276 then
277 if [ ! -z $DOBINARY ]
278 then
279 echo "No program to run was specified. Exiting."
280 exit 1
281 fi
282 fi
283 #===============================================================================================
284 #
285 # now we start to spwan things:
286 #
287 if [ ! -z $ESCRIPT_WITH_OPENMP ]
288 then
289 export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
290 EXPORT_ENV="$EXPORT_ENV, OMP_NUM_THREADS"
291 fi
292
293 if [ $MPI_FLAVOUR == "none" ]
294 then
295 $PYTHON_CMD
296 elif [ $MPI_FLAVOUR == "OPENMPI" ]
297 then
298 echo "OPENMPI not implemented yet."
299
300 elif [ $MPI_FLAVOR == "MLP" ]
301 then
302 export MPI_NUM_MEMORY_REGIONS=0
303 echo "MLP not implemented yet."
304
305 elif [ $MPI_FLAVOR == "MPICH" ]
306 then
307 echo "MPICH not implemented yet."
308 else
309 echo "unknown MPI falvour $MPI_FLAVOR."
310 exit 1
311 fi
312 exit 0
313 # Using OpenMP?
314 #OMP_OPTIONS=''
315 #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
316 # PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
317 # ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
318 # OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"
319 #fi
320
321 # Using MPI?
322 #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
323 # PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
324 #else
325 # if [ "$TOTPROC" -ne 1 ]; then
326 # echo "Escript/Finley was not compiled for MPI. You can not use the -n and -p options."
327 # exit 1
328 # fi
329 #fi

  ViewVC Help
Powered by ViewVC 1.1.26