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

Annotation of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2349 - (hide annotations)
Mon Mar 30 08:14:23 2009 UTC (10 years, 5 months ago) by gross
File size: 9362 byte(s)
first version of escript command: no MPI support yet.
1 jfenwick 2299 #!/bin/bash
2 ksteube 1756
3 ksteube 1824 # Escript/Finley wrapper for python
4     # Sets LD_LIBRARY_PATH and PYTHONPATH and then runs either python or the MPI launcher
5    
6 jfenwick 2298 #Extra paths can be configured about a page further down
7     #Search for EXTRA_PATH=""
8 jfenwick 2297
9 jfenwick 2299 #set to 1 if performing this is a standalone build and /packages contains the relevant tools
10     STANDALONE=0
11 jfenwick 2297
12 jfenwick 2296 #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 jfenwick 2332 #Environment vars which control operations:
18 gross 2349 # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROC, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_CREATESTDFILES
19 jfenwick 2332
20    
21 jfenwick 2296 #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 jfenwick 2297 cd $scriptdir/..
40 jfenwick 2296 ESCRIPT_ROOT=`pwd`
41 jfenwick 2299 cd ..
42     ESCRIPT_PARENT=`pwd`
43 jfenwick 2296 cd $CURDIR
44 jfenwick 2298 ##### End finding ESCRIPT_ROOT ########
45    
46 gross 2349 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
47    
48 jfenwick 2298 # if possible please express paths relative to $ESCRIPT_ROOT unless
49     # they are in an unrelated location
50    
51     EXTRA_DYLD_LIBRARY_PATH=""
52 gross 2349 EXTRA_PATH=$ESCRIPT_ROOT/bin
53     EXTRA_PYTHONPATH=$ESCRIPT_ROOT
54     EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
55 jfenwick 2298
56 jfenwick 2299 if [ $STANDALONE == 1 ]
57     then
58 jfenwick 2312 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 jfenwick 2299 fi
64    
65 ksteube 1756
66 jfenwick 2298
67     HELP_TEXT="
68     Usage: escript [options] script.py [arguments...]
69 jfenwick 2332 -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 jfenwick 2343 -b do not invoke python (run non-python programs)
77 jfenwick 2332 -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 jfenwick 2298 script.py Your python script
82 jfenwick 2332 arguments... The optional command-line arguments to your script
83 jfenwick 2298 "
84    
85     if [ "$1" = "--help" ]; then
86     echo "$HELP_TEXT"
87     exit 0
88     fi
89 gross 2349 #=======================================================================================
90 jfenwick 2298
91 ksteube 1909 # Avoid bug in hybrid runs with MPT MPI
92    
93 ksteube 1756
94     # Parse the command-line options
95 jfenwick 2296 # option e should not be followed by a :
96 jfenwick 2343 while getopts 'bn:p:t:f:h:ecVviox' option
97 ksteube 1756 do
98     case "$option" in
99 jfenwick 2343 "b") DOBINARY=yes
100     ;;
101 jfenwick 2332 "n") ESCRIPT_NUM_NODES=$OPTARG
102 ksteube 1756 ;;
103 jfenwick 2332 "p") ESCRIPT_NUM_PROC=$OPTARG
104 ksteube 1756 ;;
105 jfenwick 2332 "t") ESCRIPT_NUM_THREADS=$OPTARG
106 ksteube 1756 ;;
107 jfenwick 2332 "f") ESCRIPT_HOSTFILE=$OPTARG
108 ksteube 1756 ;;
109 jfenwick 2332 "c") cat $ESCRIPT_ROOT/lib/buildvars
110     exit 0
111 ksteube 1756 ;;
112 jfenwick 2332 "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 jfenwick 2298 "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 jfenwick 2296 if [ `uname` == Darwin ]
124     then
125 jfenwick 2298 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
126 jfenwick 2296 fi
127     exit 0
128     ;;
129 gross 2349 "o") ESCRIPT_CREATESTDFILES="yes"
130 jfenwick 2332 ;;
131 gross 2349 "v") ESCRIPT_VERBOSE="yes"
132 jfenwick 2332 ;;
133     "x") echo "-x not implemented yet"
134     exit 1
135     ;;
136 ksteube 1756 ?) echo "$HELP_TEXT"
137     exit 1
138     ;;
139     esac
140     done
141     shift `expr $OPTIND - 1`
142 gross 2349 #==============================================
143     #
144     # Read the MPI_FLAVOUR from the buildvars
145     #
146 jfenwick 2338 MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
147 jfenwick 2332
148 gross 2349 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 jfenwick 2298 export PATH=$EXTRA_PATH:$PATH
164     export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
165     export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
166 gross 2349 EXPORT_ENV="PATH, LD_LIBRARY_PATH, PYTHONPATH"
167 jfenwick 2298 if [ `uname` == Darwin ]
168     then
169     export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
170 gross 2349 EXPORT_ENV="$EXPORT_ENV, DYLD_LIBRARY_PATH"
171 jfenwick 2298 fi
172 gross 2349 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 jfenwick 2343 then
185 gross 2349 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 jfenwick 2343 fi
210 gross 2349 if [ ! -z $ESCRIPT_WITH_OPENMP ]
211 jfenwick 2299 then
212 gross 2349 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 jfenwick 2299 fi
221 gross 2349 else
222     ESCRIPT_NUM_THREADS=1
223 jfenwick 2299 fi
224 gross 2349 #
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 ksteube 1756 # Must have at least one command-line arg: the python script
275 gross 2349 if [ $# -eq 0 ]
276     then
277 jfenwick 2343 if [ ! -z $DOBINARY ]
278     then
279     echo "No program to run was specified. Exiting."
280     exit 1
281     fi
282 ksteube 1756 fi
283 gross 2349 #===============================================================================================
284     #
285     # now we start to spwan things:
286     #
287     if [ ! -z $ESCRIPT_WITH_OPENMP ]
288 jfenwick 2332 then
289 gross 2349 export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
290     EXPORT_ENV="$EXPORT_ENV, OMP_NUM_THREADS"
291 jfenwick 2332 fi
292    
293 gross 2349 if [ $MPI_FLAVOUR == "none" ]
294 jfenwick 2332 then
295 gross 2349 $PYTHON_CMD
296     elif [ $MPI_FLAVOUR == "OPENMPI" ]
297     then
298     echo "OPENMPI not implemented yet."
299 jfenwick 2332
300 gross 2349 elif [ $MPI_FLAVOR == "MLP" ]
301 jfenwick 2332 then
302 gross 2349 export MPI_NUM_MEMORY_REGIONS=0
303     echo "MLP not implemented yet."
304 jfenwick 2332
305 gross 2349 elif [ $MPI_FLAVOR == "MPICH" ]
306 jfenwick 2332 then
307 gross 2349 echo "MPICH not implemented yet."
308     else
309     echo "unknown MPI falvour $MPI_FLAVOR."
310     exit 1
311 jfenwick 2332 fi
312 gross 2349 exit 0
313 ksteube 1756 # Using OpenMP?
314 gross 2349 #OMP_OPTIONS=''
315     #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
316 jfenwick 2102 # PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
317 gross 2349 # ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
318     # OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"
319     #fi
320 ksteube 1756
321     # Using MPI?
322 gross 2349 #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