/[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

trunk/bin/escript revision 2865 by gross, Fri Jan 22 03:19:32 2010 UTC trunk/bin/run-escript revision 3178 by caltinay, Tue Sep 14 00:31:59 2010 UTC
# Line 22  CURDIR=`pwd` Line 22  CURDIR=`pwd`
22  #Environment vars which control operations:  #Environment vars which control operations:
23  # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROCS, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_CREATESTDFILES  # ESCRIPT_NUM_NODES, ESCRIPT_NUM_PROCS, ESCRIPT_NUM_THREADS, ESCRIPT_HOSTFILE, ESCRIPT_CREATESTDFILES
24    
25  HOSTFILE=/tmp/escript.$$  HOSTFILE=/tmp/escript.$USER.$$
26  HOSTFILE2=/tmp/escript2.$$  HOSTFILE2=/tmp/escript2.$USER.$$
27    
28  #Begin finding ESCRIPT_ROOT  #Begin finding ESCRIPT_ROOT
29  if [ $STDLOCATION -ne 0 ]  if [ $STDLOCATION -ne 0 ]
# 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 usevisit`
96    if [ "$WITH_VISIT" = "y" ]; 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...]
# 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-pre4.0(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_flavour`
187  WITH_OPENMP=`grep useopenmp $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  WITH_OPENMP=`get_buildvar useopenmp`
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."
# 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    
# 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            DOINTERACTIVE="yes"
342        fi
343  fi  fi
344    
345  #=========================================================================================================  #=========================================================================================================
# Line 321  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`
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 373  then Line 396  then
396     if [ ! -z $HOSTFILE ]     if [ ! -z $HOSTFILE ]
397     then     then
398        HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`        HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
399        CMD="mpirun -x ${EXPORT_ENV//,/ -x } --bynode -np $TOTPROC --host $HOST_LIST $EXEC_CMD"        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } --bynode -np $TOTPROC --host $HOST_LIST $EXEC_CMD"
400     else     else
401        CMD="mpirun -x ${EXPORT_ENV//,/ -x } -np $TOTPROC $EXEC_CMD"        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } -np $TOTPROC $EXEC_CMD"
402     fi     fi
403     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
404     $CMD     $CMD
# Line 401  then Line 424  then
424        else        else
425            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi
426        fi        fi
427       else
428          mpdboot -n 1 -r ssh
429          if [ $? -ne 0 ]
430          then
431             echo "mpdboot failed."
432             exit 1
433          else
434              if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi
435          fi
436     fi     fi
437     CMD="mpiexec -perhost $ESCRIPT_NUM_PROCS -envall -n $TOTPROC $EXEC_CMD"     CMD="mpiexec -perhost $ESCRIPT_NUM_PROCS -envall -n $TOTPROC $EXEC_CMD"
438     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
439     $CMD     $CMD
440     EXIT_CODE=$?     EXIT_CODE=$?
441     if [ ! -z $HOSTFILE ]     mpdallexit
442     then     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
        mpdallexit  
        if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi  
    fi  
443  #=============== SGI's MPIMPT ===================================  #=============== SGI's MPIMPT ===================================
444  elif [ "$MPI_FLAVOUR" = "MPT" ]  elif [ "$MPI_FLAVOUR" = "MPT" ]
445  then  then
# Line 419  then Line 448  then
448     if [ ! -z $HOSTFILE ]     if [ ! -z $HOSTFILE ]
449     then     then
450        HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`        HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`
451        CMD="mpirun $HOST_LIST $ESCRIPT_NUM_PROCS $EXEC_CMD"        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"
452     else     else
453        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
454     fi     fi
# Line 453  then Line 482  then
482           else           else
483               if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi               if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi
484           fi           fi
485       else
486          mpdboot -n 1 -r ssh
487          if [ $? -ne 0 ]
488          then
489             echo "mpdboot failed."
490             exit 1
491          else
492              if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi
493          fi
494     fi     fi
495     CMD="mpiexec -genvlist $EXPORT_ENV -np $TOTPROC $EXEC_CMD"     CMD="mpiexec -genvlist $EXPORT_ENV -np $TOTPROC $EXEC_CMD"
496     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
497     $CMD     $CMD
498     EXIT_CODE=$?     EXIT_CODE=$?
499     if [ ! -z $HOSTFILE ]     mpdallexit
500     then     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi
        mpdallexit  
        if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi  
    fi  
501  else  else
502     echo "unknown MPI flavour '$MPI_FLAVOUR'."     echo "unknown MPI flavour '$MPI_FLAVOUR'."
503  fi  fi

Legend:
Removed from v.2865  
changed lines
  Added in v.3178

  ViewVC Help
Powered by ViewVC 1.1.26