/[escript]/branches/py3_attempt2/bin/run-escript
ViewVC logotype

Diff of /branches/py3_attempt2/bin/run-escript

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

revision 3047 by jfenwick, Thu Jun 24 00:33:05 2010 UTC revision 3259 by jfenwick, Mon Oct 11 01:48:14 2010 UTC
# Line 41  else Line 41  else
41    else    else
42        # name does not contain / therefore we are using        # name does not contain / therefore we are using
43        tscriptdir=`which $0`        tscriptdir=`which $0`
44        if [ $? != 0 ]        if [ $? -ne 0 ]
45        then        then
46            echo "Error! Unable to determine script directory. Exiting."            echo "Error! Unable to determine script directory. Exiting."
47            exit 1            exit 1
# Line 58  else Line 58  else
58  fi  fi
59  ##### End finding ESCRIPT_ROOT  ########  ##### End finding ESCRIPT_ROOT  ########
60    
61  if [ ! -r $ESCRIPT_ROOT/lib/buildvars ]; then  BUILDINFO_FILE=$ESCRIPT_ROOT/lib/buildvars
62    if [ ! -r $BUILDINFO_FILE ]; then
63      echo "Error! Unable to read escript build information. Exiting."      echo "Error! Unable to read escript build information. Exiting."
64      exit 1      exit 1
65  fi  fi
66    
67    function get_buildvar {
68        echo `grep "^$1=" $BUILDINFO_FILE |cut -d= -f2`
69    }
70    
71  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"
72  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"
73  PYTHON_CMD=python  PYTHON_CMD=python
# Line 84  then Line 89  then
89      EXTRA_PYTHONPATH=$ESCRIPT_PARENT/pkg/numpy/lib/python2.6/site-packages:$ESCRIPT_PARENT/pkg/matplotlib/lib/python2.6/site-packages:$EXTRA_PYTHONPATH      EXTRA_PYTHONPATH=$ESCRIPT_PARENT/pkg/numpy/lib/python2.6/site-packages:$ESCRIPT_PARENT/pkg/matplotlib/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
90  fi  fi
91    
92    #
93    #   Add VisIt paths if required
94    #
95    WITH_VISIT=`get_buildvar visit`
96    if [ "$WITH_VISIT" = "1" ]; then
97        VISIT_BIN=`which visit`
98        if [ $? -eq 0 ]; then
99            VISIT_PY_PATH=`$VISIT_BIN -env | grep LIBPATH | cut -d= -f2`
100            EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH
101            EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$VISIT_PY_PATH
102        elif [ ! -z $ESCRIPT_VERBOSE ]; then
103            echo "VisIt module enabled but VisIt not in path!"
104        fi
105    fi
106    
107  HELP_TEXT="  HELP_TEXT="
108  Usage: escript [options] script.py [arguments...]  Usage: escript [options] script.py [arguments...]
109      -n nn       number of nodes to use      -n nn       number of nodes to use
110      -p np       number of MPI processes to spawn      -p np       number of MPI processes to spawn per node
111      -t nt       number of OpenMP threads to use      -t nt       number of OpenMP threads to use
112      -f file     name of MPI hostfile      -f file     name of MPI hostfile
113      -c      print compile information for escript and exit      -c      print compile information for escript and exit
# Line 131  do Line 149  do
149        "c")  cat $ESCRIPT_ROOT/lib/buildvars        "c")  cat $ESCRIPT_ROOT/lib/buildvars
150          exit 0          exit 0
151          ;;          ;;
152        "V")  echo "escript-development(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"        "V")  echo "escript-development(build "`get_buildvar svn_revision`")"
153          exit 0          exit 0
154          ;;          ;;
155        "h")  echo "$HELPTEXT"        "h")  echo "$HELPTEXT"
# Line 163  done Line 181  done
181  shift `expr $OPTIND - 1`  shift `expr $OPTIND - 1`
182  #==============================================  #==============================================
183  #  #
184  #   Read the MPI_FLAVOUR from the buildvars  #   Read MPI_FLAVOUR and WITH_OPENMP from the buildvars
185  #  #
186  MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  MPI_FLAVOUR=`get_buildvar mpi`
187  WITH_OPENMP=`grep useopenmp $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  WITH_OPENMP=`get_buildvar openmp`
188    
189  if [ ! -z $ESCRIPT_VERBOSE ]; then  if [ ! -z $ESCRIPT_VERBOSE ]; then
190      echo "MPI flavour is $MPI_FLAVOUR."      echo "MPI flavour is $MPI_FLAVOUR."
191      if [ "$WITH_OPENMP" = "y" ]; then echo "OpenMP enabled."; fi      if [ "$WITH_OPENMP" = "1" ]; then echo "OpenMP enabled."; fi
192  fi  fi
193    
194  #  #
# Line 213  then Line 231  then
231      ESCRIPT_NUM_NODES=1      ESCRIPT_NUM_NODES=1
232      ESCRIPT_NUM_PROCS=1      ESCRIPT_NUM_PROCS=1
233  else  else
234        # use the PBS_NODEFILE if not otherwise specified
235        if [[ ( ! -z $PBS_NODEFILE ) && ( -z $ESCRIPT_HOSTFILE ) ]]
236        then
237            ESCRIPT_HOSTFILE=$PBS_NODEFILE
238        fi
239    
240      if [ ! -z $ESCRIPT_HOSTFILE ]      if [ ! -z $ESCRIPT_HOSTFILE ]
241      then      then
242          if [ -f $ESCRIPT_HOSTFILE ]          if [ -f $ESCRIPT_HOSTFILE ]
# Line 239  else Line 263  else
263    
264      if [ -z $ESCRIPT_NUM_NODES ]      if [ -z $ESCRIPT_NUM_NODES ]
265      then      then
266        ESCRIPT_NUM_NODES=1          ESCRIPT_NUM_NODES=1
267      fi      fi
268    
269      if [ -z $ESCRIPT_NUM_PROCS ]      if [ -z $ESCRIPT_NUM_PROCS ]
270      then      then
271        ESCRIPT_NUM_PROCS=1          ESCRIPT_NUM_PROCS=1
272      fi      fi
273    
274      if [ ! -z $ESCRIPT_VERBOSE ]      if [ ! -z $ESCRIPT_VERBOSE ]
275      then      then
276            echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "          echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
277            echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "          echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
278      fi      fi
279  fi  fi
280    
281  if [ "$WITH_OPENMP" = "y" ]  if [ "$WITH_OPENMP" = "1" ]
282  then  then
283     if [ -z $ESCRIPT_NUM_THREADS ]     if [ -z $ESCRIPT_NUM_THREADS ]
284     then     then
# Line 281  fi Line 305  fi
305  (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))  (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))
306  if [ $? -ne 0 ]     #Some compute error  if [ $? -ne 0 ]     #Some compute error
307  then            #This could happen if the args were not a number  then            #This could happen if the args were not a number
308    echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."      echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."
309    exit 1      exit 1
310  fi  fi
311    
312  #  #
# Line 290  fi Line 314  fi
314  #  #
315  if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]  if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]
316  then  then
317    echo "Interactive mode cannot be used with more than one process"      echo "Interactive mode cannot be used with more than one process"
318    exit 1      exit 1
319  fi  fi
320    
321  if [ $TOTPROC -gt 1 ]  if [ $TOTPROC -gt 1 ]
322  then  then
323     if [ "$ESCRIPT_CREATESTDFILES" = "yes" ]      if [ "$ESCRIPT_CREATESTDFILES" = "yes" ]
324     then      then
325         PYTHON_MPI=$PYTHON_MPI_REDIRECT          PYTHON_MPI=$PYTHON_MPI_REDIRECT
326     else      else
327         PYTHON_MPI=$PYTHON_MPI_NULL          PYTHON_MPI=$PYTHON_MPI_NULL
328     fi      fi
329  else  else
330      PYTHON_MPI=$PYTHON_MPI_NULL      PYTHON_MPI=$PYTHON_MPI_NULL
331  fi  fi
# Line 309  fi Line 333  fi
333  # Must have at least one command-line arg: the python script  # Must have at least one command-line arg: the python script
334  if [ $# -eq 0 ]  if [ $# -eq 0 ]
335  then  then
336    if [ ! -z $DOBINARY ]      if [ ! -z $DOBINARY ]
337    then      then
338      echo "No program to run was specified. Exiting."          echo "No program to run was specified. Exiting."
339      exit 1          exit 1
340    fi      else
341  fi          DOINTERACTIVE="yes"
342  if [ -z $@ ]      fi
 then  
    if [ ! -z $DOBINARY ]  
    then  
        echo "Program must be given."  
        exit 1  
    else  
       DOINTERACTIVE="yes"  
    fi  
343  fi  fi
344    
345  #=========================================================================================================  #=========================================================================================================
# Line 331  if [ ! -z $DOBINARY ] Line 347  if [ ! -z $DOBINARY ]
347  then  then
348      EXEC_CMD="$@"      EXEC_CMD="$@"
349  else  else
350        # Check to see if the python version we were compiled with matches the
351        # one of PYTHON_CMD.
352        compversion=`get_buildvar python_version`
353        intversion=`$PYTHON_CMD -c 'import sys;print "%d.%d.%d"%(sys.version_info[0], sys.version_info[1], sys.version_info[2])'`
354        if [ "$compversion" != "$intversion" ]
355        then
356            echo "Python versions do not match. Escript was compiled for "$compversion"."
357            echo "Current version of Python appears to be "$intversion"."
358            exit 1
359        fi
360      if [ "$MPI_FLAVOUR" = "none" ]      if [ "$MPI_FLAVOUR" = "none" ]
361      then      then
362          # Check to see if the python version we were compiled with matches the one of EXEC_CMD          if [ ! -z $DOINTERACTIVE ]
         # We should only do this check if they are running a python script  
         if [ -f $ESCRIPT_ROOT/lib/pyversion ]  
         then  
            compversion=`cat $ESCRIPT_ROOT/lib/pyversion`  
            intversion=`$PYTHON_CMD -V 2>&1`  
            if [ "$compversion" != "$intversion" ]  
            then  
               echo "Python versions do not match. Escript was compiled for "$compversion"."  
               echo "Current version of Python appears to be "$intversion"."  
               exit 1  
            fi  
         fi  
     if [ ! -z $DOINTERACTIVE ]  
363          then          then
364             EXEC_CMD="$PYTHON_CMD -i $@"             EXEC_CMD="$PYTHON_CMD -i $@"
365          else          else
366             EXEC_CMD="$PYTHON_CMD $@"             EXEC_CMD="$PYTHON_CMD $@"
367          fi          fi
368      else      else
369      if [ ! -z $DOINTERACTIVE ]          if [ ! -z $DOINTERACTIVE ]
370          then          then
371             EXEC_CMD="$PYTHON_MPI -i $@"             EXEC_CMD="$PYTHON_MPI -i $@"
372          else          else
# Line 366  if [ ! -z $ESCRIPT_VERBOSE ]; then echo Line 379  if [ ! -z $ESCRIPT_VERBOSE ]; then echo
379  #  #
380  #   now we start to spwan things:  #   now we start to spwan things:
381  #  #
382  if [ "$WITH_OPENMP" = "y" ]  if [ "$WITH_OPENMP" = "1" ]
383  then  then
384     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
385     EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"     EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"
# Line 395  then Line 408  then
408  elif [ "$MPI_FLAVOUR" = "INTELMPI" ]  elif [ "$MPI_FLAVOUR" = "INTELMPI" ]
409  then  then
410    
411     if [ "$WITH_OPENMP" = "y" ]     if [ "$WITH_OPENMP" = "1" ]
412     then     then
413         export I_MPI_PIN_DOMAIN=omp         export I_MPI_PIN_DOMAIN=omp
414         EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"         EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"

Legend:
Removed from v.3047  
changed lines
  Added in v.3259

  ViewVC Help
Powered by ViewVC 1.1.26