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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2312 - (show annotations)
Tue Mar 17 01:42:02 2009 UTC (12 years, 3 months ago) by jfenwick
File size: 5059 byte(s)
Made the standalone setup a bit more generic.

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 #Need to match if the name contains /
18 if [[ $0 =~ / ]]
19 then
20 # We are not using the PATH to find the script
21 cd `dirname $0`
22 scriptdir=`pwd`
23 cd $CURDIR
24 else
25 # name does not contain / therefore we are using
26 tscriptdir=`which $0`
27 if [ $? != 0 ]
28 then
29 echo "Error unable to determine script directory. Exiting."
30 exit 1
31 fi
32 scriptdir=`dirname $tscriptdir`
33 fi
34
35 cd $scriptdir/..
36 ESCRIPT_ROOT=`pwd`
37 cd ..
38 ESCRIPT_PARENT=`pwd`
39 cd $CURDIR
40
41 ##### End finding ESCRIPT_ROOT ########
42
43 # if possible please express paths relative to $ESCRIPT_ROOT unless
44 # they are in an unrelated location
45
46 EXTRA_PATH=""
47 EXTRA_LD_LIBRARY_PATH=""
48 EXTRA_DYLD_LIBRARY_PATH=""
49 EXTRA_PYTHONPATH=""
50
51 if [ $STANDALONE == 1 ]
52 then
53 EXTRA_PATH=$ESCRIPT_PARENT/packages/python/bin:$EXTRA_PATH
54 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/boost/lib:$ESCRIPT_PARENT/packages/netcdf/lib/:$EXTRA_LD_LIBRARY_PATH
55 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/vtk/lib/vtk-5.2:$ESCRIPT_PARENT/packages/mesa/lib:$EXTRA_LD_LIBRARY_PATH
56 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/packages/python/lib:$EXTRA_LD_LIBRARY_PATH
57 EXTRA_PYTHONPATH=$ESCRIPT_PARENT/packages/numarray/lib:$ESCRIPT_PARENT/packages/vtk/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
58 fi
59
60 # For stand-alone builds this will need to be changed
61 PYTHON_CMD=python
62
63 EXTRA_PYTHONPATH=$ESCRIPT_ROOT:$EXTRA_PYTHONPATH
64 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib:$EXTRA_LD_LIBRARY_PATH
65
66
67 HELP_TEXT="
68 Usage: escript [options] script.py [arguments...]
69 -O N Use N OpenMP threads (OMP_NUM_THREADS=N)
70 -M K Use K MPI processes
71 -l 'launcher' MPI launcher, usually -l 'mpirun -np' or -l 'mpiexec -n'
72 -L /path Prepend /path to library search path
73 -P /path Prepend /path to python module search path
74 -e Print export statements for environment and exit
75 script.py Your python script
76 arguments... The optional command-line arguments to your python script
77 "
78
79 if [ "$1" = "--help" ]; then
80 echo "$HELP_TEXT"
81 exit 0
82 fi
83
84
85
86 # Avoid bug in hybrid runs with MPT MPI
87 export MPI_NUM_MEMORY_REGIONS=0
88
89 # Try to guess the MPI launcher (mpirun unless in PBS batch job in which case mpiexec)
90 mpi_launcher='mpirun -np'
91 if [ $?PBS_ENVIRONMENT ]; then
92 if [ "X_$PBS_ENVIRONMENT" = "X_PBS_BATCH" ]; then
93 mpi_launcher='mpiexec -n'
94 fi
95 fi
96
97 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
98 OMP_NUM_THREADS=1
99 MPI_NUM_PROCS=1
100
101 # Parse the command-line options
102 # option e should not be followed by a :
103 while getopts 'L:P:O:M:l:e' option
104 do
105 case "$option" in
106 "L") EXTRA_LD_LIBRARY_PATH="$OPTARG:$EXTRA_LD_LIBRARY_PATH"
107 ;;
108 "P") EXTRA_PYTHONPATH="$OPTARG:$EXTRA_PYTHONPATH"
109 ;;
110 "O") OMP_NUM_THREADS="$OPTARG"
111 ;;
112 "M") MPI_NUM_PROCS="$OPTARG"
113 ;;
114 "l") mpi_launcher="$OPTARG"
115 ;;
116 "e") echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
117 echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
118 echo "export PATH=$EXTRA_PATH:\$PATH"
119 if [ `uname` == Darwin ]
120 then
121 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
122 fi
123 exit 0
124 ;;
125 ?) echo "$HELP_TEXT"
126 exit 1
127 ;;
128 esac
129 done
130 shift `expr $OPTIND - 1`
131
132 export PATH=$EXTRA_PATH:$PATH
133 export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
134 export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
135 if [ `uname` == Darwin ]
136 then
137 export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
138 fi
139
140 # Check to see if the python version we were compiled with matches the one of PYTHON_CMD
141 if [ -f $ESCRIPT_ROOT/lib/pyversion ]
142 then
143 compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
144 intversion=`python --version 2>&1`
145 if [ "$compversion" != "$intversion" ]
146 then
147 echo "Python versions do not match. Escript was compiled for "$compversion"."
148 echo "Current version of Python appears to be "$intversion"."
149 exit 1
150 fi
151 fi
152
153 # Must have at least one command-line arg: the python script
154 if [ $# -eq 0 ]; then
155 echo "No python script specified. Starting python interpreter."
156 # echo "Missing python script"
157 # echo "$HELP_TEXT"
158 # exit 1
159 fi
160
161 # Using OpenMP?
162 OMP_OPTIONS=''
163 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
164 # PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
165 OMP_OPTIONS="env OMP_NUM_THREADS=$OMP_NUM_THREADS"
166 fi
167
168 # Using MPI?
169 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
170 PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
171 else
172 if [ "$MPI_NUM_PROCS" -ne 1 ]; then
173 echo "Escript/Finley was not compiled for MPI so you must use -M 1"
174 exit 1
175 fi
176 fi
177
178 set -x
179 $OMP_OPTIONS $PYTHON_CMD "$@"
180

  ViewVC Help
Powered by ViewVC 1.1.26