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

Diff of /trunk/scripts/finley_wrapper_template

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2348 by jfenwick, Mon Mar 30 01:34:45 2009 UTC revision 2349 by gross, Mon Mar 30 08:14:23 2009 UTC
# Line 15  scriptdir="" Line 15  scriptdir=""
15  CURDIR=`pwd`  CURDIR=`pwd`
16    
17  #Environment vars which control operations:  #Environment vars which control operations:
18  # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROC, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_STDFILES  # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROC, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_CREATESTDFILES
19    
20    
21  #Need to match if the name contains /  #Need to match if the name contains /
# Line 41  ESCRIPT_ROOT=`pwd` Line 41  ESCRIPT_ROOT=`pwd`
41  cd ..  cd ..
42  ESCRIPT_PARENT=`pwd`  ESCRIPT_PARENT=`pwd`
43  cd $CURDIR  cd $CURDIR
   
44  ##### End finding ESCRIPT_ROOT  ########  ##### End finding ESCRIPT_ROOT  ########
45    
46    PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"
47    
48  # if possible please express paths relative to $ESCRIPT_ROOT unless  # if possible please express paths relative to $ESCRIPT_ROOT unless
49  # they are in an unrelated location  # they are in an unrelated location
50    
 EXTRA_PATH=""  
 EXTRA_LD_LIBRARY_PATH=""  
51  EXTRA_DYLD_LIBRARY_PATH=""  EXTRA_DYLD_LIBRARY_PATH=""
52  EXTRA_PYTHONPATH=""  EXTRA_PATH=$ESCRIPT_ROOT/bin
53    EXTRA_PYTHONPATH=$ESCRIPT_ROOT
54    EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
55    
56  if [ $STANDALONE == 1 ]  if [ $STANDALONE == 1 ]
57  then  then
# Line 61  then Line 62  then
62      EXTRA_PYTHONPATH=$ESCRIPT_PARENT/packages/numarray/lib:$ESCRIPT_PARENT/packages/vtk/lib/python2.6/site-packages:$EXTRA_PYTHONPATH      EXTRA_PYTHONPATH=$ESCRIPT_PARENT/packages/numarray/lib:$ESCRIPT_PARENT/packages/vtk/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
63  fi  fi
64    
 # For stand-alone builds this will need to be changed  
 PYTHON_CMD=python  
   
 EXTRA_PYTHONPATH=$ESCRIPT_ROOT:$EXTRA_PYTHONPATH  
 EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib:$EXTRA_LD_LIBRARY_PATH  
65    
66    
67  HELP_TEXT="  HELP_TEXT="
# Line 90  if [ "$1" = "--help" ]; then Line 86  if [ "$1" = "--help" ]; then
86    echo "$HELP_TEXT"    echo "$HELP_TEXT"
87    exit 0    exit 0
88  fi  fi
89    #=======================================================================================
   
90    
91  # Avoid bug in hybrid runs with MPT MPI  # Avoid bug in hybrid runs with MPT MPI
 export MPI_NUM_MEMORY_REGIONS=0  
92    
 # Try to guess the MPI launcher (mpirun unless in PBS batch job in which case mpiexec)  
 mpi_launcher='mpirun -np'  
 if [ $?PBS_ENVIRONMENT ]; then  
   if [ "X_$PBS_ENVIRONMENT" = "X_PBS_BATCH" ]; then  
     mpi_launcher='mpiexec -n'  
   fi    
 fi  
   
 PYTHON_MPI="$ESCRIPT_ROOT/lib/pythonMPI"  
 OMP_NUM_THREADS=1  
 MPI_NUM_PROCS=1  
93    
94  # Parse the command-line options  # Parse the command-line options
95  # option e should not be followed by a :  # option e should not be followed by a :
# Line 143  do Line 126  do
126          fi          fi
127          exit 0          exit 0
128          ;;          ;;
129        "o")  ESCRIPT_STDFILES="yes"        "o")  ESCRIPT_CREATESTDFILES="yes"
130          ;;          ;;
131        "v")  echo "Diagnostics:"        "v")  ESCRIPT_VERBOSE="yes"
         exit 0  
