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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2357 - (show annotations)
Wed Apr 1 06:01:56 2009 UTC (10 years, 3 months ago) by gross
File size: 11685 byte(s)
fixes to run escript command with SGI MPT
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_PROCS, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_CREATESTDFILES
19
20 HOSTFILE=/tmp/escript.$$
21
22
23 #Need to match if the name contains /
24 if [[ $0 =~ / ]]
25 then
26 # We are not using the PATH to find the script
27 cd `dirname $0`
28 scriptdir=`pwd`
29 cd $CURDIR
30 else
31 # name does not contain / therefore we are using
32 tscriptdir=`which $0`
33 if [ $? != 0 ]
34 then
35 echo "Error unable to determine script directory. Exiting."
36 exit 1
37 fi
38 scriptdir=`dirname $tscriptdir`
39 fi
40
41 cd $scriptdir/..
42 ESCRIPT_ROOT=`pwd`
43 cd ..
44 ESCRIPT_PARENT=`pwd`
45 cd $CURDIR
46 ##### End finding ESCRIPT_ROOT ########
47
48 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
49 PYTHON_CMD=python
50
51 # if possible please express paths relative to $ESCRIPT_ROOT unless
52 # they are in an unrelated location
53
54 EXTRA_DYLD_LIBRARY_PATH=""
55 EXTRA_PATH=$ESCRIPT_ROOT/bin
56 EXTRA_PYTHONPATH=$ESCRIPT_ROOT
57 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
58
59 if [ $STANDALONE == 1 ]
60 then
61 EXTRA_PATH=$ESCRIPT_PARENT/packages/python/bin:$EXTRA_PATH
62 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/boost/lib:$ESCRIPT_PARENT/packages/netcdf/lib/:$EXTRA_LD_LIBRARY_PATH
63 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/vtk/lib/vtk-5.2:$ESCRIPT_PARENT/packages/mesa/lib:$EXTRA_LD_LIBRARY_PATH
64 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/python/lib:$EXTRA_LD_LIBRARY_PATH
65 EXTRA_PYTHONPATH=$ESCRIPT_PARENT/packages/numarray/lib:$ESCRIPT_PARENT/packages/vtk/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
66 fi
67
68
69
70 HELP_TEXT="
71 Usage: escript [options] script.py [arguments...]
72 -n nn number of nodes to use
73 -p np number of MPI processes to spawn
74 -t nt number of OpenMP threads to use
75 -f file name of MPI hostfile
76 -c print compile information for escript and exit
77 -V print escript version and exit
78 -i interactive mode
79 -b do not invoke python (run non-python programs)
80 -e print export statements for environment and exit
81 -o redirect output from MPI to files
82 -v print diagnostics
83 -x ..reserved for future use ..
84 script.py Your python script
85 arguments... The optional command-line arguments to your script
86 "
87
88 if [ "$1" = "--help" ]; then
89 echo "$HELP_TEXT"
90 exit 0
91 fi
92 #=======================================================================================
93
94 # Avoid bug in hybrid runs with MPT MPI
95
96
97 # Parse the command-line options
98 # option e should not be followed by a :
99 while getopts 'bn:p:t:f:h:ecVviox' option
100 do
101 case "$option" in
102 "b") DOBINARY=yes
103 ;;
104 "n") ESCRIPT_NUM_NODES=$OPTARG
105 ;;
106 "p") ESCRIPT_NUM_PROCS=$OPTARG
107 ;;
108 "t") ESCRIPT_NUM_THREADS=$OPTARG
109 ;;
110 "f") ESCRIPT_HOSTFILE=$OPTARG
111 ;;
112 "c") cat $ESCRIPT_ROOT/lib/buildvars
113 exit 0
114 ;;
115 "V") echo "escript-pre2.0(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"
116 exit 0
117 ;;
118 "h") echo "$HELPTEXT"
119 exit 0
120 ;;
121 "i") DOINTERACTIVE=yes
122 ;;
123 "e") echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
124 echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
125 echo "export PATH=$EXTRA_PATH:\$PATH"
126 if [ `uname` == Darwin ]
127 then
128 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
129 fi
130 exit 0
131 ;;
132 "o") ESCRIPT_CREATESTDFILES="yes"
133 ;;
134 "v") ESCRIPT_VERBOSE="yes"
135 ;;
136 "x") echo "-x not implemented yet"
137 exit 1
138 ;;
139 ?) echo "$HELP_TEXT"
140 exit 1
141 ;;
142 esac
143 done
144 shift `expr $OPTIND - 1`
145 #==============================================
146 #
147 # Read the MPI_FLAVOUR from the buildvars
148 #
149 MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
150
151 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ] && [ $MPI_FLAVOUR == "none" ]
152 then
153 echo "compiled with MPI but no MPI flavour specified."
154 exit 1
155 fi
156
157 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI flavor is $MPI_FLAVOUR."; fi
158 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ];
159 then
160 ESCRIPT_WITH_OPENMP="yes"
161 fi
162 if [ ! -z $ESCRIPT_VERBOSE ] && [ ! -z $ESCRIPT_WITH_OPENMP ]; then echo "OpenMP enbaled."; fi
163 #
164 # extend path variables
165 #
166 export PATH=$EXTRA_PATH:$PATH
167 export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
168 export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
169 EXPORT_ENV="PATH, LD_LIBRARY_PATH, PYTHONPATH"
170 if [ `uname` == Darwin ]
171 then
172 export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
173 EXPORT_ENV="$EXPORT_ENV, DYLD_LIBRARY_PATH"
174 fi
175 if [ ! -z $ESCRIPT_VERBOSE ]
176 then
177 echo "PATH = $PATH "
178 echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
179 echo "PYTHONPATH = $PYTHONPATH "
180 if [ ! -z $DYLD_LIBRARY_PATH ]; then echo "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH "; fi
181 fi
182 set -x
183 #==============================================
184 #
185 # Ensure the variables have sensible values
186 #
187 if [ $MPI_FLAVOUR == "none" ]
188 then
189 if [ ! -z $ESCRIPT_NUM_NODES ]
190 then
191 echo "Warning: MPI disabled but number of nodes set. Option ignored."
192 fi
193 if [ ! -z $ESCRIPT_NUM_PROCS ]
194 then
195 echo "Warning: MPI disabled but number of processors per node set. Option ignored."
196 fi
197 if [ ! -z $ESCRIPT_HOSTFILE ]
198 then
199 echo "Warning: MPI disabled but host file is given. Option ignored."
200 fi
201 ESCRIPT_NUM_NODES=1
202 ESCRIPT_NUM_PROCS=1
203 else
204 if [ ! -z $ESCRIPT_HOSTFILE ]
205 then
206 if [ -f $ESCRIPT_HOSTFILE ]
207 then
208 cat $ESCRIPT_HOSTFILE | sort -u > $HOSTFILE
209 NUM_HOSTS=`cat $HOSTFILE | wc -l`
210 if [ ! -z $ESCRIPT_NUM_NODES ]
211 then
212 if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]
213 then
214 echo "number of hosts selected in the host file $ESCRIPT_HOSTFILE needs to match the requested number of nodes $ESCRIPT_NUM_NODES."
215 exit 1
216 fi
217 else
218 ESCRIPT_NUM_NODES=$NUM_HOSTS
219 fi
220 else
221 echo "cannot find hostfile $ESCRIPT_HOSTFILE."
222 exit 1
223 fi
224 else
225 HOSTFILE=''
226 fi
227
228 if [ -z $ESCRIPT_NUM_NODES ]
229 then
230 ESCRIPT_NUM_NODES=1
231 fi
232
233 if [ -z $ESCRIPT_NUM_PROCS ]
234 then
235 ESCRIPT_NUM_PROCS=1
236 fi
237
238 if [ ! -z $ESCRIPT_VERBOSE ]
239 then
240 echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
241 echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
242 fi
243 fi
244
245 if [ ! -z $ESCRIPT_WITH_OPENMP ]
246 then
247 if [ -z $ESCRIPT_NUM_THREADS ]
248 then
249 ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
250 if [ -z $ESCRIPT_NUM_THREADS ]
251 then
252 ESCRIPT_NUM_THREADS=1
253 fi
254 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Number of threads is $ESCRIPT_NUM_THREADS."; fi
255 fi
256 else
257 ESCRIPT_NUM_THREADS=1
258 fi
259 #
260 # Now we compute total number of Processes
261 #
262 (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
263 if [ $? -ne 0 ] #Some compute error
264 then #This could happen if the args were not a number
265 echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."
266 exit 1
267 fi
268 #
269 # Test to ensure people aren't trying to combine interactive and multi-process
270 #
271 if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
272 then
273 echo "Interactive mode cannot be used with more than one process"
274 exit 1
275 fi
276 #=========================================================================================================
277 # Must have at least one command-line arg: the python script
278 if [ $# -eq 0 ]
279 then
280 if [ ! -z $DOBINARY ]
281 then
282 echo "No program to run was specified. Exiting."
283 exit 1
284 fi
285 fi
286
287 #=========================================================================================================
288 if [ ! -z $DOBINARY ]
289 then
290 EXEC_CMD="$@"
291 else
292 if [ $MPI_FLAVOUR == "none" ]
293 then
294 # Check to see if the python version we were compiled with matches the one of EXEC_CMD
295 # We should only do this check if they are running a python script
296 if [ -f $ESCRIPT_ROOT/lib/pyversion ]
297 then
298 compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
299 intversion=`$PYTHON_CMD --version 2>&1`
300 if [ "$compversion" != "$intversion" ]
301 then
302 echo "Python versions do not match. Escript was compiled for "$compversion"."
303 echo "Current version of Python appears to be "$intversion"."
304 exit 1
305 fi
306 fi
307 if [ ! -z $DOINTERACTIVE ]
308 then
309 EXEC_CMD="$PYTHON_CMD -i $@"
310 else
311 EXEC_CMD="$PYTHON_CMD $@"
312 fi
313 else
314 EXEC_CMD="$PYTHON_MPI $@"
315 fi
316 fi
317 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is $EXEC_CMD."; fi
318 #===============================================================================================
319 #
320 # now we start to spwan things:
321 #
322 if [ ! -z $ESCRIPT_WITH_OPENMP ]
323 then
324 export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
325 EXPORT_ENV="$EXPORT_ENV, OMP_NUM_THREADS"
326 fi
327
328 #=============== no MPI ===================================
329 if [ $MPI_FLAVOUR == "none" ]
330 then
331 $EXEC_CMD
332
333 #=============== OpenMPI ===================================
334 elif [ $MPI_FLAVOUR == "OPENMPI" ]
335 then
336 echo "OPENMPI not implemented yet."
337
338 #=============== Intel MPI ===================================
339 elif [ $MPI_FLAVOUR == "INTELMPI" ]
340 then
341 if [ ! -z $HOSTFILE ]
342 then
343 mpdboot -n $ESCRIPT_NUM_PROCS -r ssh -f $HOSTFILE
344 if [ $? -ne 0 ]
345 then
346 echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_PROCS nodes failed."
347 exit 1
348 else
349 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_PROCS nodes."; fi
350 fi
351 fi
352 $CMD="mpiexec -n $ESCRIPT_NUM_PROCS -perhost $ESCRIPT_NUM_PROCS -envall -$EXEC_CMD"
353 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is $CMD."; fi
354 $CMD
355 if [ ! -z $HOSTFILE ]
356 then
357 mpdallexit
358 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
359 fi
360 #=============== SGI's MPIMPT ===================================
361 elif [ $MPI_FLAVOUR == "MPT" ]
362 then
363 export MPI_NUM_MEMORY_REGIONS=0
364 EXPORT_ENV="$EXPORT_ENV, MPI_NUM_MEMORY_REGIONS"
365 if [ ! -z $HOSTFILE ]
366 then
367 HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
368 CMD="mpirun $HOST_LIST $ESCRIPT_NUM_PROCS $EXEC_CMD"
369 else
370 CMD="mpirun -np $TOTPROC $EXEC_CMD"
371 fi
372 if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is $CMD."; fi
373 $CMD
374 #=============== SGI's MPICH ===================================
375 elif [ $MPI_FLAVOUR == "MPICH" ]
376 then
377 echo "MPICH not implemented yet."
378 else
379 echo "unknown MPI falvour $MPI_FLAVOUR."
380 exit 1
381 fi
382 exit 0
383 # Using OpenMP?
384 #OMP_OPTIONS=''
385 #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
386 # EXEC_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
387 # ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
388 # OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"
389 #fi
390
391 # Using MPI?
392 #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
393 # EXEC_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
394 #else
395 # if [ "$TOTPROC" -ne 1 ]; then
396 # echo "Escript/Finley was not compiled for MPI. You can not use the -n and -p options."
397 # exit 1
398 # fi
399 #fi

  ViewVC Help
Powered by ViewVC 1.1.26