/[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 4078 by jfenwick, Fri Nov 16 07:50:49 2012 UTC revision 4993 by sshaw, Thu Jun 5 03:04:56 2014 UTC
# Line 1  Line 1 
1  #!/bin/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 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 28  HOSTFILE2=/tmp/escript2.$USER.$$ Line 28  HOSTFILE2=/tmp/escript2.$USER.$$
28  #Begin finding ESCRIPT_ROOT  #Begin finding ESCRIPT_ROOT
29  if [ $STDLOCATION -ne 0 ]  if [ $STDLOCATION -ne 0 ]
30  then  then
31      ESCRIPT_ROOT=/usr/lib/escript      ESCRIPT_ROOT=/usr/lib/python-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 $(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 71  EXTRA_PYTHONPATH=$ESCRIPT_ROOT Line 71  EXTRA_PYTHONPATH=$ESCRIPT_ROOT
71    
72  if [ $STDLOCATION -eq 1 ]  if [ $STDLOCATION -eq 1 ]
73  then  then
74      EXTRA_LD_LIBRARY_PATH=/usr/lib/escript      EXTRA_LD_LIBRARY_PATH=/usr/lib/python-escript
75  else  else
76      EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib      EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
77  fi  fi
# Line 87  then Line 87  then
87  fi  fi
88    
89    
90  BUILDINFO_FILE=$ESCRIPT_ROOT/lib/buildvars  BUILDINFO_FILE="$ESCRIPT_ROOT/lib/buildvars"
91  if [ "$STDLOCATION" = "1" ]  if [ "$STDLOCATION" = "1" ]
92  then  then
93      BUILDINFO_FILE=/usr/lib/escript/buildvars      BUILDINFO_FILE=/usr/lib/python-escript/buildvars
94  fi  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."
# 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 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
141      -v      print diagnostics      -v      print diagnostics
142      -x      run in new xterm instance      -x      run in new xterm instance
143        -m tool     run with valgrind {tool=m[emcheck]/c[allgrind]}
144      script.py   Your python script      script.py   Your python script
145      arguments...    The optional command-line arguments to your script      arguments...    The optional command-line arguments to your script
146  "  "
# Line 151  fi Line 152  fi
152  #==============================================================================  #==============================================================================
153    
154  # Parse the command-line options  # Parse the command-line options
155  # option e should not be followed by a :  while getopts 'bn:p:t:f:echim:oVvx' option
 while getopts 'bn:p:t:f:hecVviox' option  
156  do  do
157      case "$option" in      case "$option" in
158        "b")  DO_BINARY=y        "b")  DO_BINARY=y
159          ;;          ;;
160          "m")  DO_VALGRIND=$OPTARG
161            ;;
162        "n")  ESCRIPT_NUM_NODES=$OPTARG        "n")  ESCRIPT_NUM_NODES=$OPTARG
163          ;;          ;;
164        "p")  ESCRIPT_NUM_PROCS=$OPTARG        "p")  ESCRIPT_NUM_PROCS=$OPTARG
# Line 165  do Line 167  do
167          ;;          ;;
168        "f")  ESCRIPT_HOSTFILE=$OPTARG        "f")  ESCRIPT_HOSTFILE=$OPTARG
169          ;;          ;;
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 179  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 196  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 216  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"
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 232  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 ]      if [ ! -z "$ESCRIPT_NUM_NODES" ]; then
240      then          if [ $ESCRIPT_NUM_NODES -gt 1 ]; then
241          echo "Warning: MPI disabled but number of nodes set. Option ignored."              echo "Warning: MPI disabled but number of nodes set. Option ignored."
242            fi
243      fi      fi
244      if [ ! -z $ESCRIPT_NUM_PROCS ]      if [ ! -z "$ESCRIPT_NUM_PROCS" ]; then
245      then          if [ $ESCRIPT_NUM_PROCS -gt 1 ]; then
246          echo "Warning: MPI disabled but number of processors per node set. Option ignored."              echo "Warning: MPI disabled but number of processors per node set. Option ignored."
247            fi
248      fi      fi
249      if [ ! -z $ESCRIPT_HOSTFILE ]      if [ ! -z "$ESCRIPT_HOSTFILE" ]
250      then      then
251          echo "Warning: MPI disabled but host file is given. Option ignored."          echo "Warning: MPI disabled but host file is given. Option ignored."
252      fi      fi
# Line 250  then Line 254  then
254      ESCRIPT_NUM_PROCS=1      ESCRIPT_NUM_PROCS=1
255  else  else
256      # use the PBS_NODEFILE if not otherwise specified      # use the PBS_NODEFILE if not otherwise specified
257      if [ ! -z $PBS_NODEFILE ] && [ -z $ESCRIPT_HOSTFILE ]      if [ ! -z "$PBS_NODEFILE" ] && [ -z "$ESCRIPT_HOSTFILE" ]
258      then      then
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 290  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 321  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 336  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" = "yes" ]      if [ "$ESCRIPT_CREATESTDFILES" = "y" ]
346      then      then
347          PYTHON_MPI=$PYTHON_MPI_REDIRECT          PYTHON_MPI=$PYTHON_MPI_REDIRECT
348      else      else
# Line 361  then Line 365  then
365  fi  fi
366    
367  #==============================================================================  #==============================================================================
368    
369  if [ ! -z $DO_XTERM ]  if [ ! -z $DO_XTERM ]
370  then  then
371      EXEC_CMD="xterm -e"      EXEC_CMD="xterm -e"
# Line 368  else Line 373  else
373      EXEC_CMD=""      EXEC_CMD=""
374  fi  fi
375    
376    if [ ! -z "$DO_VALGRIND" ]
377    then
378        VALGRIND_BIN=$(which valgrind 2>/dev/null)
379        if [ $? -eq 0 ]; then
380            LOGDIR=$ESCRIPT_ROOT/valgrind_logs
381            [ -d $LOGDIR ] || mkdir $LOGDIR
382            VG_TOOL=$(echo $DO_VALGRIND | awk '{ s=substr($0,1,1);print s;}')
383            if [ $VG_TOOL = "c" ];
384            then
385                # run callgrind
386                LOGFILE=${LOGDIR}/callgrind.%p.xml
387                VALGRIND="valgrind --tool=callgrind --callgrind-out-file=$LOGFILE"
388                EXEC_CMD="$EXEC_CMD $VALGRIND"
389            else
390                # run memcheck by default
391                LAST_N=$(ls -1 $LOGDIR|grep "^memcheck"|tail -1|cut -d. -f2)
392                NEW_N=$(printf "%04d" $((LAST_N + 1)))
393                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"
395                EXEC_CMD="$EXEC_CMD $VALGRIND"
396            fi
397        else
398            echo "Execution with valgrind requested but valgrind not in path!"
399            exit 1
400        fi
401    fi
402    
403  if [ ! -z $DO_BINARY ]  if [ ! -z $DO_BINARY ]
404  then  then
405      EXEC_CMD="$EXEC_CMD $@"      EXEC_CMD="$EXEC_CMD $@"
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 384  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 420  then Line 452  then
452  fi  fi
453  EXIT_CODE=1  EXIT_CODE=1
454  #=============== no MPI ===================================  #=============== no MPI ===================================
455  if [ "$MPI_FLAVOUR" = "none" ]  if [ "$MPI_FLAVOUR" = "none" ]
456  then  then
457     $EXEC_CMD     $EXEC_CMD
458     EXIT_CODE=$?     EXIT_CODE=$?
459  #=============== OpenMPI ===================================  #=============== OpenMPI ===================================
460  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]
461  then  then
462     if [ ! -z $HOSTFILE ]     EXPORT_ENV=$(echo $EXPORT_ENV|sed -e 's/,/ -x /g')
463       if [ ! -z "$HOSTFILE" ]
464     then     then
465        HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`        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//,/ -x } --bynode -np $TOTPROC --bind-to-socket --cpus-per-rank $ESCRIPT_NUM_THREADS --host $HOST_LIST $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//,/ -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"
469     fi     fi
470     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
471     $CMD     $CMD
472     EXIT_CODE=$?     EXIT_CODE=$?
# Line 445  then Line 478  then
478     if [ "$WITH_OPENMP" = "1" ]     if [ "$WITH_OPENMP" = "1" ]
479     then     then
480         export I_MPI_PIN_DOMAIN=omp         export I_MPI_PIN_DOMAIN=omp
481         EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"         EXPORT_ENV="$EXPORT_ENV,I_MPI_PIN_DOMAIN"
482     fi     fi
483    
484     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
485     then     then
486        mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE          CMD="mpirun -hostfile $HOSTFILE -n $TOTPROC -ppn $ESCRIPT_NUM_PROCS $EXEC_CMD"
       if [ $? -ne 0 ]  
       then  
          echo "mpdboot with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes failed."  
          exit 1  
       else  
           if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started with host file $ESCRIPT_HOSTFILE for $ESCRIPT_NUM_NODES nodes."; fi  
       fi  
487     else     else
488        mpdboot -n 1 -r ssh          if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Empty hostfile, running on single node"; fi
489        if [ $? -ne 0 ]          CMD="mpirun -n 1 -ppn $ESCRIPT_NUM_PROCS $EXEC_CMD"
       then  
          echo "mpdboot failed."  
          exit 1  
       else  
           if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi  
       fi  
490     fi     fi
    CMD="mpiexec -perhost $ESCRIPT_NUM_PROCS -envall -n $TOTPROC $EXEC_CMD"  
491     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
492     $CMD     $CMD
493     EXIT_CODE=$?     EXIT_CODE=$?
    mpdallexit  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi  
494  #=============== SGI's MPIMPT ===================================  #=============== SGI's MPIMPT ===================================
495  elif [ "$MPI_FLAVOUR" = "MPT" ]  elif [ "$MPI_FLAVOUR" = "MPT" ]
496  then  then
497     export MPI_NUM_MEMORY_REGIONS=0     export MPI_NUM_MEMORY_REGIONS=0
498     EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"     EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"
499     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
500     then     then
501        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")
502        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"
503     else     else
504        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
505     fi     fi
506     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
507     $CMD     $CMD
508     EXIT_CODE=$?     EXIT_CODE=$?
509  #=============== MPICH ===================================  #=============== MPICH ===================================
510  elif [ "$MPI_FLAVOUR" = "MPICH" ]  elif [ "$MPI_FLAVOUR" = "MPICH" ]
511  then  then
512     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
513     then     then
514        touch $HOSTFILE2        touch "$HOSTFILE2"
515        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
516        CMD="mpirun -machinefile $HOSTFILE2  -np $TOTPROC $EXEC_CMD"        CMD="mpirun -machinefile \"$HOSTFILE2\" -np $TOTPROC $EXEC_CMD"
517     else     else
518        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
519     fi     fi
520     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
521     $CMD     $CMD
522     EXIT_CODE=$?     EXIT_CODE=$?
523  #=============== MPICH2 ===================================  #=============== MPICH2 ===================================
524  elif [ "$MPI_FLAVOUR" = "MPICH2" ]  elif [ "$MPI_FLAVOUR" = "MPICH2" ]
525  then  then
526     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
527     then     then
528           mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE           mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"
529           if [ $? -ne 0 ]           if [ $? -ne 0 ]
530           then           then
531              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."
532              exit 1              exit 1
533           else           else
534               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
535           fi           fi
536     else     else
537        mpdboot -n 1 -r ssh        mpdboot -n 1 -r ssh
538        if [ $? -ne 0 ]        if [ $? -ne 0 ]
539        then        then
540           echo "mpdboot failed."           echo "mpdboot failed."
541           exit 1           exit 1
542        else        else
543            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi
544        fi        fi
545     fi     fi
# Line 535  then Line 552  then
552  else  else
553     echo "unknown MPI flavour '$MPI_FLAVOUR'."     echo "unknown MPI flavour '$MPI_FLAVOUR'."
554  fi  fi
555    
556    if [ ! -z "$DO_VALGRIND" ]; then
557       echo "Valgrind log file written to ${LOGFILE}"
558    fi
559    
560  exit $EXIT_CODE  exit $EXIT_CODE
561    

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

  ViewVC Help
Powered by ViewVC 1.1.26