/[escript]/trunk/bin/run-escript
ViewVC logotype

Diff of /trunk/bin/run-escript

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

revision 4030 by caltinay, Wed Oct 24 00:57:36 2012 UTC revision 4031 by caltinay, Wed Oct 24 03:36:37 2012 UTC
# Line 30  if [ $STDLOCATION -ne 0 ] Line 30  if [ $STDLOCATION -ne 0 ]
30  then  then
31      ESCRIPT_ROOT=/usr/lib/escript      ESCRIPT_ROOT=/usr/lib/escript
32  else  else
33    #We don't know the escript root so we need to work it out from the invocation    # We don't know the escript root so we need to work it out from the invocation
34    #Need to match if the name contains /    # Need to match if the name contains /
35    if [[ $0 =~ / ]]    if [[ $0 =~ / ]]
36    then    then
37        # We are not using the PATH to find the script        # We are not using the PATH to find the script
# Line 56  else Line 56  else
56    cd "$CURDIR"    cd "$CURDIR"
57    
58  fi  fi
59  ##### End finding ESCRIPT_ROOT  ########  ##### End finding ESCRIPT_ROOT ########
60    
61    
62    
# Line 84  fi Line 84  fi
84    
85  BUILDINFO_FILE=$ESCRIPT_ROOT/lib/buildvars  BUILDINFO_FILE=$ESCRIPT_ROOT/lib/buildvars
86  if [ ! -r $BUILDINFO_FILE ]; then  if [ ! -r $BUILDINFO_FILE ]; then
87      if [ "$1" = "-e" ];then      if [ "$1" = "-e" ]; then
88      echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"          echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
89      echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
90      echo "export PATH=$EXTRA_PATH:\$PATH"          echo "export PATH=$EXTRA_PATH:\$PATH"
91      if [ "`uname`" = "Darwin" ]          if [ "`uname`" = "Darwin" ]
92      then          then
93          echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
94      fi            fi  
95          exit 0          exit 0
96      fi      fi
97      echo "Error! Unable to read escript build information. Exiting."      echo "Error! Unable to read escript build information. Exiting."
98      exit 1      exit 1
99  fi  fi
100    
101  function get_buildvar {  get_buildvar () {
102      echo `grep "^$1=" $BUILDINFO_FILE |cut -d= -f2`      echo `grep "^$1=" $BUILDINFO_FILE |cut -d= -f2`
103  }  }
104    
# Line 118  if [ "$WITH_VISIT" = "1" ]; then Line 118  if [ "$WITH_VISIT" = "1" ]; then
118  fi  fi
119    
120  HELP_TEXT="  HELP_TEXT="
121  Usage: escript [options] script.py [arguments...]  Usage: run-escript [options] script.py [arguments...]
122      -n nn       number of nodes to use      -n nn       number of nodes to use
123      -p np       number of MPI processes to spawn per node      -p np       number of MPI processes to spawn per node
124      -t nt       number of OpenMP threads to use      -t nt       number of OpenMP threads to use
125      -f file     name of MPI hostfile      -f file     name of MPI hostfile
126      -c      print compile information for escript and exit      -c      print compile information for escript and exit
127      -V      print escript version and exit      -V      print escript version and exit
128      -i      interactive mode      -i      interactive mode
129      -b      do not invoke python (run non-python programs)      -b      do not invoke python (run non-python programs)
130      -e      print export statements for environment and exit      -e      print export statements for environment and exit
131      -o      redirect output from MPI to files      -o      redirect output from MPI to files
132      -v      print diagnostics      -v      print diagnostics
133      -x      ..reserved for future use ..      -x      run in new xterm instance
134      script.py   Your python script      script.py   Your python script
135      arguments...    The optional command-line arguments to your script      arguments...    The optional command-line arguments to your script
136  "  "
# Line 139  if [ "$1" = "--help" ]; then Line 139  if [ "$1" = "--help" ]; then
139    echo "$HELP_TEXT"    echo "$HELP_TEXT"
140    exit 0    exit 0
141  fi  fi
142  #=======================================================================================  #==============================================================================
   
 # Avoid bug in hybrid runs with MPT MPI  
   
