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

Annotation of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2338 - (hide annotations)
Fri Mar 27 05:01:49 2009 UTC (10 years, 5 months ago) by jfenwick
File size: 6448 byte(s)
Added vars for mpi_flavour
Output correct version into the user guide
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     # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROC, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_STDFILES
19    
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    
45 jfenwick 2298 ##### 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 jfenwick 2299 if [ $STANDALONE == 1 ]
56     then
57 jfenwick 2312 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 jfenwick 2299 fi
63    
64 jfenwick 2297 # For stand-alone builds this will need to be changed
65     PYTHON_CMD=python
66 ksteube 1756
67 jfenwick 2298 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 jfenwick 2332 -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     -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 jfenwick 2298 script.py Your python script
85 jfenwick 2332 arguments... The optional command-line arguments to your script
86 jfenwick 2298 "
87    
88     if [ "$1" = "--help" ]; then
89     echo "$HELP_TEXT"
90     exit 0
91     fi
92    
93 jfenwick 2297
94 jfenwick 2299
95 ksteube 1909 # Avoid bug in hybrid runs with MPT MPI
96     export MPI_NUM_MEMORY_REGIONS=0
97    
98 ksteube 1756 # Try to guess the MPI launcher (mpirun unless in PBS batch job in which case mpiexec)
99     mpi_launcher='mpirun -np'
100     if [ $?PBS_ENVIRONMENT ]; then
101     if [ "X_$PBS_ENVIRONMENT" = "X_PBS_BATCH" ]; then
102     mpi_launcher='mpiexec -n'
103     fi
104     fi
105    
106     PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
107     OMP_NUM_THREADS=1
108     MPI_NUM_PROCS=1
109    
110     # Parse the command-line options
111 jfenwick 2296 # option e should not be followed by a :
112 jfenwick 2332 while getopts 'n:p:t:f:h:ecVviox' option
113 ksteube 1756 do
114     case "$option" in
115 jfenwick 2332 "n") ESCRIPT_NUM_NODES=$OPTARG
116 ksteube 1756 ;;
117 jfenwick 2332 "p") ESCRIPT_NUM_PROC=$OPTARG
118 ksteube 1756 ;;
119 jfenwick 2332 "t") ESCRIPT_NUM_THREADS=$OPTARG
120 ksteube 1756 ;;
121 jfenwick 2332 "f") ESCRIPT_HOSTFILE=$OPTARG
122 ksteube 1756 ;;
123 jfenwick 2332 "c") cat $ESCRIPT_ROOT/lib/buildvars
124     exit 0
125 ksteube 1756 ;;
126 jfenwick 2332 "V") echo "escript-pre2.0(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"
127     exit 0
128     ;;
129     "h") echo "$HELPTEXT"
130     exit 0
131     ;;
132     "i") DOINTERACTIVE=yes
133     ;;
134 jfenwick 2298 "e") echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
135     echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
136     echo "export PATH=$EXTRA_PATH:\$PATH"
137 jfenwick 2296 if [ `uname` == Darwin ]
138     then
139 jfenwick 2298 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
140 jfenwick 2296 fi
141     exit 0
142     ;;
143 jfenwick 2332 "o") ESCRIPT_STDFILES="yes"
144     ;;
145     "v") echo "Diagnostics:"
146     exit 0
147     ;;
148     "x") echo "-x not implemented yet"
149     exit 1
150     ;;
151 ksteube 1756 ?) echo "$HELP_TEXT"
152     exit 1
153     ;;
154     esac
155     done
156     shift `expr $OPTIND - 1`
157    
158 jfenwick 2338 #Read the MPI_FLAVOUR from the buildvars
159     MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
160 jfenwick 2332
161 jfenwick 2298 export PATH=$EXTRA_PATH:$PATH
162     export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
163     export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
164     if [ `uname` == Darwin ]
165     then
166     export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
167     fi
168    
169 jfenwick 2299 # Check to see if the python version we were compiled with matches the one of PYTHON_CMD
170     if [ -f $ESCRIPT_ROOT/lib/pyversion ]
171     then
172     compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
173     intversion=`python --version 2>&1`
174     if [ "$compversion" != "$intversion" ]
175     then
176     echo "Python versions do not match. Escript was compiled for "$compversion"."
177     echo "Current version of Python appears to be "$intversion"."
178     exit 1
179     fi
180     fi
181 jfenwick 2298
182 ksteube 1756 # Must have at least one command-line arg: the python script
183     if [ $# -eq 0 ]; then
184 jfenwick 2294 echo "No python script specified. Starting python interpreter."
185 ksteube 1756 fi
186    
187 jfenwick 2332 #Ensure the variables have sensible values
188     if [ -z $ESCRIPT_NUM_NODES ]
189     then
190     ESCRIPT_NUM_NODES=1
191     fi
192    
193     if [ -z $ESCRIPT_NUM_PROCS ]
194     then
195     ESCRIPT_NUM_PROCS=1
196     fi
197    
198     if [ -z $ESCRIPT_NUM_THREADS ]
199     then
200     ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
201     if [ -z $ESCRIPT_NUM_THREADS ]
202     then
203     ESCRIPT_NUM_THREADS=1
204     fi
205     fi
206    
207     #Now we compute total number of Processes
208     (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
209     if [ $? -ne 0 ] #Some compute error
210     then #This could happen if the args were not a number
211     ESCRIPT_NUM_NODES=1
212     ESCRIPT_NUM_PROCS=1
213     fi
214    
215     # Test to ensure people aren't trying to combine interactive and multi-process
216    
217     if [[ ( ( -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
218     then
219     echo "Interactive mode cannot be used with more than one process"
220     exit 1
221     fi
222    
223 ksteube 1756 # Using OpenMP?
224     OMP_OPTIONS=''
225     if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
226 jfenwick 2102 # PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
227 jfenwick 2332 OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"
228 ksteube 1756 fi
229    
230     # Using MPI?
231     if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
232     PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
233 ksteube 1912 else
234 jfenwick 2332 if [ "$TOTPROC" -ne 1 ]; then
235     echo "Escript/Finley was not compiled for MPI. You can not use the -n and -p options."
236 ksteube 1912 exit 1
237     fi
238 ksteube 1756 fi
239    
240     set -x
241 ksteube 2110 $OMP_OPTIONS $PYTHON_CMD "$@"
242 ksteube 1756

  ViewVC Help
Powered by ViewVC 1.1.26