/[escript]/trunk/run-escript.in
ViewVC logotype

Diff of /trunk/run-escript.in

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

revision 4927 by caltinay, Fri May 2 02:47:44 2014 UTC revision 4973 by sshaw, Wed May 28 06:02:38 2014 UTC
# Line 17  STDLOCATION=0 Line 17  STDLOCATION=0
17  #Now we find the location of this script  #Now we find the location of this script
18  #Note that this location should be absolute but does not need to be unique  #Note that this location should be absolute but does not need to be unique
19  scriptdir=""  scriptdir=""
20  CURDIR=`pwd`  CURDIR=$(pwd)
21    
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
# Line 35  else Line 35  else
35    if $(echo $0|grep -q /)    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
46            echo "Error! Unable to determine script directory. Exiting."            echo "Error! Unable to determine script directory. Exiting."
47            exit 1            exit 1
48        fi        fi
49        scriptdir=`dirname $tscriptdir`        scriptdir=$(dirname $tscriptdir)
50    fi    fi
51    
52    cd "$scriptdir/.."    cd "$scriptdir/.."
53    ESCRIPT_ROOT=`pwd`    ESCRIPT_ROOT=$(pwd)
54    cd ..    cd ..
55    ESCRIPT_PARENT=`pwd`    ESCRIPT_PARENT=$(pwd)
56    cd "$CURDIR"    cd "$CURDIR"
57    
58  fi  fi
# Line 97  if [ ! -r "$BUILDINFO_FILE" ]; then Line 97  if [ ! -r "$BUILDINFO_FILE" ]; 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
# Line 108  if [ ! -r "$BUILDINFO_FILE" ]; then Line 108  if [ ! -r "$BUILDINFO_FILE" ]; then
108  fi  fi
109    
110  get_buildvar () {  get_buildvar () {
111      echo `grep "^$1=" "$BUILDINFO_FILE" |cut -d= -f2`      echo $(grep "^$1=" "$BUILDINFO_FILE" |cut -d= -f2)
112  }  }
113    
114  #  #
115  #   Add VisIt paths if required  #   Add VisIt paths if required
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 2>/dev/null`      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
123          EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$VISIT_PY_PATH          EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$VISIT_PY_PATH
124      elif [ ! -z $ESCRIPT_VERBOSE ]; then      elif [ ! -z $ESCRIPT_VERBOSE ]; then
# Line 170  do Line 170  do
170        "c")  cat "$BUILDINFO_FILE"        "c")  cat "$BUILDINFO_FILE"
171          exit 0          exit 0
172          ;;          ;;
173        "V")  echo "escript-development(build "`get_buildvar svn_revision`")"        "V")  echo "escript-development(build "$(get_buildvar svn_revision)")"
174          exit 0          exit 0
175          ;;          ;;
176        "h")  echo "$HELP_TEXT"        "h")  echo "$HELP_TEXT"
# Line 181  do Line 181  do
181        "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"
182          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
183          echo "export PATH=$EXTRA_PATH:\$PATH"          echo "export PATH=$EXTRA_PATH:\$PATH"
184          if [ "`uname`" = "Darwin" ]          if [ "$(uname)" = "Darwin" ]
185          then          then
186              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"
187          fi          fi
# Line 198  do Line 198  do
198          ;;          ;;
199      esac      esac
200  done  done
201  shift `expr $OPTIND - 1`  shift $(($OPTIND - 1))
202  #==============================================  #==============================================
203  #  #
204  #   Read MPI_FLAVOUR and WITH_OPENMP from the buildvars  #   Read MPI_FLAVOUR and WITH_OPENMP from the buildvars
205  #  #
206  MPI_FLAVOUR=`get_buildvar mpi`  MPI_FLAVOUR=$(get_buildvar mpi)
207  WITH_OPENMP=`get_buildvar openmp`  WITH_OPENMP=$(get_buildvar openmp)
208    
209  if [ ! -z $ESCRIPT_VERBOSE ]; then  if [ ! -z $ESCRIPT_VERBOSE ]; then
210      echo "MPI flavour is $MPI_FLAVOUR."      echo "MPI flavour is $MPI_FLAVOUR."
# Line 218  export PATH=$EXTRA_PATH:$PATH Line 218  export PATH=$EXTRA_PATH:$PATH
218  export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH  export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
219  export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH  export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
220  EXPORT_ENV="PATH,LD_LIBRARY_PATH,PYTHONPATH"  EXPORT_ENV="PATH,LD_LIBRARY_PATH,PYTHONPATH"
221  if [ "`uname`" = "Darwin" ]  if [ "$(uname)" = "Darwin" ]
222  then  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"
# Line 264  else Line 264  else
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 ]
# Line 375  fi Line 375  fi
375    
376  if [ ! -z "$DO_VALGRIND" ]  if [ ! -z "$DO_VALGRIND" ]
377  then  then
378      VALGRIND_BIN=`which valgrind 2>/dev/null`      VALGRIND_BIN=$(which valgrind 2>/dev/null)
379      if [ $? -eq 0 ]; then      if [ $? -eq 0 ]; then
380          LOGDIR=$ESCRIPT_ROOT/valgrind_logs          LOGDIR=$ESCRIPT_ROOT/valgrind_logs
381          [ -d $LOGDIR ] || mkdir $LOGDIR          [ -d $LOGDIR ] || mkdir $LOGDIR
382          if [ ${DO_VALGRIND:0:1} = "c" ];          VG_TOOL=$(echo $DO_VALGRIND | awk '{ s=substr($0,1,1);print s;}')
383            if [ $VG_TOOL = "c" ];
384          then          then
385              # run callgrind              # run callgrind
386              LOGFILE=${LOGDIR}/callgrind.%p.xml              LOGFILE=${LOGDIR}/callgrind.%p.xml
# Line 387  then Line 388  then
388              EXEC_CMD="$EXEC_CMD $VALGRIND"              EXEC_CMD="$EXEC_CMD $VALGRIND"
389          else          else
390              # run memcheck by default              # run memcheck by default
391              LAST_N=`ls -1 $LOGDIR|grep "^memcheck"|tail -1|cut -d. -f2`              LAST_N=$(ls -1 $LOGDIR|grep "^memcheck"|tail -1|cut -d. -f2)
392              NEW_N=`printf "%04d" $((10#$LAST_N + 1))`              NEW_N=$(printf "%04d" $((LAST_N + 1)))
393              LOGFILE=${LOGDIR}/memcheck.${NEW_N}.xml              LOGFILE=${LOGDIR}/memcheck.${NEW_N}.xml
394              VALGRIND="valgrind --tool=memcheck --xml=yes --show-reachable=yes --error-limit=no --gen-suppressions=all --suppressions=$ESCRIPT_ROOT/scripts/escript.supp --leak-check=full --xml-file=$LOGFILE"              VALGRIND="valgrind --tool=memcheck --xml=yes --show-reachable=yes --error-limit=no --gen-suppressions=all --suppressions=$ESCRIPT_ROOT/scripts/escript.supp --leak-check=full --xml-file=$LOGFILE"
395              EXEC_CMD="$EXEC_CMD $VALGRIND"              EXEC_CMD="$EXEC_CMD $VALGRIND"
# Line 405  then Line 406  then
406  else  else
407      # 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
408      # one of PYTHON_CMD.      # one of PYTHON_CMD.
409      compfull=`get_buildvar python_version`      compfull=$(get_buildvar python_version)
410      compversion=`echo $compfull | cut -d. -f1,2`      compversion=$(echo $compfull | cut -d. -f1,2)
411      compmajor=`echo $compfull | cut -d. -f1`      compmajor=$(echo $compfull | cut -d. -f1)
412      if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they      if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they
413      then                                # might not want us changing it      then                                # might not want us changing it
414          if [ "$compmajor" = "3" ]          if [ "$compmajor" = "3" ]
# Line 415  else Line 416  else
416              PYTHON_CMD=python3              PYTHON_CMD=python3
417          fi          fi
418      fi      fi
419      intversion=`$PYTHON_CMD -c 'from __future__ import print_function;import sys;print("%d.%d"%(sys.version_info[0], sys.version_info[1]))'`      intversion=$($PYTHON_CMD -c 'from __future__ import print_function;import sys;print("%d.%d"%(sys.version_info[0], sys.version_info[1]))')
420      if [ "$compversion" != "$intversion" ]      if [ "$compversion" != "$intversion" ]
421      then      then
422          echo "Python versions do not match. Escript was compiled for "$compversion"."          echo "Python versions do not match. Escript was compiled for "$compversion"."
# Line 461  then Line 462  then
462     EXPORT_ENV=$(echo $EXPORT_ENV|sed -e 's/,/ -x /g')     EXPORT_ENV=$(echo $EXPORT_ENV|sed -e 's/,/ -x /g')
463     if [ ! -z "$HOSTFILE" ]     if [ ! -z "$HOSTFILE" ]
464     then     then
465        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}')
466        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV} --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"
467     else     else
468        CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV} --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"
# Line 485  then Line 486  then
486        mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"        mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"
487        if [ $? -ne 0 ]        if [ $? -ne 0 ]
488        then        then
489           echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."           echo "mpdboot with host file $HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."
490           exit 1           exit 1
491        else        else
492            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 $HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi
493        fi        fi
494     else     else
495        mpdboot -n 1 -r ssh        mpdboot -n 1 -r ssh
# Line 513  then Line 514  then
514     EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"     EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"
515     if [ ! -z "$HOSTFILE" ]     if [ ! -z "$HOSTFILE" ]
516     then     then
517        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")
518        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"
519     else     else
520        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
# Line 527  then Line 528  then
528     if [ ! -z "$HOSTFILE" ]     if [ ! -z "$HOSTFILE" ]
529     then     then
530        touch "$HOSTFILE2"        touch "$HOSTFILE2"
531        for i in `seq $ESCRIPT_NUM_PROCS`; do cat "$HOSTFILE" >> "$HOSTFILE2"; done        for i in $(seq $ESCRIPT_NUM_PROCS); do cat "$HOSTFILE" >> "$HOSTFILE2"; done
532        CMD="mpirun -machinefile \"$HOSTFILE2\" -np $TOTPROC $EXEC_CMD"        CMD="mpirun -machinefile \"$HOSTFILE2\" -np $TOTPROC $EXEC_CMD"
533     else     else
534        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
# Line 543  then Line 544  then
544           mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"           mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"
545           if [ $? -ne 0 ]           if [ $? -ne 0 ]
546           then           then
547              echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."              echo "mpdboot with host file $HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."
548              exit 1              exit 1
549           else           else
550               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 $HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi
551           fi           fi
552     else     else
553        mpdboot -n 1 -r ssh        mpdboot -n 1 -r ssh
# Line 567  then Line 568  then
568  else  else
569     echo "unknown MPI flavour '$MPI_FLAVOUR'."     echo "unknown MPI flavour '$MPI_FLAVOUR'."
570  fi  fi
571    
572    if [ ! -z "$DO_VALGRIND" ]; then
573       echo "Valgrind log file written to ${LOGFILE}"
574    fi
575    
576  exit $EXIT_CODE  exit $EXIT_CODE
577    

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

  ViewVC Help
Powered by ViewVC 1.1.26