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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26