143    
144  # Parse the command-line options  # Parse the command-line options
145  # option e should not be followed by a :  # option e should not be followed by a :
146  while getopts 'bn:p:t:f:h:ecVviox' option  while getopts 'bn:p:t:f:hecVviox' option
147  do  do
148      case "$option" in      case "$option" in
149        "b")  DOBINARY=yes        "b")  DO_BINARY=y
150          ;;          ;;
151        "n")  ESCRIPT_NUM_NODES=$OPTARG        "n")  ESCRIPT_NUM_NODES=$OPTARG
152          ;;          ;;
153        "p")  ESCRIPT_NUM_PROCS=$OPTARG        "p")  ESCRIPT_NUM_PROCS=$OPTARG
154          ;;          ;;
155        "t")  ESCRIPT_NUM_THREADS=$OPTARG        "t")  ESCRIPT_NUM_THREADS=$OPTARG
156          ;;          ;;
157        "f")  ESCRIPT_HOSTFILE=$OPTARG        "f")  ESCRIPT_HOSTFILE=$OPTARG
158          ;;          ;;
159        "c")  cat $ESCRIPT_ROOT/lib/buildvars        "c")  cat $ESCRIPT_ROOT/lib/buildvars
160          exit 0          exit 0
161          ;;          ;;
162        "V")  echo "escript-development(build "`get_buildvar svn_revision`")"        "V")  echo "escript-development(build "`get_buildvar svn_revision`")"
163          exit 0          exit 0
164          ;;          ;;
165        "h")  echo "$HELPTEXT"        "h")  echo "$HELP_TEXT"
166          exit 0          exit 0
167          ;;          ;;
168        "i")  DOINTERACTIVE=yes        "i")  DO_INTERACTIVE=y
169          ;;          ;;
170        "e")  echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"        "e")  echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
171          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
172          echo "export PATH=$EXTRA_PATH:\$PATH"          echo "export PATH=$EXTRA_PATH:\$PATH"
173          if [ "`uname`" = "Darwin" ]          if [ "`uname`" = "Darwin" ]
174          then          then
175              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
176          fi          fi
177          exit 0          exit 0
178          ;;          ;;
179        "o")  ESCRIPT_CREATESTDFILES="yes"        "o")  ESCRIPT_CREATESTDFILES=y
180          ;;          ;;
181        "v")  ESCRIPT_VERBOSE="yes"        "v")  ESCRIPT_VERBOSE=y
182          ;;          ;;
183        "x")  echo "-x not implemented yet"        "x")  DO_XTERM=y
184          exit 1          ;;
185          ;;        ?)    echo "$HELP_TEXT"
186        ?)    echo "$HELP_TEXT"          exit 1
187          exit 1          ;;
188          ;;      esac
     esac  
