/[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 3056 by jfenwick, Mon Jul 5 00:07:16 2010 UTC revision 5239 by caltinay, Thu Oct 30 05:36:00 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
24    
25    #set up thread binding if unset
26    if [ "$OMP_PROC_BIND" = "" ]; then
27        #Force OpenMP binding for Intel (and GCC, though GCC is on by default)
28        export OMP_PROC_BIND=true
29    fi
30    if [ "$KMP_AFFINITY" = "" ]; then
31        #Set the style of binding (overrides OMP_PROC_BIND in many cases)
32        export KMP_AFFINITY=verbose,compact
33    fi
34    
35  HOSTFILE=/tmp/escript.$USER.$$  HOSTFILE=/tmp/escript.$USER.$$
36  HOSTFILE2=/tmp/escript2.$USER.$$  HOSTFILE2=/tmp/escript2.$USER.$$
37    
38  #Begin finding ESCRIPT_ROOT  #Begin finding ESCRIPT_ROOT
39  if [ $STDLOCATION -ne 0 ]  if [ $STDLOCATION -ne 0 ]
40  then  then
41      ESCRIPT_ROOT=/usr/lib/escript      ESCRIPT_ROOT=/usr/lib/python-escript
42  else  else
43    #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
44    #Need to match if the name contains /    # Need to match if the name contains /
45    if [[ $0 =~ / ]]    if $(echo $0|grep -q /)
46    then    then
47        # We are not using the PATH to find the script        # We are not using the PATH to find the script
48        cd `dirname $0`        cd "$(dirname $0)"
49        scriptdir=`pwd`        scriptdir=$(pwd)
50        cd $CURDIR        cd "$CURDIR"
51    else    else
52        # name does not contain / therefore we are using        # name does not contain / therefore we are using
53        tscriptdir=`which $0`        tscriptdir=$(which $0)
54        if [ $? != 0 ]        if [ $? -ne 0 ]
55        then        then
56            echo "Error! Unable to determine script directory. Exiting."            echo "Error! Unable to determine script directory. Exiting."
57            exit 1            exit 1
58        fi        fi
59        scriptdir=`dirname $tscriptdir`        scriptdir=$(dirname $tscriptdir)
60    fi    fi
61    
62    cd $scriptdir/..    cd "$scriptdir/.."
63    ESCRIPT_ROOT=`pwd`    ESCRIPT_ROOT=$(pwd)
64    cd ..    cd ..
65    ESCRIPT_PARENT=`pwd`    ESCRIPT_PARENT=$(pwd)
66    cd $CURDIR    cd "$CURDIR"
   
 fi  
 ##### End finding ESCRIPT_ROOT  ########  
67    
 if [ ! -r $ESCRIPT_ROOT/lib/buildvars ]; then  
     echo "Error! Unable to read escript build information. Exiting."  
     exit 1  
68  fi  fi
69    ##### End finding ESCRIPT_ROOT ########
70    
71  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"
72  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"
# Line 73  PYTHON_CMD=python Line 78  PYTHON_CMD=python
78  EXTRA_DYLD_LIBRARY_PATH=""  EXTRA_DYLD_LIBRARY_PATH=""
79  EXTRA_PATH=$ESCRIPT_ROOT/bin  EXTRA_PATH=$ESCRIPT_ROOT/bin
80  EXTRA_PYTHONPATH=$ESCRIPT_ROOT  EXTRA_PYTHONPATH=$ESCRIPT_ROOT
81  EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib  
82    if [ $STDLOCATION -eq 1 ]
83    then
84        EXTRA_LD_LIBRARY_PATH=/usr/lib/python-escript
85    else
86        EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
87    fi
88    
89    
90  if [ $STANDALONE -eq 1 ]  if [ $STANDALONE -eq 1 ]
91  then  then
92      EXTRA_PATH=$ESCRIPT_PARENT/pkg/python/bin:$EXTRA_PATH      EXTRA_PATH=$ESCRIPT_PARENT/pkg/python/bin:$ESCRIPT_PARENT/pkg/scons/bin:$EXTRA_PATH
93      EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/pkg/boost/lib:$ESCRIPT_PARENT/pkg/netcdf/lib/:$EXTRA_LD_LIBRARY_PATH      EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/pkg/boost/lib:$ESCRIPT_PARENT/pkg/netcdf/lib/:$EXTRA_LD_LIBRARY_PATH
94      EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH      EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH
95      EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/pkg/python/lib:$EXTRA_LD_LIBRARY_PATH      EXTRA_LD_LIBRARY_PATH=$ESCRIPT_PARENT/pkg/python/lib:$EXTRA_LD_LIBRARY_PATH
# Line 85  then Line 97  then
97  fi  fi
98    
99    
100    BUILDINFO_FILE="$ESCRIPT_ROOT/lib/buildvars"
101    if [ "$STDLOCATION" = "1" ]
102    then
103        BUILDINFO_FILE=/usr/lib/python-escript/buildvars
104    fi
105    if [ ! -r "$BUILDINFO_FILE" ]; then
106        if [ "$1" = "-e" ]; then
107            echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
108            echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
109            echo "export PATH=$EXTRA_PATH:\$PATH"
110            if [ "$(uname)" = "Darwin" ]
111            then
112                echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
113            fi
114            exit 0
115        fi
116        echo "Error! Unable to read escript build information. Exiting."
117        exit 1
118    fi
119    
120    get_buildvar () {
121        echo $(grep "^$1=" "$BUILDINFO_FILE" |cut -d= -f2)
122    }
123    
124    #
125    #   Add VisIt paths if required
126    #
127    WITH_VISIT=$(get_buildvar visit)
128    if [ "$WITH_VISIT" = "1" ]; then
129        VISIT_BIN=$(which visit 2>/dev/null)
130        if [ $? -eq 0 ]; then
131            VISIT_PY_PATH=$($VISIT_BIN -env | grep LIBPATH | cut -d= -f2)
132            EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH
133            EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$VISIT_PY_PATH
134        elif [ ! -z $ESCRIPT_VERBOSE ]; then
135            echo "VisIt module enabled but VisIt not in path!"
136        fi
137    fi
138    
139  HELP_TEXT="  HELP_TEXT="
140  Usage: escript [options] script.py [arguments...]  Usage: run-escript [options] script.py [arguments...]
141      -n nn       number of nodes to use      -n nn       number of nodes to use
142      -p np       number of MPI processes to spawn      -p np       number of MPI processes to spawn per node
143      -t nt       number of OpenMP threads to use      -t nt       number of OpenMP threads to use
144      -f file     name of MPI hostfile      -f file     name of MPI hostfile
145      -c      print compile information for escript and exit      -c      print compile information for escript and exit
146      -V      print escript version and exit      -V      print escript version and exit
147      -i      interactive mode      -i      interactive mode
148      -b      do not invoke python (run non-python programs)      -b      do not invoke python (run non-python programs)
149      -e      print export statements for environment and exit      -e      print export statements for environment and exit
150      -o      redirect output from MPI to files      -o      redirect output from MPI to files
151      -v      print diagnostics      -v      print diagnostics
152      -x      ..reserved for future use ..      -x      run in new xterm instance
153        -m tool     run with valgrind {tool=m[emcheck]/c[allgrind]/[cac]h[egrind]}
154      script.py   Your python script      script.py   Your python script
155      arguments...    The optional command-line arguments to your script      arguments...    The optional command-line arguments to your script
156  "  "
# Line 108  if [ "$1" = "--help" ]; then Line 159  if [ "$1" = "--help" ]; then
159    echo "$HELP_TEXT"    echo "$HELP_TEXT"
160    exit 0    exit 0
161  fi  fi
162  #=======================================================================================  #==============================================================================
   
 # Avoid bug in hybrid runs with MPT MPI  
   
163    
164  # Parse the command-line options  # Parse the command-line options
165  # option e should not be followed by a :  while getopts 'bn:p:t:f:echim:oVvx' option
 while getopts 'bn:p:t:f:h:ecVviox' option  
166  do  do
167      case "$option" in      case "$option" in
168        "b")  DOBINARY=yes        "b")  DO_BINARY=y
169          ;;          ;;
170        "n")  ESCRIPT_NUM_NODES=$OPTARG        "m")  DO_VALGRIND=$OPTARG
171          ;;          ;;
172        "p")  ESCRIPT_NUM_PROCS=$OPTARG        "n")  ESCRIPT_NUM_NODES=$OPTARG
173          ;;          ;;
174        "t")  ESCRIPT_NUM_THREADS=$OPTARG        "p")  ESCRIPT_NUM_PROCS=$OPTARG
175          ;;          ;;
176        "f")  ESCRIPT_HOSTFILE=$OPTARG        "t")  ESCRIPT_NUM_THREADS=$OPTARG
177          ;;          ;;
178        "c")  cat $ESCRIPT_ROOT/lib/buildvars        "f")  ESCRIPT_HOSTFILE=$OPTARG
179          exit 0          ;;
180          ;;        "c")  cat "$BUILDINFO_FILE"
181        "V")  echo "escript-development(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"          exit 0
182          exit 0          ;;
183          ;;        "V")  echo "escript-development(build "$(get_buildvar svn_revision)")"
184        "h")  echo "$HELPTEXT"          exit 0
185          exit 0          ;;
186          ;;        "h")  echo "$HELP_TEXT"
187        "i")  DOINTERACTIVE=yes          exit 0
188          ;;          ;;
189        "e")  echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"        "i")  DO_INTERACTIVE=y
190          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"          ;;
191          echo "export PATH=$EXTRA_PATH:\$PATH"        "e")  echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
192          if [ "`uname`" = "Darwin" ]          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
193          then          echo "export PATH=$EXTRA_PATH:\$PATH"
194              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"          if [ "$(uname)" = "Darwin" ]
195          fi          then
196          exit 0              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
197          ;;          fi
198        "o")  ESCRIPT_CREATESTDFILES="yes"          exit 0
199          ;;          ;;
200        "v")  ESCRIPT_VERBOSE="yes"        "o")  ESCRIPT_CREATESTDFILES=y
201          ;;          ;;
202        "x")  echo "-x not implemented yet"        "v")  ESCRIPT_VERBOSE=y
203          exit 1          ;;
204          ;;        "x")  DO_XTERM=y
205        ?)    echo "$HELP_TEXT"          ;;
206          exit 1        ?)    echo "$HELP_TEXT"
207          ;;          exit 1
208      esac          ;;
209        esac
210  done  done
211  shift `expr $OPTIND - 1`  shift $(($OPTIND - 1))
212  #==============================================  #==============================================
213  #  #
214  #   Read the MPI_FLAVOUR from the buildvars  #   Read MPI_FLAVOUR and WITH_OPENMP from the buildvars
215  #  #
216  MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  MPI_FLAVOUR=$(get_buildvar mpi)
217  WITH_OPENMP=`grep useopenmp $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  WITH_OPENMP=$(get_buildvar openmp)
218    
219  if [ ! -z $ESCRIPT_VERBOSE ]; then  if [ ! -z $ESCRIPT_VERBOSE ]; then
220      echo "MPI flavour is $MPI_FLAVOUR."      echo "MPI flavour is $MPI_FLAVOUR."
221      if [ "$WITH_OPENMP" = "y" ]; then echo "OpenMP enabled."; fi      if [ "$WITH_OPENMP" = "1" ]; then echo "OpenMP enabled."; fi
222  fi  fi
223    
224  #  #
# Line 180  export PATH=$EXTRA_PATH:$PATH Line 228  export PATH=$EXTRA_PATH:$PATH
228  export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH  export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
229  export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH  export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
230  EXPORT_ENV="PATH,LD_LIBRARY_PATH,PYTHONPATH"  EXPORT_ENV="PATH,LD_LIBRARY_PATH,PYTHONPATH"
231  if [ "`uname`" = "Darwin" ]  if [ "$(uname)" = "Darwin" ]
232  then  then
233      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
234      EXPORT_ENV="$EXPORT_ENV,DYLD_LIBRARY_PATH"      EXPORT_ENV="$EXPORT_ENV,DYLD_LIBRARY_PATH"
235  fi  fi
236  if [ ! -z $ESCRIPT_VERBOSE ]  if [ ! -z $ESCRIPT_VERBOSE ]
237  then  then
238      echo "PATH = $PATH "      echo "PATH = $PATH "
239      echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "      echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "
240      echo "PYTHONPATH = $PYTHONPATH "      echo "PYTHONPATH = $PYTHONPATH "
# Line 196  fi Line 244  fi
244  #  #
245  #  Ensure the variables have sensible values  #  Ensure the variables have sensible values
246  #  #
247  if [ "$MPI_FLAVOUR" = "none" ]  if [ "$MPI_FLAVOUR" = "none" ]
248  then  then
249      if [ ! -z $ESCRIPT_NUM_NODES ]      if [ ! -z "$ESCRIPT_NUM_NODES" ]; then
250      then          if [ $ESCRIPT_NUM_NODES -gt 1 ]; then
251          echo "Warning: MPI disabled but number of nodes set. Option ignored."              echo "Warning: MPI disabled but number of nodes set. Option ignored."
252            fi
253      fi      fi
254      if [ ! -z $ESCRIPT_NUM_PROCS ]      if [ ! -z "$ESCRIPT_NUM_PROCS" ]; then
255      then          if [ $ESCRIPT_NUM_PROCS -gt 1 ]; then
256          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."
257            fi
258      fi      fi
259      if [ ! -z $ESCRIPT_HOSTFILE ]      if [ ! -z "$ESCRIPT_HOSTFILE" ]
260      then      then
261          echo "Warning: MPI disabled but host file is given. Option ignored."          echo "Warning: MPI disabled but host file is given. Option ignored."
262      fi      fi
# Line 214  then Line 264  then
264      ESCRIPT_NUM_PROCS=1      ESCRIPT_NUM_PROCS=1
265  else  else
266      # use the PBS_NODEFILE if not otherwise specified      # use the PBS_NODEFILE if not otherwise specified
267      if [[ ( ! -z $PBS_NODEFILE ) && ( -z $ESCRIPT_HOSTFILE ) ]]      if [ ! -z "$PBS_NODEFILE" ] && [ -z "$ESCRIPT_HOSTFILE" ]
268      then      then
269      ESCRIPT_HOSTFILE=$PBS_NODEFILE          ESCRIPT_HOSTFILE=$PBS_NODEFILE
   
270      fi      fi
271    
272      if [ ! -z $ESCRIPT_HOSTFILE ]      if [ ! -z "$ESCRIPT_HOSTFILE" ]
273      then      then
274          if [ -f $ESCRIPT_HOSTFILE ]          if [ -f "$ESCRIPT_HOSTFILE" ]
275          then          then
276              cat $ESCRIPT_HOSTFILE | sort -u > $HOSTFILE              cat "$ESCRIPT_HOSTFILE" | sort -u > $HOSTFILE
277              NUM_HOSTS=`cat $HOSTFILE | wc -l`              NUM_HOSTS=$(cat "$HOSTFILE" | wc -l)
278              if [ ! -z $ESCRIPT_NUM_NODES ]              if [ ! -z $ESCRIPT_NUM_NODES ]
279              then              then
280                  if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]                  if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]
281                  then                  then
# Line 246  else Line 295  else
295    
296      if [ -z $ESCRIPT_NUM_NODES ]      if [ -z $ESCRIPT_NUM_NODES ]
297      then      then
298        ESCRIPT_NUM_NODES=1          ESCRIPT_NUM_NODES=1
299      fi      fi
300    
301      if [ -z $ESCRIPT_NUM_PROCS ]      if [ -z $ESCRIPT_NUM_PROCS ]
302      then      then
303        ESCRIPT_NUM_PROCS=1          ESCRIPT_NUM_PROCS=1
304      fi      fi
305    
306      if [ ! -z $ESCRIPT_VERBOSE ]      if [ ! -z $ESCRIPT_VERBOSE ]
307      then      then
308            echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "          echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "
309            echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "          echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "
310      fi      fi
311  fi  fi
312    
313  if [ "$WITH_OPENMP" = "y" ]  if [ "$WITH_OPENMP" = "1" ]
314  then  then
315     if [ -z $ESCRIPT_NUM_THREADS ]     if [ -z $ESCRIPT_NUM_THREADS ]
316     then     then
# Line 276  then Line 325  then
325          echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."          echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."
326     fi     fi
327  else  else
328     if [[ ( ! -z $ESCRIPT_NUM_THREADS ) && ( $ESCRIPT_NUM_THREADS != 1 ) ]]     if [ ! -z $ESCRIPT_NUM_THREADS ] && [ $ESCRIPT_NUM_THREADS != 1 ]
329     then     then
330         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."
331     fi     fi
# Line 285  fi Line 334  fi
334  #  #
335  # Now we compute total number of Processes  # Now we compute total number of Processes
336  #  #
337  (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))  TOTPROC=$((ESCRIPT_NUM_NODES * ESCRIPT_NUM_PROCS))
338  if [ $? -ne 0 ]     #Some compute error  if [ $? -ne 0 ]     #Some compute error
339  then            #This could happen if the args were not a number  then            #This could happen if the args were not a number
340    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."
341    exit 1      exit 1
342  fi  fi
343    
344  #  #
345  # 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
346  #  #
347  if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]  if ([ ! -z $DO_INTERACTIVE ] || [ $# -eq 0 ]) && ([ $TOTPROC -gt 1 ])
348  then  then
349    echo "Interactive mode cannot be used with more than one process"      echo "Interactive mode cannot be used with more than one process"
350    exit 1      exit 1
351  fi  fi
352    
353  if [ $TOTPROC -gt 1 ]  if [ $TOTPROC -gt 1 ]
354  then  then
355     if [ "$ESCRIPT_CREATESTDFILES" = "yes" ]      if [ "$ESCRIPT_CREATESTDFILES" = "y" ]
356     then      then
357         PYTHON_MPI=$PYTHON_MPI_REDIRECT          PYTHON_MPI=$PYTHON_MPI_REDIRECT
358     else      else
359         PYTHON_MPI=$PYTHON_MPI_NULL          PYTHON_MPI=$PYTHON_MPI_NULL
360     fi      fi
361  else  else
362      PYTHON_MPI=$PYTHON_MPI_NULL      PYTHON_MPI=$PYTHON_MPI_NULL
363  fi  fi
364  #=========================================================================================================  #==============================================================================
365  # Must have at least one command-line arg: the python script  # Must have at least one command-line arg: the python script
366  if [ $# -eq 0 ]  if [ $# -eq 0 ]
367  then  then
368    if [ ! -z $DOBINARY ]      if [ ! -z $DO_BINARY ]
369    then      then
370      echo "No program to run was specified. Exiting."          echo "No program to run was specified. Exiting."
371      exit 1          exit 1
372    fi      else
373            DO_INTERACTIVE=y
374        fi
375  fi  fi
376  if [ -z $@ ]  
377    #==============================================================================
378    
379    if [ ! -z $DO_XTERM ]
380  then  then
381     if [ ! -z $DOBINARY ]      EXEC_CMD="xterm -e"
382     then  else
383         echo "Program must be given."      EXEC_CMD=""
384         exit 1  fi
385     else  
386        DOINTERACTIVE="yes"  if [ ! -z "$DO_VALGRIND" ]
387     fi  then
388        VALGRIND_BIN=$(which valgrind 2>/dev/null)
389        if [ $? -eq 0 ]; then
390            LOGDIR=$ESCRIPT_ROOT/valgrind_logs
391            [ -d $LOGDIR ] || mkdir $LOGDIR
392            VG_TOOL=$(echo $DO_VALGRIND | awk '{ s=substr($0,1,1);print s;}')
393            if [ $VG_TOOL = "c" ];
394            then
395                # run callgrind
396                LOGFILE=${LOGDIR}/callgrind.%p.xml
397                VALGRIND="valgrind --tool=callgrind --callgrind-out-file=$LOGFILE"
398                EXEC_CMD="$EXEC_CMD $VALGRIND"
399            elif [ $VG_TOOL = "h" ];
400            then
401                # run cachegrind
402                LOGFILE=${LOGDIR}/cachegrind.%p.xml
403                VALGRIND="valgrind --tool=cachegrind --cachegrind-out-file=$LOGFILE"
404                EXEC_CMD="$EXEC_CMD $VALGRIND"
405            else
406                # run memcheck by default
407                LAST_N=$(ls -1 $LOGDIR|grep "^memcheck"|tail -1|cut -d. -f2)
408                NEW_N=$(printf "%04d" $((LAST_N + 1)))
409                LOGFILE=${LOGDIR}/memcheck.${NEW_N}.xml
410                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"
411                EXEC_CMD="$EXEC_CMD $VALGRIND"
412            fi
413        else
414            echo "Execution with valgrind requested but valgrind not in path!"
415            exit 1
416        fi
417  fi  fi
418    
419  #=========================================================================================================  if [ ! -z $DO_BINARY ]
 if [ ! -z $DOBINARY ]  
420  then  then
421      EXEC_CMD="$@"      EXEC_CMD="$EXEC_CMD $@"
422  else  else
423      if [ "$MPI_FLAVOUR" = "none" ]      # Check to see if the python version we were compiled with matches the
424      then      # one of PYTHON_CMD.
425          # Check to see if the python version we were compiled with matches the one of EXEC_CMD      compfull=$(get_buildvar python_version)
426          # We should only do this check if they are running a python script      compversion=$(echo $compfull | cut -d. -f1,2)
427          if [ -f $ESCRIPT_ROOT/lib/pyversion ]      compmajor=$(echo $compfull | cut -d. -f1)
428        if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they
429        then                                # might not want us changing it
430            if [ "$compmajor" = "3" ]
431          then          then
432             compversion=`cat $ESCRIPT_ROOT/lib/pyversion`              PYTHON_CMD=python3
            intversion=`$PYTHON_CMD -V 2>&1`  
            if [ "$compversion" != "$intversion" ]  
            then  
               echo "Python versions do not match. Escript was compiled for "$compversion"."  
               echo "Current version of Python appears to be "$intversion"."  
               exit 1  
            fi  
433          fi          fi
434      if [ ! -z $DOINTERACTIVE ]      fi
435        intversion=$($PYTHON_CMD -c 'from __future__ import print_function;import sys;print("%d.%d"%(sys.version_info[0], sys.version_info[1]))')
436        if [ "$compversion" != "$intversion" ]
437        then
438            echo "Python versions do not match. Escript was compiled for "$compversion"."
439            echo "Current version of Python appears to be "$intversion"."
440            exit 1
441        fi
442        if [ "$MPI_FLAVOUR" = "none" ]
443        then
444            if [ ! -z $DO_INTERACTIVE ]
445          then          then
446             EXEC_CMD="$PYTHON_CMD -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD -i $@"
447          else          else
448             EXEC_CMD="$PYTHON_CMD $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD $@"
449          fi          fi
450      else      else
451      if [ ! -z $DOINTERACTIVE ]          if [ ! -z $DO_INTERACTIVE ]
452          then          then
453             EXEC_CMD="$PYTHON_MPI -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI -i $@"
454          else          else
455             EXEC_CMD="$PYTHON_MPI $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI $@"
456          fi          fi
457      fi      fi
458  fi  fi
459  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
460  #===============================================================================================  #==============================================================================
461  #  #
462  #   now we start to spwan things:  #   now we start to spawn things:
463  #  #
464  if [ "$WITH_OPENMP" = "y" ]  if [ "$WITH_OPENMP" = "1" ]
465  then  then
466     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
467     EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"     EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"
468  fi  fi
469  EXIT_CODE=1  EXIT_CODE=1
470  #=============== no MPI ===================================  #=============== no MPI ===================================
471  if [ "$MPI_FLAVOUR" = "none" ]  if [ "$MPI_FLAVOUR" = "none" ]
472  then  then
473     $EXEC_CMD     $EXEC_CMD
474     EXIT_CODE=$?     EXIT_CODE=$?
475  #=============== OpenMPI ===================================  #=============== OpenMPI ===================================
476  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]
477  then  then
478     if [ ! -z $HOSTFILE ]     EXPORT_ENV=$(echo $EXPORT_ENV|sed -e 's/,/ -x /g')
479       if [ ! -z "$HOSTFILE" ]
480     then     then
481        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}')
482        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} --bynode --bind-to-none --host $HOST_LIST -np $TOTPROC $EXEC_CMD"
483     else     else
484        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} --cpus-per-rank $ESCRIPT_NUM_THREADS --bind-to-core -np $TOTPROC $EXEC_CMD"
485     fi     fi
486     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
487     $CMD     $CMD
488     EXIT_CODE=$?     EXIT_CODE=$?
# Line 402  then Line 491  then
491  elif [ "$MPI_FLAVOUR" = "INTELMPI" ]  elif [ "$MPI_FLAVOUR" = "INTELMPI" ]
492  then  then
493    
494     if [ "$WITH_OPENMP" = "y" ]     if [ "$WITH_OPENMP" = "1" ]
495     then     then
496         export I_MPI_PIN_DOMAIN=omp         export I_MPI_PIN_DOMAIN=omp
497         EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"         EXPORT_ENV="$EXPORT_ENV,I_MPI_PIN_DOMAIN"
498     fi     fi
499    
500     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
501     then     then
502        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  
503     else     else
504        mpdboot -n 1 -r ssh          if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Empty hostfile, running on single node"; fi
505        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  
506     fi     fi
    CMD="mpiexec -perhost $ESCRIPT_NUM_PROCS -envall -n $TOTPROC $EXEC_CMD"  
507     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
508     $CMD     $CMD
509     EXIT_CODE=$?     EXIT_CODE=$?
    mpdallexit  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi  
510  #=============== SGI's MPIMPT ===================================  #=============== SGI's MPIMPT ===================================
511  elif [ "$MPI_FLAVOUR" = "MPT" ]  elif [ "$MPI_FLAVOUR" = "MPT" ]
512  then  then
513     export MPI_NUM_MEMORY_REGIONS=0     export MPI_NUM_MEMORY_REGIONS=0
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"
521     fi     fi
522     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
523     $CMD     $CMD
524     EXIT_CODE=$?     EXIT_CODE=$?
525  #=============== MPICH ===================================  #=============== MPICH ===================================
526  elif [ "$MPI_FLAVOUR" = "MPICH" ]  elif [ "$MPI_FLAVOUR" = "MPICH" ]
527  then  then
528     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
529     then     then
530        touch $HOSTFILE2        touch "$HOSTFILE2"
531        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
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"
535     fi     fi
536     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
537     $CMD     $CMD
538     EXIT_CODE=$?     EXIT_CODE=$?
539  #=============== MPICH2 ===================================  #=============== MPICH2 ===================================
540  elif [ "$MPI_FLAVOUR" = "MPICH2" ]  elif [ "$MPI_FLAVOUR" = "MPICH2" ]
541  then  then
542     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
543     then     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 $ESCRIPT_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
554        if [ $? -ne 0 ]        if [ $? -ne 0 ]
555        then        then
556           echo "mpdboot failed."           echo "mpdboot failed."
557           exit 1           exit 1
558        else        else
559            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi            if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi
560        fi        fi
561     fi     fi
# Line 495  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.3056  
changed lines
  Added in v.5239

  ViewVC Help
Powered by ViewVC 1.1.26