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

Annotation of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


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

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     #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 jfenwick 2297 cd $scriptdir/..
36 jfenwick 2296 ESCRIPT_ROOT=`pwd`
37 jfenwick 2299 cd ..
38     ESCRIPT_PARENT=`pwd`
39 jfenwick 2296 cd $CURDIR
40    
41 jfenwick 2298 ##### 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 jfenwick 2299 if [ $STANDALONE == 1 ]
52     then
53 jfenwick 2312 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 jfenwick 2299 fi
59    
60 jfenwick 2297 # For stand-alone builds this will need to be changed
61     PYTHON_CMD=python
62 ksteube 1756
63 jfenwick 2298 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 jfenwick 2297
85 jfenwick 2299
86 ksteube 1909 # Avoid bug in hybrid runs with MPT MPI
87     export MPI_NUM_MEMORY_REGIONS=0
88    
89 ksteube 1756 # 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 jfenwick 2296 # option e should not be followed by a :
103     while getopts 'L:P:O:M:l:e' option
104 ksteube 1756 do
105     case "$option" in
106 jfenwick 2299 "L") EXTRA_LD_LIBRARY_PATH="$OPTARG:$EXTRA_LD_LIBRARY_PATH"
107 ksteube 1756 ;;
108 jfenwick 2299 "P") EXTRA_PYTHONPATH="$OPTARG:$EXTRA_PYTHONPATH"
109 ksteube 1756 ;;
110     "O") OMP_NUM_THREADS="$OPTARG"
111     ;;
112     "M") MPI_NUM_PROCS="$OPTARG"
113     ;;
114     "l") mpi_launcher="$OPTARG"
115     ;;
116 jfenwick 2298 "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 jfenwick 2296 if [ `uname` == Darwin ]
120     then
121 jfenwick 2298 echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
122 jfenwick 2296 fi
123     exit 0
124     ;;
125 ksteube 1756 ?) echo "$HELP_TEXT"
126     exit 1
127     ;;
128     esac
129     done
130     shift `expr $OPTIND - 1`
131    
132 jfenwick 2298 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 jfenwick 2299 # 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 jfenwick 2298
153 ksteube 1756 # Must have at least one command-line arg: the python script
154     if [ $# -eq 0 ]; then
155 jfenwick 2294 echo "No python script specified. Starting python interpreter."
156     # echo "Missing python script"
157     # echo "$HELP_TEXT"
158     # exit 1
159 ksteube 1756 fi
160    
161     # Using OpenMP?
162     OMP_OPTIONS=''
163     if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
164 jfenwick 2102 # PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
165 ksteube 1756 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 ksteube 1912 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 ksteube 1756 fi
177    
178     set -x
179 ksteube 2110 $OMP_OPTIONS $PYTHON_CMD "$@"
180 ksteube 1756

  ViewVC Help
Powered by ViewVC 1.1.26