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

Contents of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1912 - (show annotations)
Thu Oct 23 05:08:31 2008 UTC (11 years, 1 month ago) by ksteube
File size: 2205 byte(s)
Finished wrapper script by setting PATH.

The wrapper script reproduces the environment of the person who built
the software + values specified in his hostname_options.py file.  A
user can run a python script without setting any environment variables
or loading any SGI modules.

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 HELP_TEXT="
7 Usage: escript [options] script.py [arguments...]
8 -O N Use N OpenMP threads (OMP_NUM_THREADS=N)
9 -M K Use K MPI processes
10 -l 'launcher' MPI launcher, usually -l 'mpirun -np' or -l 'mpiexec -n'
11 -L /path Prepend /path to library search path
12 -P /path Prepend /path to python module search path
13 script.py Your python script
14 arguments... The optional command-line arguments to your python script
15 "
16
17 if [ "$1" = "--help" ]; then
18 echo "$HELP_TEXT"
19 exit 0
20 fi
21
22 PYTHON_CMD="@@PYTHON_CMD@@"
23
24 ESCRIPT_ROOT="@@ESCRIPT_ROOT@@"
25
26 export PATH="@@PATH@@"
27
28 export LD_LIBRARY_PATH="@@LD_LIBRARY_PATH@@"
29
30 export PYTHONPATH="@@PYTHONPATH@@"
31
32 # Avoid bug in hybrid runs with MPT MPI
33 export MPI_NUM_MEMORY_REGIONS=0
34
35 # Try to guess the MPI launcher (mpirun unless in PBS batch job in which case mpiexec)
36 mpi_launcher='mpirun -np'
37 if [ $?PBS_ENVIRONMENT ]; then
38 if [ "X_$PBS_ENVIRONMENT" = "X_PBS_BATCH" ]; then
39 mpi_launcher='mpiexec -n'
40 fi
41 fi
42
43 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
44 OMP_NUM_THREADS=1
45 MPI_NUM_PROCS=1
46
47 # Parse the command-line options
48 while getopts 'L:P:O:M:l:' option
49 do
50 case "$option" in
51 "L") export LD_LIBRARY_PATH="$OPTARG:$LD_LIBRARY_PATH"
52 ;;
53 "P") export PYTHONPATH="$OPTARG:$PYTHONPATH"
54 ;;
55 "O") OMP_NUM_THREADS="$OPTARG"
56 ;;
57 "M") MPI_NUM_PROCS="$OPTARG"
58 ;;
59 "l") mpi_launcher="$OPTARG"
60 ;;
61 ?) echo "$HELP_TEXT"
62 exit 1
63 ;;
64 esac
65 done
66 shift `expr $OPTIND - 1`
67
68 # Must have at least one command-line arg: the python script
69 if [ $# -eq 0 ]; then
70 echo "Missing python script"
71 echo "$HELP_TEXT"
72 exit 1
73 fi
74
75 # Using OpenMP?
76 OMP_OPTIONS=''
77 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
78 PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
79 OMP_OPTIONS="env OMP_NUM_THREADS=$OMP_NUM_THREADS"
80 fi
81
82 # Using MPI?
83 if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
84 PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
85 else
86 if [ "$MPI_NUM_PROCS" -ne 1 ]; then
87 echo "Escript/Finley was not compiled for MPI so you must use -M 1"
88 exit 1
89 fi
90 fi
91
92 set -x
93 $OMP_OPTIONS time $PYTHON_CMD "$@"
94

  ViewVC Help
Powered by ViewVC 1.1.26