189  done  done
190  shift `expr $OPTIND - 1`  shift `expr $OPTIND - 1`
191  #==============================================  #==============================================
# Line 245  then Line 241  then
241      ESCRIPT_NUM_PROCS=1      ESCRIPT_NUM_PROCS=1
242  else  else
243      # use the PBS_NODEFILE if not otherwise specified      # use the PBS_NODEFILE if not otherwise specified
244      if [[ ( ! -z $PBS_NODEFILE ) && ( -z $ESCRIPT_HOSTFILE ) ]]      if [ ! -z $PBS_NODEFILE ] && [ -z $ESCRIPT_HOSTFILE ]
245      then      then
246          ESCRIPT_HOSTFILE=$PBS_NODEFILE          ESCRIPT_HOSTFILE=$PBS_NODEFILE
247      fi      fi
# Line 306  then Line 302  then
302          echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."          echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."
303     fi     fi
304  else  else
305     if [[ ( ! -z $ESCRIPT_NUM_THREADS ) && ( $ESCRIPT_NUM_THREADS != 1 ) ]]     if [ ! -z $ESCRIPT_NUM_THREADS ] && [ $ESCRIPT_NUM_THREADS != 1 ]
306     then     then
307         echo "Warning: OpenMP is disabled but number of threads requested is $ESCRIPT_NUM_THREADS!=1. Running without threads."         echo "Warning: OpenMP is disabled but number of threads requested is $ESCRIPT_NUM_THREADS!=1. Running without threads."
308     fi     fi
# Line 315  fi Line 311  fi
311  #  #
312  # Now we compute total number of Processes  # Now we compute total number of Processes
313  #  #
314  (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))  TOTPROC=$((ESCRIPT_NUM_NODES * ESCRIPT_NUM_PROCS))
315  if [ $? -ne 0 ]     #Some compute error  if [ $? -ne 0 ]     #Some compute error
316  then            #This could happen if the args were not a number  then            #This could happen if the args were not a number
317      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."
318      exit 1      exit 1
319  fi  fi
# Line 325  fi Line 321  fi
321  #  #
322  # Test to ensure people aren't trying to combine interactive and multi-process  # Test to ensure people aren't trying to combine interactive and multi-process
323  #  #
324  if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]  if ([ ! -z $DO_INTERACTIVE ] || ([ $# -eq 0 ] && [ $TOTPROC -gt 1 ]))
325  then  then
326      echo "Interactive mode cannot be used with more than one process"      echo "Interactive mode cannot be used with more than one process"
327      exit 1      exit 1
# Line 342  then Line 338  then
338  else  else
339      PYTHON_MPI=$PYTHON_MPI_NULL      PYTHON_MPI=$PYTHON_MPI_NULL
340  fi  fi
341  #=========================================================================================================  #==============================================================================
342  # Must have at least one command-line arg: the python script  # Must have at least one command-line arg: the python script
343  if [ $# -eq 0 ]  if [ $# -eq 0 ]
344  then  then
345      if [ ! -z $DOBINARY ]      if [ ! -z $DO_BINARY ]
346      then      then
347          echo "No program to run was specified. Exiting."          echo "No program to run was specified. Exiting."
348          exit 1          exit 1
349      else      else
350          DOINTERACTIVE="yes"          DO_INTERACTIVE=y
351      fi      fi
352  fi  fi
353    
354  #=========================================================================================================  #==============================================================================
355  if [ ! -z $DOBINARY ]  if [ ! -z $DO_XTERM ]
356  then  then
357      EXEC_CMD="$@"      EXEC_CMD="xterm -e"
358    else
359        EXEC_CMD=""
360    fi
361    
362    if [ ! -z $DO_BINARY ]
363    then
364        EXEC_CMD="$EXEC_CMD $@"
365  else  else
366      # Check to see if the python version we were compiled with matches the      # Check to see if the python version we were compiled with matches the
367      # one of PYTHON_CMD.      # one of PYTHON_CMD.
368      compfull=`get_buildvar python_version`      compfull=`get_buildvar python_version`
369      compversion=`echo $compfull | cut -d. -f1,2`      compversion=`echo $compfull | cut -d. -f1,2`
370      compmajor=`echo $compfull | cut -d. -f1`      compmajor=`echo $compfull | cut -d. -f1`
371      if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they      if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they
372      then                                # might not want us changing it      then                                # might not want us changing it
373          if [ "$compmajor" = "3" ]          if [ "$compmajor" = "3" ]
374          then          then
# Line 381  else Line 384  else
384      fi      fi
385      if [ "$MPI_FLAVOUR" = "none" ]      if [ "$MPI_FLAVOUR" = "none" ]
386      then      then
387          if [ ! -z $DOINTERACTIVE ]          if [ ! -z $DO_INTERACTIVE ]
388          then          then
389             EXEC_CMD="$PYTHON_CMD -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD -i $@"
390          else          else
391             EXEC_CMD="$PYTHON_CMD $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD $@"
392          fi          fi
393      else      else
394          if [ ! -z $DOINTERACTIVE ]          if [ ! -z $DO_INTERACTIVE ]
395          then          then
396             EXEC_CMD="$PYTHON_MPI -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI -i $@"
397          else          else
398             EXEC_CMD="$PYTHON_MPI $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI $@"
399          fi          fi
400      fi      fi
401  fi  fi
402  if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is \"$EXEC_CMD\"."; fi  if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is \"$EXEC_CMD\"."; fi
403  #===============================================================================================  #==============================================================================
404  #  #
405  #   now we start to spwan things:  #   now we start to spawn things:
406  #  #
407  if [ "$WITH_OPENMP" = "1" ]  if [ "$WITH_OPENMP" = "1" ]
408  then  then
# Line 524  else Line 527  else
527     echo "unknown MPI flavour '$MPI_FLAVOUR'."     echo "unknown MPI flavour '$MPI_FLAVOUR'."
528  fi  fi
529  exit $EXIT_CODE  exit $EXIT_CODE
530    

Legend:
Removed from v.4030  
changed lines
  Added in v.4031

  ViewVC Help
Powered by ViewVC 1.1.26