132          ;;          ;;
133        "x")  echo "-x not implemented yet"        "x")  echo "-x not implemented yet"
134          exit 1          exit 1
# Line 157  do Line 139  do
139      esac      esac
140  done  done
141  shift `expr $OPTIND - 1`  shift `expr $OPTIND - 1`
142    #==============================================
143  #Read the MPI_FLAVOUR from the buildvars  #
144    #   Read the MPI_FLAVOUR from the buildvars
145    #
146  MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`
147    
148    if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ] && [ $MPI_FLAVOUR  == "none" ]
149    then
150         echo "compiled with MPI but no MPI flavour specified."
151         exit 1
152    fi
153    
154    if [ ! -z $ESCRIPT_VERBOSE  ]; then echo "MPI flavor is $MPI_FLAVOUR."; fi
155    if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ];
156    then
157        ESCRIPT_WITH_OPENMP="yes"
158    fi
159    if [ ! -z $ESCRIPT_VERBOSE ] && [ ! -z $ESCRIPT_WITH_OPENMP ]; then echo "OpenMP enbaled."; fi
160    #
161    #  extend path variables
162    #
163  export PATH=$EXTRA_PATH:$PATH  export PATH=$EXTRA_PATH:$PATH
164  export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH  export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
165  export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH  export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
166    EXPORT_ENV="PATH, LD_LIBRARY_PATH, PYTHONPATH"
167  if [ `uname` == Darwin ]  if [ `uname` == Darwin ]
168  then  then
169      export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH      export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
170        EXPORT_ENV="$EXPORT_ENV, DYLD_LIBRARY_PATH"
171  fi  fi
172    if [ ! -z $ESCRIPT_VERBOSE  ]
173  if [ ! -z $DOBINARY ]  then
174        echo "PATH = $PATH "
175        echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
176        echo "PYTHONPATH = $PYTHONPATH "
177        if [ ! -z $DYLD_LIBRARY_PATH ]; then echo "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH "; fi
178    fi
179    #==============================================
180    #
181    #  Ensure the variables have sensible values
182    #
183    if [ $MPI_FLAVOUR  == "none" ]
184  then  then
185      PYTHON_CMD=''      if [ ! -z $ESCRIPT_NUM_NODES ]
186        then
187            echo "Warning: MPI disabled but number of nodes set. Option ignored."
188        fi
189        if [ ! -z $ESCRIPT_NUM_PROCS ]
190        then
191            echo "Warning: MPI disabled but number of processors per node set. Option ignored."
192        fi
193        ESCRIPT_NUM_NODES=1
194        ESCRIPT_NUM_PROCS=1
195    else
196        if [ -z $ESCRIPT_NUM_NODES ]
197        then
198          ESCRIPT_NUM_NODES=1
199        fi
200        if [ -z $ESCRIPT_NUM_PROCS ]
201        then
202          ESCRIPT_NUM_PROCS=1
203        fi
204        if [ ! -z $ESCRIPT_VERBOSE  ]
205        then
206              echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
207              echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
208        fi
209  fi  fi
210    if [ ! -z $ESCRIPT_WITH_OPENMP ]
   
 # Check to see if the python version we were compiled with matches the one of PYTHON_CMD  
 # We should only do this check if they are running a python script  
 if [[ (! -z $PYTHON_CMD ) && -f $ESCRIPT_ROOT/lib/pyversion ]]  
211  then  then
212     compversion=`cat $ESCRIPT_ROOT/lib/pyversion`     if [ -z $ESCRIPT_NUM_THREADS ]
213     intversion=`$PYTHON_CMD --version 2>&1`       then
214     if [ "$compversion" != "$intversion" ]       ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
215     then       if [ -z $ESCRIPT_NUM_THREADS ]
216        echo "Python versions do not match. Escript was compiled for "$compversion"."       then
217        echo "Current version of Python appears to be "$intversion"."         ESCRIPT_NUM_THREADS=1
218        exit 1       fi
219         if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Number of threads is $ESCRIPT_NUM_THREADS."; fi
220     fi     fi
221    else
222       ESCRIPT_NUM_THREADS=1
223  fi  fi
224    #
225    # Now we compute total number of Processes
226    #
227    (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
228    if [ $? -ne 0 ]     #Some compute error
229    then            #This could happen if the args were not a number
230      echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."
231      exit 1
232    fi
233    #
234    # Test to ensure people aren't trying to combine interactive and multi-process
235    #
236    if [[ ( ( -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
237    then
238      echo "Interactive mode cannot be used with more than one process"
239      exit 1
240    fi
241    #=========================================================================================================
242    if [ ! -z $DOBINARY ]
243    then
244        PYTHON_CMD=""
245    else
246        PYTHON_CMD=python
247        if [ $TOTPROC -gt 1 ]
248        then
249            PYTHON_CMD="$PYTHONMPI $@"
250        else
251            # Check to see if the python version we were compiled with matches the one of PYTHON_CMD
252            # We should only do this check if they are running a python script
253            if [ -f $ESCRIPT_ROOT/lib/pyversion ]
254            then
255               compversion=`cat $ESCRIPT_ROOT/lib/pyversion`
256               intversion=`$PYTHON_CMD --version 2>&1`
257               if [ "$compversion" != "$intversion" ]
258               then
259                  echo "Python versions do not match. Escript was compiled for "$compversion"."
260                  echo "Current version of Python appears to be "$intversion"."
261                  exit 1
262               fi
263            fi
264        if [ ! -z $DOINTERACTIVE ]
265            then
266               PYTHON_CMD="python -i $@"
267            else
268               PYTHON_CMD="python $@"
269            fi
270        fi
271        if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Python command is $PYTHON_CMD."; fi
272    fi
273    #=========================================================================================================
274  # Must have at least one command-line arg: the python script  # Must have at least one command-line arg: the python script
275  if [ $# -eq 0 ]; then  if [ $# -eq 0 ]
276    then
277    if [ ! -z $DOBINARY ]    if [ ! -z $DOBINARY ]
278    then    then
279      echo "No program to run was specified. Exiting."      echo "No program to run was specified. Exiting."
280      exit 1      exit 1
   else  
     echo "No python script specified. Starting python interpreter."  
281    fi    fi
282  fi  fi
283    #===============================================================================================
284  #Ensure the variables have sensible values  #
285  if [ -z $ESCRIPT_NUM_NODES ]  #   now we start to spwan things:
286    #
287    if [ ! -z $ESCRIPT_WITH_OPENMP ]
288  then  then
289    ESCRIPT_NUM_NODES=1     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
290       EXPORT_ENV="$EXPORT_ENV, OMP_NUM_THREADS"
291  fi  fi
292    
293  if [ -z $ESCRIPT_NUM_PROCS ]  if [ $MPI_FLAVOUR  == "none" ]
294  then  then
295    ESCRIPT_NUM_PROCS=1     $PYTHON_CMD
296  fi  elif [ $MPI_FLAVOUR == "OPENMPI" ]
297    then
298       echo "OPENMPI not implemented yet."
299    
300  if [ -z $ESCRIPT_NUM_THREADS ]  elif [ $MPI_FLAVOR == "MLP" ]
301  then  then
302    ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS     export MPI_NUM_MEMORY_REGIONS=0
303    if [ -z $ESCRIPT_NUM_THREADS ]     echo "MLP not implemented yet."
   then  
     ESCRIPT_NUM_THREADS=1  
   fi  
 fi  
304    
305  #Now we compute total number of Processes  elif [ $MPI_FLAVOR == "MPICH" ]
 (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))  
 if [ $? -ne 0 ]     #Some compute error  
 then            #This could happen if the args were not a number  
   ESCRIPT_NUM_NODES=1  
   ESCRIPT_NUM_PROCS=1  
 fi  
   
 # Test to ensure people aren't trying to combine interactive and multi-process  
   
 if [[ ( ( -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]  
306  then  then
307    echo "Interactive mode cannot be used with more than one process"     echo "MPICH not implemented yet."
308    exit 1  else
309       echo "unknown MPI falvour $MPI_FLAVOR."
310       exit 1
311  fi  fi
312    exit 0
313  # Using OpenMP?  # Using OpenMP?
314  OMP_OPTIONS=''  #OMP_OPTIONS=''
315  if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then  #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.openmp" ]; then
316  #  PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"  #  PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
317    OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"  #  ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
318  fi  #  OMP_OPTIONS="env OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS"
319    #fi
320    
321  # Using MPI?  # Using MPI?
322  if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then  #if [ -f "$ESCRIPT_ROOT/lib/Compiled.with.mpi" ]; then
323    PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"  #  PYTHON_CMD="$mpi_launcher $MPI_NUM_PROCS $PYTHON_MPI"
324  else  #else
325    if [ "$TOTPROC" -ne 1 ]; then  #  if [ "$TOTPROC" -ne 1 ]; then
326      echo "Escript/Finley was not compiled for MPI. You can not use the -n and -p options."  #    echo "Escript/Finley was not compiled for MPI. You can not use the -n and -p options."
327      exit 1  #    exit 1
328    fi  #  fi
329  fi  #fi
   
 set -x  
 $OMP_OPTIONS $PYTHON_CMD "$@"  
   

Legend:
Removed from v.2348  
changed lines
  Added in v.2349

  ViewVC Help
Powered by ViewVC 1.1.26