/[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 3975 by caltinay, Thu Sep 20 01:54:06 2012 UTC revision 4078 by jfenwick, Fri Nov 16 07:50:49 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  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"
62  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"
# Line 70  PYTHON_CMD=python Line 68  PYTHON_CMD=python
68  EXTRA_DYLD_LIBRARY_PATH=""  EXTRA_DYLD_LIBRARY_PATH=""
69  EXTRA_PATH=$ESCRIPT_ROOT/bin  EXTRA_PATH=$ESCRIPT_ROOT/bin
70  EXTRA_PYTHONPATH=$ESCRIPT_ROOT  EXTRA_PYTHONPATH=$ESCRIPT_ROOT
71  EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib  
72    if [ $STDLOCATION -eq 1 ]
73    then
74        EXTRA_LD_LIBRARY_PATH=/usr/lib/escript
75    else
76        EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
77    fi
78    
79    
80  if [ $STANDALONE -eq 1 ]  if [ $STANDALONE -eq 1 ]
81  then  then
# Line 83  fi Line 88  fi
88    
89    
90  BUILDINFO_FILE=$ESCRIPT_ROOT/lib/buildvars  BUILDINFO_FILE=$ESCRIPT_ROOT/lib/buildvars
91    if [ "$STDLOCATION" = "1" ]
92    then
93        BUILDINFO_FILE=/usr/lib/escript/buildvars
94    fi
95  if [ ! -r $BUILDINFO_FILE ]; then  if [ ! -r $BUILDINFO_FILE ]; then
96      if [ "$1" = "-e" ];then      if [ "$1" = "-e" ]; then
97      echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"          echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
98      echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
99      echo "export PATH=$EXTRA_PATH:\$PATH"          echo "export PATH=$EXTRA_PATH:\$PATH"
100      if [ "`uname`" = "Darwin" ]          if [ "`uname`" = "Darwin" ]
101      then          then
102          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"
103      fi            fi  
104          exit 0          exit 0
105      fi      fi
106      echo "Error! Unable to read escript build information. Exiting."      echo "Error! Unable to read escript build information. Exiting."
107      exit 1      exit 1
108  fi  fi
109    
110  function get_buildvar {  get_buildvar () {
111      echo `grep "^$1=" $BUILDINFO_FILE |cut -d= -f2`      echo `grep "^$1=" $BUILDINFO_FILE |cut -d= -f2`
112  }  }
113    
# Line 107  function get_buildvar { Line 116  function get_buildvar {
116  #  #
117  WITH_VISIT=`get_buildvar visit`  WITH_VISIT=`get_buildvar visit`
118  if [ "$WITH_VISIT" = "1" ]; then  if [ "$WITH_VISIT" = "1" ]; then
119      VISIT_BIN=`which visit`      VISIT_BIN=`which visit 2>/dev/null`
120      if [ $? -eq 0 ]; then      if [ $? -eq 0 ]; then
121          VISIT_PY_PATH=`$VISIT_BIN -env | grep LIBPATH | cut -d= -f2`          VISIT_PY_PATH=`$VISIT_BIN -env | grep LIBPATH | cut -d= -f2`
122          EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH          EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH
# Line 118  if [ "$WITH_VISIT" = "1" ]; then Line 127  if [ "$WITH_VISIT" = "1" ]; then
127  fi  fi
128    
129  HELP_TEXT="  HELP_TEXT="
130  Usage: escript [options] script.py [arguments...]  Usage: run-escript [options] script.py [arguments...]
131      -n nn       number of nodes to use      -n nn       number of nodes to use
132      -p np       number of MPI processes to spawn per node      -p np       number of MPI processes to spawn per node
133      -t nt       number of OpenMP threads to use      -t nt       number of OpenMP threads to use
134      -f file     name of MPI hostfile      -f file     name of MPI hostfile
135      -c      print compile information for escript and exit      -c      print compile information for escript and exit
136      -V      print escript version and exit      -V      print escript version and exit
137      -i      interactive mode      -i      interactive mode
138      -b      do not invoke python (run non-python programs)      -b      do not invoke python (run non-python programs)
139      -e      print export statements for environment and exit      -e      print export statements for environment and exit
140      -o      redirect output from MPI to files      -o      redirect output from MPI to files
141      -v      print diagnostics      -v      print diagnostics
142      -x      ..reserved for future use ..      -x      run in new xterm instance
143      script.py   Your python script      script.py   Your python script
144      arguments...    The optional command-line arguments to your script      arguments...    The optional command-line arguments to your script
145  "  "
# Line 139  if [ "$1" = "--help" ]; then Line 148  if [ "$1" = "--help" ]; then
148    echo "$HELP_TEXT"    echo "$HELP_TEXT"
149    exit 0    exit 0
150  fi  fi
151  #=======================================================================================  #==============================================================================
   
 # Avoid bug in hybrid runs with MPT MPI  
   
152    
153  # Parse the command-line options  # Parse the command-line options
154  # option e should not be followed by a :  # option e should not be followed by a :
155  while getopts 'bn:p:t:f:h:ecVviox' option  while getopts 'bn:p:t:f:hecVviox' option
156  do  do
157      case "$option" in      case "$option" in
158        "b")  DOBINARY=yes        "b")  DO_BINARY=y
159          ;;          ;;
160        "n")  ESCRIPT_NUM_NODES=$OPTARG        "n")  ESCRIPT_NUM_NODES=$OPTARG
161          ;;          ;;
162        "p")  ESCRIPT_NUM_PROCS=$OPTARG        "p")  ESCRIPT_NUM_PROCS=$OPTARG
163          ;;          ;;
164        "t")  ESCRIPT_NUM_THREADS=$OPTARG        "t")  ESCRIPT_NUM_THREADS=$OPTARG
165          ;;          ;;
166        "f")  ESCRIPT_HOSTFILE=$OPTARG        "f")  ESCRIPT_HOSTFILE=$OPTARG
167          ;;          ;;
168        "c")  cat $ESCRIPT_ROOT/lib/buildvars        "c")  cat $BUILDINFO_FILE
169          exit 0          exit 0
170          ;;          ;;
171        "V")  echo "escript-development(build "`get_buildvar svn_revision`")"        "V")  echo "escript-development(build "`get_buildvar svn_revision`")"
172          exit 0          exit 0
173          ;;          ;;
174        "h")  echo "$HELPTEXT"        "h")  echo "$HELP_TEXT"
175          exit 0          exit 0
176          ;;          ;;
177        "i")  DOINTERACTIVE=yes        "i")  DO_INTERACTIVE=y
178          ;;          ;;
179        "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"
180          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
181          echo "export PATH=$EXTRA_PATH:\$PATH"          echo "export PATH=$EXTRA_PATH:\$PATH"
182          if [ "`uname`" = "Darwin" ]          if [ "`uname`" = "Darwin" ]
183          then          then
184              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"
185          fi          fi
186          exit 0          exit 0
187          ;;          ;;
188        "o")  ESCRIPT_CREATESTDFILES="yes"        "o")  ESCRIPT_CREATESTDFILES=y
189          ;;          ;;
190        "v")  ESCRIPT_VERBOSE="yes"        "v")  ESCRIPT_VERBOSE=y
191          ;;          ;;
192        "x")  echo "-x not implemented yet"        "x")  DO_XTERM=y
193          exit 1          ;;
194          ;;        ?)    echo "$HELP_TEXT"
195        ?)    echo "$HELP_TEXT"          exit 1
196          exit 1          ;;
197          ;;      esac
     esac  
