/[escript]/branches/inv2jf/run-escript.in
ViewVC logotype

Diff of /branches/inv2jf/run-escript.in

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

revision 4667 by sshaw, Tue Feb 11 00:47:26 2014 UTC revision 4927 by caltinay, Fri May 2 02:47:44 2014 UTC
# Line 1  Line 1 
1  #!/usr/bin/env bash  #!/usr/bin/env sh
2    
3  # Escript/Finley wrapper for python  # Escript/Finley wrapper for python
4  # Sets LD_LIBRARY_PATH and PYTHONPATH and then runs either python or the MPI launcher  # Sets LD_LIBRARY_PATH and PYTHONPATH and then runs either python or the MPI launcher
# Line 32  then Line 32  then
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 $(echo $0|grep -q /)
36    then    then
37        # We are not using the PATH to find the script        # We are not using the PATH to find the script
38        cd "`dirname $0`"        cd "`dirname $0`"
39        scriptdir=`pwd`        scriptdir=`pwd`
40        cd "$CURDIR"        cd "$CURDIR"
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 [ $? -ne 0 ]        if [ $? -ne 0 ]
45        then        then
# Line 100  if [ ! -r "$BUILDINFO_FILE" ]; then Line 100  if [ ! -r "$BUILDINFO_FILE" ]; then
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."
# Line 134  Usage: run-escript [options] script.py [ Line 134  Usage: run-escript [options] script.py [
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
# Line 223  then Line 223  then
223      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
224      EXPORT_ENV="$EXPORT_ENV,DYLD_LIBRARY_PATH"      EXPORT_ENV="$EXPORT_ENV,DYLD_LIBRARY_PATH"
225  fi  fi
226  if [ ! -z $ESCRIPT_VERBOSE ]  if [ ! -z $ESCRIPT_VERBOSE ]
227  then  then
228      echo "PATH = $PATH "      echo "PATH = $PATH "
229      echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "      echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
230      echo "PYTHONPATH = $PYTHONPATH "      echo "PYTHONPATH = $PYTHONPATH "
# Line 234  fi Line 234  fi
234  #  #
235  #  Ensure the variables have sensible values  #  Ensure the variables have sensible values
236  #  #
237  if [ "$MPI_FLAVOUR" = "none" ]  if [ "$MPI_FLAVOUR" = "none" ]
238  then  then
239      if [ ! -z "$ESCRIPT_NUM_NODES" ]; then      if [ ! -z "$ESCRIPT_NUM_NODES" ]; then
240          if [ $ESCRIPT_NUM_NODES -gt 1 ]; then          if [ $ESCRIPT_NUM_NODES -gt 1 ]; then
# Line 259  else Line 259  else
259          ESCRIPT_HOSTFILE=$PBS_NODEFILE          ESCRIPT_HOSTFILE=$PBS_NODEFILE
260      fi      fi
261    
262      if [ ! -z "$ESCRIPT_HOSTFILE" ]      if [ ! -z "$ESCRIPT_HOSTFILE" ]
263      then      then
264          if [ -f "$ESCRIPT_HOSTFILE" ]          if [ -f "$ESCRIPT_HOSTFILE" ]
265          then          then
266              cat "$ESCRIPT_HOSTFILE" | sort -u > $HOSTFILE              cat "$ESCRIPT_HOSTFILE" | sort -u > $HOSTFILE
267              NUM_HOSTS=`cat "$HOSTFILE" | wc -l`              NUM_HOSTS=`cat "$HOSTFILE" | wc -l`
268              if [ ! -z $ESCRIPT_NUM_NODES ]              if [ ! -z $ESCRIPT_NUM_NODES ]
269              then              then
270                  if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]                  if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]
271                  then                  then
# Line 294  else Line 294  else
294      fi      fi
295    
296      if [ ! -z $ESCRIPT_VERBOSE ]      if [ ! -z $ESCRIPT_VERBOSE ]
297      then      then
298          echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "          echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
299          echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "          echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
300      fi      fi
# Line 325  fi Line 325  fi
325  # Now we compute total number of Processes  # Now we compute total number of Processes
326  #  #
327  TOTPROC=$((ESCRIPT_NUM_NODES * ESCRIPT_NUM_PROCS))  TOTPROC=$((ESCRIPT_NUM_NODES * ESCRIPT_NUM_PROCS))
328  if [ $? -ne 0 ]     #Some compute error  if [ $? -ne 0 ]     #Some compute error
329  then            #This could happen if the args were not a number  then            #This could happen if the args were not a number
330      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."
331      exit 1      exit 1
# Line 340  then Line 340  then
340      exit 1      exit 1
341  fi  fi
342    
343  if [ $TOTPROC -gt 1 ]  if [ $TOTPROC -gt 1 ]
344  then  then
345      if [ "$ESCRIPT_CREATESTDFILES" = "y" ]      if [ "$ESCRIPT_CREATESTDFILES" = "y" ]
346      then      then
# Line 451  then Line 451  then
451  fi  fi
452  EXIT_CODE=1  EXIT_CODE=1
453  #=============== no MPI ===================================  #=============== no MPI ===================================
454  if [ "$MPI_FLAVOUR" = "none" ]  if [ "$MPI_FLAVOUR" = "none" ]
455  then  then
456     $EXEC_CMD     $EXEC_CMD
457     EXIT_CODE=$?     EXIT_CODE=$?
458  #=============== OpenMPI ===================================  #=============== OpenMPI ===================================
459  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]
460  then  then
461     if [ ! -z "$HOSTFILE" ]     EXPORT_ENV=$(echo $EXPORT_ENV|sed -e 's/,/ -x /g')
462       if [ ! -z "$HOSTFILE" ]
463     then     then
464        HOST_LIST=`sort -u "$HOSTFILE" | awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}'`        HOST_LIST=`sort -u "$HOSTFILE" | awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}'`
465        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } --bynode --bind-to-none --host $HOST_LIST -np $TOTPROC $EXEC_CMD"        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV} --bynode --bind-to-none --host $HOST_LIST -np $TOTPROC $EXEC_CMD"
466     else     else
467        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } --cpus-per-rank $ESCRIPT_NUM_THREADS -np $TOTPROC $EXEC_CMD"        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV} --cpus-per-rank $ESCRIPT_NUM_THREADS -np $TOTPROC $EXEC_CMD"
468     fi     fi
469     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
470     $CMD     $CMD
471     EXIT_CODE=$?     EXIT_CODE=$?
# Line 476  then Line 477  then
477     if [ "$WITH_OPENMP" = "1" ]     if [ "$WITH_OPENMP" = "1" ]
478     then     then
479         export I_MPI_PIN_DOMAIN=omp         export I_MPI_PIN_DOMAIN=omp
480         EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"         EXPORT_ENV="$EXPORT_ENV,I_MPI_PIN_DOMAIN"
481     fi     fi
482    
483     if [ ! -z "$HOSTFILE" ]     if [ ! -z "$HOSTFILE" ]
484     then     then
485        mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"        mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"
486        if [ $? -ne 0 ]        if [ $? -ne 0 ]
487        then        then
488           echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."           echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."
489           exit 1           exit 1
490        else        else
491            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
492        fi        fi
493     else     else
494        mpdboot -n 1 -r ssh        mpdboot -n 1 -r ssh
495        if [ $? -ne 0 ]        if [ $? -ne 0 ]
496        then        then
497           echo "mpdboot failed."           echo "mpdboot failed."
498           exit 1           exit 1
499        else        else
500            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi
501        fi        fi
502     fi     fi
# Line 510  elif [ "$MPI_FLAVOUR" = "MPT" ] Line 511  elif [ "$MPI_FLAVOUR" = "MPT" ]
511  then  then
512     export MPI_NUM_MEMORY_REGIONS=0     export MPI_NUM_MEMORY_REGIONS=0
513     EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"     EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"
514     if [ ! -z "$HOSTFILE" ]     if [ ! -z "$HOSTFILE" ]
515     then     then
516        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"`
517        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"
518     else     else
519        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
520     fi     fi
521     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
522     $CMD     $CMD
523     EXIT_CODE=$?     EXIT_CODE=$?
524  #=============== MPICH ===================================  #=============== MPICH ===================================
525  elif [ "$MPI_FLAVOUR" = "MPICH" ]  elif [ "$MPI_FLAVOUR" = "MPICH" ]
526  then  then
527     if [ ! -z "$HOSTFILE" ]     if [ ! -z "$HOSTFILE" ]
528     then     then
529        touch "$HOSTFILE2"        touch "$HOSTFILE2"
530        for (( i=1;i<=$ESCRIPT_NUM_PROCS;i+=1 )) ; do cat "$HOSTFILE" >> "$HOSTFILE2"  ; done        for i in `seq $ESCRIPT_NUM_PROCS`; do cat "$HOSTFILE" >> "$HOSTFILE2"; done
531        CMD="mpirun -machinefile \"$HOSTFILE2\"  -np $TOTPROC $EXEC_CMD"        CMD="mpirun -machinefile \"$HOSTFILE2\" -np $TOTPROC $EXEC_CMD"
532     else     else
533        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
534     fi     fi
535     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
536     $CMD     $CMD
537     EXIT_CODE=$?     EXIT_CODE=$?
538  #=============== MPICH2 ===================================  #=============== MPICH2 ===================================
539  elif [ "$MPI_FLAVOUR" = "MPICH2" ]  elif [ "$MPI_FLAVOUR" = "MPICH2" ]
540  then  then
541     if [ ! -z "$HOSTFILE" ]     if [ ! -z "$HOSTFILE" ]
542     then     then
543           mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"           mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"
544           if [ $? -ne 0 ]           if [ $? -ne 0 ]
545           then           then
546              echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."              echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."
547              exit 1              exit 1
548           else           else
549               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
550           fi           fi
551     else     else
552        mpdboot -n 1 -r ssh        mpdboot -n 1 -r ssh
553        if [ $? -ne 0 ]        if [ $? -ne 0 ]
554        then        then
555           echo "mpdboot failed."           echo "mpdboot failed."
556           exit 1           exit 1
557        else        else
558            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi
559        fi        fi
560     fi     fi

Legend:
Removed from v.4667  
changed lines
  Added in v.4927

  ViewVC Help
Powered by ViewVC 1.1.26