198  done  done
199  shift `expr $OPTIND - 1`  shift `expr $OPTIND - 1`
200  #==============================================  #==============================================
# Line 245  then Line 250  then
250      ESCRIPT_NUM_PROCS=1      ESCRIPT_NUM_PROCS=1
251  else  else
252      # use the PBS_NODEFILE if not otherwise specified      # use the PBS_NODEFILE if not otherwise specified
253      if [[ ( ! -z $PBS_NODEFILE ) && ( -z $ESCRIPT_HOSTFILE ) ]]      if [ ! -z $PBS_NODEFILE ] && [ -z $ESCRIPT_HOSTFILE ]
254      then      then
255          ESCRIPT_HOSTFILE=$PBS_NODEFILE          ESCRIPT_HOSTFILE=$PBS_NODEFILE
256      fi      fi
# Line 306  then Line 311  then
311          echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."          echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."
312     fi     fi
313  else  else
314     if [[ ( ! -z $ESCRIPT_NUM_THREADS ) && ( $ESCRIPT_NUM_THREADS != 1 ) ]]     if [ ! -z $ESCRIPT_NUM_THREADS ] && [ $ESCRIPT_NUM_THREADS != 1 ]
315     then     then
316         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."
317     fi     fi
# Line 315  fi Line 320  fi
320  #  #
321  # Now we compute total number of Processes  # Now we compute total number of Processes
322  #  #
323  (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))  TOTPROC=$((ESCRIPT_NUM_NODES * ESCRIPT_NUM_PROCS))
324  if [ $? -ne 0 ]     #Some compute error  if [ $? -ne 0 ]     #Some compute error
325  then            #This could happen if the args were not a number  then            #This could happen if the args were not a number
326      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."
327      exit 1      exit 1
328  fi  fi
# Line 325  fi Line 330  fi
330  #  #
331  # 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
332  #  #
333  if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]  if ([ ! -z $DO_INTERACTIVE ] || [ $# -eq 0 ]) && ([ $TOTPROC -gt 1 ])
334  then  then
335      echo "Interactive mode cannot be used with more than one process"      echo "Interactive mode cannot be used with more than one process"
336      exit 1      exit 1
# Line 342  then Line 347  then
347  else  else
348      PYTHON_MPI=$PYTHON_MPI_NULL      PYTHON_MPI=$PYTHON_MPI_NULL
349  fi  fi
350  #=========================================================================================================  #==============================================================================
351  # Must have at least one command-line arg: the python script  # Must have at least one command-line arg: the python script
352  if [ $# -eq 0 ]  if [ $# -eq 0 ]
353  then  then
354      if [ ! -z $DOBINARY ]      if [ ! -z $DO_BINARY ]
355      then      then
356          echo "No program to run was specified. Exiting."          echo "No program to run was specified. Exiting."
357          exit 1          exit 1
358      else      else
359          DOINTERACTIVE="yes"          DO_INTERACTIVE=y
360      fi      fi
361  fi  fi
362    
363  #=========================================================================================================  #==============================================================================
364  if [ ! -z $DOBINARY ]  if [ ! -z $DO_XTERM ]
365    then
366        EXEC_CMD="xterm -e"
367    else
368        EXEC_CMD=""
369    fi
370    
371    if [ ! -z $DO_BINARY ]
372  then  then
373      EXEC_CMD="$@"      EXEC_CMD="$EXEC_CMD $@"
374  else  else
375      # 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
376      # one of PYTHON_CMD.      # one of PYTHON_CMD.
377      compfull=`get_buildvar python_version`      compfull=`get_buildvar python_version`
378      compversion=`echo $compfull | cut -d. -f1,2`      compversion=`echo $compfull | cut -d. -f1,2`
379      compmajor=`echo $compfull | cut -d. -f1`      compmajor=`echo $compfull | cut -d. -f1`
380      if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they      if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they
381      then                                # might not want us changing it      then                                # might not want us changing it
382          if [ "$compmajor" = "3" ]          if [ "$compmajor" = "3" ]
383          then          then
# Line 381  else Line 393  else
393      fi      fi
394      if [ "$MPI_FLAVOUR" = "none" ]      if [ "$MPI_FLAVOUR" = "none" ]
395      then      then
396          if [ ! -z $DOINTERACTIVE ]          if [ ! -z $DO_INTERACTIVE ]
397          then          then
398             EXEC_CMD="$PYTHON_CMD -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD -i $@"
399          else          else
400             EXEC_CMD="$PYTHON_CMD $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD $@"
401          fi          fi
402      else      else
403          if [ ! -z $DOINTERACTIVE ]          if [ ! -z $DO_INTERACTIVE ]
404          then          then
405             EXEC_CMD="$PYTHON_MPI -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI -i $@"
406          else          else
407             EXEC_CMD="$PYTHON_MPI $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI $@"
408          fi          fi
409      fi      fi
410  fi  fi
411  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
412  #===============================================================================================  #==============================================================================
413  #  #
414  #   now we start to spwan things:  #   now we start to spawn things:
415  #  #
416  if [ "$WITH_OPENMP" = "1" ]  if [ "$WITH_OPENMP" = "1" ]
417  then  then
# Line 418  then Line 430  then
430     if [ ! -z $HOSTFILE ]     if [ ! -z $HOSTFILE ]
431     then     then
432        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`
433        CMD="mpirun --gmca mpi_warn_on_fork 0 -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 --bind-to-socket --cpus-per-rank $ESCRIPT_NUM_THREADS --host $HOST_LIST $EXEC_CMD"
434     else     else
435        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } -np $TOTPROC $EXEC_CMD"        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } --cpus-per-rank $ESCRIPT_NUM_THREADS -np $TOTPROC $EXEC_CMD"
436     fi     fi
437     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
438     $CMD     $CMD
# Line 524  else Line 536  else
536     echo "unknown MPI flavour '$MPI_FLAVOUR'."     echo "unknown MPI flavour '$MPI_FLAVOUR'."
537  fi  fi
538  exit $EXIT_CODE  exit $EXIT_CODE
539    

Legend:
Removed from v.3975  
changed lines
  Added in v.4078

  ViewVC Help
Powered by ViewVC 1.1.26