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

Diff of /trunk/run-escript.in

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

trunk/bin/run-escript revision 3162 by jfenwick, Tue Sep 7 05:29:32 2010 UTC trunk/run-escript.in revision 5266 by caltinay, Mon Nov 17 06:45:01 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/usr/bin/env sh
2    
3  # Escript/Finley wrapper for python  ##############################################################################
4  # Sets LD_LIBRARY_PATH and PYTHONPATH and then runs either python or the MPI launcher  #
5    # Copyright (c) 2003-2014 by University of Queensland
6    # http://www.uq.edu.au
7    #
8    # Primary Business: Queensland, Australia
9    # Licensed under the Open Software License version 3.0
10    # http://www.opensource.org/licenses/osl-3.0.php
11    #
12    # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13    # Development 2012-2013 by School of Earth Sciences
14    # Development from 2014 by Centre for Geoscience Computing (GeoComp)
15    #
16    ##############################################################################
17    
18  #Extra paths can be configured about a page further down  # Escript wrapper for python
19  #Search for EXTRA_PATH=""  # Sets LD_LIBRARY_PATH and PYTHONPATH and then runs either python or the MPI
20    # launcher.
21    
22  #set to 1 if performing this is a standalone build and ../../pkg contains the relevant tools  # Extra paths can be configured about a page further down
23    # Search for EXTRA_PATH=""
24    
25    # set to 1 if this is a standalone build and ../../pkg contains the relevant
26    # tools
27  STANDALONE=0  STANDALONE=0
28    
29  #set to 1 if this is part of a packaged build (.deb) and files will be installed in standard locations  # set to 1 if this is part of a packaged build (.deb) and files will be
30  #rather than everything in a single directory  # installed in standard locations rather than everything in a single directory
31  #Do not use this together with $STANDALONE  # Do not use this together with STANDALONE
32  STDLOCATION=0  STDLOCATION=0
33    
34  #Now we find the location of this script  # Now we find the location of this script
35  #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
36  scriptdir=""  scriptdir=""
37  CURDIR=`pwd`  CURDIR=$(pwd)
38    
39  #Environment vars which control operations:  # Environment vars which control operations:
40  # 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
41    
42  HOSTFILE=/tmp/escript.$USER.$$  HOSTFILE=/tmp/escript.$USER.$$
43  HOSTFILE2=/tmp/escript2.$USER.$$  
44    die () {
45        echo "Error: $@" 1>&2
46        exit 1
47    }
48    
49  #Begin finding ESCRIPT_ROOT  #Begin finding ESCRIPT_ROOT
50  if [ $STDLOCATION -ne 0 ]  if [ $STDLOCATION -ne 0 ]
51  then  then
52      ESCRIPT_ROOT=/usr/lib/escript      ESCRIPT_ROOT=/usr/lib/python-escript
53  else  else
54    #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
55    #Need to match if the name contains /    # Need to match if the name contains /
56    if [[ $0 =~ / ]]    if $(echo $0|grep -q /)
57    then    then
58        # We are not using the PATH to find the script        # We are not using the PATH to find the script
59        cd `dirname $0`        cd "$(dirname $0)"
60        scriptdir=`pwd`        scriptdir=$(pwd)
61        cd $CURDIR        cd "$CURDIR"
62    else    else
63        # name does not contain / therefore we are using        # name does not contain / therefore we are using
64        tscriptdir=`which $0`        tscriptdir=$(which $0)
65        if [ $? -ne 0 ]        if [ $? -ne 0 ]
66        then        then
67            echo "Error! Unable to determine script directory. Exiting."            die "Unable to determine script directory!"
           exit 1  
68        fi        fi
69        scriptdir=`dirname $tscriptdir`        scriptdir=$(dirname $tscriptdir)
70    fi    fi
71    
72    cd $scriptdir/..    cd "$scriptdir/.."
73    ESCRIPT_ROOT=`pwd`    ESCRIPT_ROOT=$(pwd)
74    cd ..    cd ..
75    ESCRIPT_PARENT=`pwd`    ESCRIPT_PARENT=$(pwd)
76    cd $CURDIR    cd "$CURDIR"
77    
78  fi  fi
79  ##### End finding ESCRIPT_ROOT  ########  ##### End finding ESCRIPT_ROOT ########
   
 if [ ! -r $ESCRIPT_ROOT/lib/buildvars ]; then  
     echo "Error! Unable to read escript build information. Exiting."  
     exit 1  
 fi  
80    
81  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"
82  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"
# Line 73  PYTHON_CMD=python Line 88  PYTHON_CMD=python
88  EXTRA_DYLD_LIBRARY_PATH=""  EXTRA_DYLD_LIBRARY_PATH=""
89  EXTRA_PATH=$ESCRIPT_ROOT/bin  EXTRA_PATH=$ESCRIPT_ROOT/bin
90  EXTRA_PYTHONPATH=$ESCRIPT_ROOT  EXTRA_PYTHONPATH=$ESCRIPT_ROOT
91  EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib  
92    if [ $STDLOCATION -eq 1 ]
93    then
94        EXTRA_LD_LIBRARY_PATH=/usr/lib/python-escript
95    else
96        EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
97    fi
98    
99    
100  if [ $STANDALONE -eq 1 ]  if [ $STANDALONE -eq 1 ]
101  then  then
102      EXTRA_PATH=$ESCRIPT_PARENT/pkg/python/bin:$EXTRA_PATH      EXTRA_PATH=$ESCRIPT_PARENT/pkg/python/bin:$ESCRIPT_PARENT/pkg/scons/bin:$EXTRA_PATH
103      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
104      EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH      EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH
105      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
106      EXTRA_PYTHONPATH=$ESCRIPT_PARENT/pkg/numpy/lib/python2.6/site-packages:$ESCRIPT_PARENT/pkg/matplotlib/lib/python2.6/site-packages:$EXTRA_PYTHONPATH      EXTRA_PYTHONPATH=$ESCRIPT_PARENT/pkg/numpy/lib/python2.6/site-packages:$ESCRIPT_PARENT/pkg/matplotlib/lib/python2.6/site-packages:$EXTRA_PYTHONPATH
107  fi  fi
108    
109  #  
110  #   Add VisIt paths if required  BUILDINFO_FILE="$ESCRIPT_ROOT/lib/buildvars"
111  #  if [ "$STDLOCATION" = "1" ]
112  WITH_VISIT=`grep usevisit $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  then
113  if [ "$WITH_VISIT" = "y" ]; then      BUILDINFO_FILE=/usr/lib/python-escript/buildvars
114      VISIT_BIN=`which visit`  fi
115      if [ $? -eq 0 ]; then  if [ ! -r "$BUILDINFO_FILE" ]; then
116          VISIT_PY_PATH=`$VISIT_BIN -env | grep LIBPATH | cut -d= -f2`      if [ "$1" = "-e" ]; then
117          EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH          echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
118          EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$VISIT_PY_PATH          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
119      elif [ ! -z $ESCRIPT_VERBOSE ]; then          echo "export PATH=$EXTRA_PATH:\$PATH"
120          echo "VisIt module enabled but VisIt not in path!"          if [ "$(uname)" = "Darwin" ]
121            then
122                echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
123            fi
124            exit 0
125      fi      fi
126        die "Unable to read escript build information!"
127  fi  fi
128    
129    get_buildvar () {
130        echo $(grep "^$1=" "$BUILDINFO_FILE" |cut -d= -f2)
131    }
132    
133  HELP_TEXT="  HELP_TEXT="
134  Usage: escript [options] script.py [arguments...]  Usage: run-escript [options] script.py [arguments...]
135      -n nn       number of nodes to use      -n nn       number of nodes to use
136      -p np       number of MPI processes to spawn      -p np       number of MPI processes to spawn per node
137      -t nt       number of OpenMP threads to use      -t nt       number of OpenMP threads to use
138      -f file     name of MPI hostfile      -f file     name of MPI hostfile
139      -c      print compile information for escript and exit      -c      print compile information for escript and exit
140      -V      print escript version and exit      -V      print escript version and exit
141      -i      interactive mode      -i      interactive mode
142      -b      do not invoke python (run non-python programs)      -b      do not invoke python (run non-python programs)
143      -e      print export statements for environment and exit      -e      print export statements for environment and exit
144      -o      redirect output from MPI to files      -o      redirect output from MPI to files
145      -v      print diagnostics      -v      print diagnostics
146      -x      ..reserved for future use ..      -x      run in new xterm instance
147        -m tool     run with valgrind {tool=m[emcheck]/c[allgrind]/[cac]h[egrind]}
148      script.py   Your python script      script.py   Your python script
149      arguments...    The optional command-line arguments to your script      arguments...    The optional command-line arguments to your script
150  "  "
# Line 121  if [ "$1" = "--help" ]; then Line 153  if [ "$1" = "--help" ]; then
153    echo "$HELP_TEXT"    echo "$HELP_TEXT"
154    exit 0    exit 0
155  fi  fi
156  #=======================================================================================  #==============================================================================
   
 # Avoid bug in hybrid runs with MPT MPI  
   
157    
158  # Parse the command-line options  # Parse the command-line options
159  # 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  
160  do  do
161      case "$option" in      case "$option" in
162        "b")  DOBINARY=yes        "b")  DO_BINARY=y
163          ;;          ;;
164        "n")  ESCRIPT_NUM_NODES=$OPTARG        "m")  DO_VALGRIND=$OPTARG
165          ;;          ;;
166        "p")  ESCRIPT_NUM_PROCS=$OPTARG        "n")  ESCRIPT_NUM_NODES=$OPTARG
167          ;;          ;;
168        "t")  ESCRIPT_NUM_THREADS=$OPTARG        "p")  ESCRIPT_NUM_PROCS=$OPTARG
169          ;;          ;;
170        "f")  ESCRIPT_HOSTFILE=$OPTARG        "t")  ESCRIPT_NUM_THREADS=$OPTARG
171          ;;          ;;
172        "c")  cat $ESCRIPT_ROOT/lib/buildvars        "f")  ESCRIPT_HOSTFILE=$OPTARG
173          exit 0          ;;
174          ;;        "c")  cat "$BUILDINFO_FILE"
175        "V")  echo "escript-development(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"          exit 0
176          exit 0          ;;
177          ;;        "V")  echo "escript-development(build "$(get_buildvar svn_revision)")"
178        "h")  echo "$HELPTEXT"          exit 0
179          exit 0          ;;
180          ;;        "h")  echo "$HELP_TEXT"
181        "i")  DOINTERACTIVE=yes          exit 0
182          ;;          ;;
183        "e")  echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"        "i")  DO_INTERACTIVE=y
184          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"          ;;
185          echo "export PATH=$EXTRA_PATH:\$PATH"        "e")  echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
186          if [ "`uname`" = "Darwin" ]          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
187          then          echo "export PATH=$EXTRA_PATH:\$PATH"
188              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"          if [ "$(uname)" = "Darwin" ]
189          fi          then
190          exit 0              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
191          ;;          fi
192        "o")  ESCRIPT_CREATESTDFILES="yes"          exit 0
193          ;;          ;;
194        "v")  ESCRIPT_VERBOSE="yes"        "o")  ESCRIPT_CREATESTDFILES=y
195          ;;          ;;
196        "x")  echo "-x not implemented yet"        "v")  ESCRIPT_VERBOSE=y
197          exit 1          ;;
198          ;;        "x")  DO_XTERM=y
199        ?)    echo "$HELP_TEXT"          ;;
200          exit 1        ?)    echo "$HELP_TEXT"
201          ;;          exit 1
202      esac          ;;
203        esac
204  done  done
205  shift `expr $OPTIND - 1`  shift $(($OPTIND - 1))
206    
207    vlog () {
208        if [ ! -z $ESCRIPT_VERBOSE ]; then
209            echo "$@"
210        fi
211    }
212    
213  #==============================================  #==============================================
214  #  #
215  #   Read the MPI_FLAVOUR from the buildvars  #   Read MPI_FLAVOUR and WITH_OPENMP from the buildvars
216  #  #
217  MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  MPI_FLAVOUR=$(get_buildvar mpi)
218  WITH_OPENMP=`grep useopenmp $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  WITH_OPENMP=$(get_buildvar openmp)
219    
220    vlog "MPI flavour is $MPI_FLAVOUR."
221    if [ "$WITH_OPENMP" = "1" ]; then
222        vlog "OpenMP enabled."
223    else
224        vlog "OpenMP disabled."
225    fi
226    
227  if [ ! -z $ESCRIPT_VERBOSE ]; then  #
228      echo "MPI flavour is $MPI_FLAVOUR."  #   Add VisIt paths if required
229      if [ "$WITH_OPENMP" = "y" ]; then echo "OpenMP enabled."; fi  #
230    WITH_VISIT=$(get_buildvar visit)
231    if [ "$WITH_VISIT" = "1" ]; then
232        VISIT_BIN=$(which visit 2>/dev/null)
233        if [ $? -eq 0 ]; then
234            VISIT_PY_PATH=$($VISIT_BIN -env | grep LIBPATH | cut -d= -f2)
235            EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH
236            EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$VISIT_PY_PATH
237        else
238            vlog "Warning: VisIt module enabled but VisIt not in path!"
239        fi
240  fi  fi
241    
242  #  #
# Line 193  export PATH=$EXTRA_PATH:$PATH Line 246  export PATH=$EXTRA_PATH:$PATH
246  export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH  export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
247  export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH  export PYTHONPATH=$EXTRA_PYTHONPATH:$PYTHONPATH
248  EXPORT_ENV="PATH,LD_LIBRARY_PATH,PYTHONPATH"  EXPORT_ENV="PATH,LD_LIBRARY_PATH,PYTHONPATH"
249  if [ "`uname`" = "Darwin" ]  if [ "$(uname)" = "Darwin" ]
250  then  then
251      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
252      EXPORT_ENV="$EXPORT_ENV,DYLD_LIBRARY_PATH"      EXPORT_ENV="$EXPORT_ENV,DYLD_LIBRARY_PATH"
253  fi  fi
254  if [ ! -z $ESCRIPT_VERBOSE ]  vlog "PATH = $PATH
255  then  LD_LIBRARY_PATH = $LD_LIBRARY_PATH
256      echo "PATH = $PATH "  PYTHONPATH = $PYTHONPATH"
257      echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH "  if [ ! -z $DYLD_LIBRARY_PATH ]; then
258      echo "PYTHONPATH = $PYTHONPATH "      vlog "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH"
     if [ ! -z $DYLD_LIBRARY_PATH ]; then echo "DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH "; fi  
259  fi  fi
260    
261  #==============================================  #==============================================
262  #  #
263  #  Ensure the variables have sensible values  #  Ensure the variables have sensible values
264  #  #
265  if [ "$MPI_FLAVOUR" = "none" ]  if [ "$MPI_FLAVOUR" = "none" ]
266  then  then
267      if [ ! -z $ESCRIPT_NUM_NODES ]      if [ ! -z "$ESCRIPT_NUM_NODES" ]; then
268      then          if [ $ESCRIPT_NUM_NODES -gt 1 ]; then
269          echo "Warning: MPI disabled but number of nodes set. Option ignored."              echo "Warning: MPI disabled but number of nodes set. Option ignored."
270            fi
271      fi      fi
272      if [ ! -z $ESCRIPT_NUM_PROCS ]      if [ ! -z "$ESCRIPT_NUM_PROCS" ]; then
273      then          if [ $ESCRIPT_NUM_PROCS -gt 1 ]; then
274          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."
275            fi
276      fi      fi
277      if [ ! -z $ESCRIPT_HOSTFILE ]      if [ ! -z "$ESCRIPT_HOSTFILE" ]
278      then      then
279          echo "Warning: MPI disabled but host file is given. Option ignored."          echo "Warning: MPI disabled but host file is given. Option ignored."
280      fi      fi
# Line 227  then Line 282  then
282      ESCRIPT_NUM_PROCS=1      ESCRIPT_NUM_PROCS=1
283  else  else
284      # use the PBS_NODEFILE if not otherwise specified      # use the PBS_NODEFILE if not otherwise specified
285      if [[ ( ! -z $PBS_NODEFILE ) && ( -z $ESCRIPT_HOSTFILE ) ]]      if [ ! -z "$PBS_NODEFILE" ] && [ -z "$ESCRIPT_HOSTFILE" ]
286      then      then
287      ESCRIPT_HOSTFILE=$PBS_NODEFILE          ESCRIPT_HOSTFILE=$PBS_NODEFILE
   
288      fi      fi
289    
290      if [ ! -z $ESCRIPT_HOSTFILE ]      if [ ! -z "$ESCRIPT_HOSTFILE" ]
291      then      then
292          if [ -f $ESCRIPT_HOSTFILE ]          if [ -f "$ESCRIPT_HOSTFILE" ]
293          then          then
294              cat $ESCRIPT_HOSTFILE | sort -u > $HOSTFILE              sort -u "${ESCRIPT_HOSTFILE}" > $HOSTFILE
295              NUM_HOSTS=`cat $HOSTFILE | wc -l`              HOSTLIST=$(awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' "$HOSTFILE")
296              if [ ! -z $ESCRIPT_NUM_NODES ]  
297                NUM_HOSTS=$(wc -l "$HOSTFILE")
298                if [ ! -z $ESCRIPT_NUM_NODES ]
299              then              then
300                  if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]                  if [ $NUM_HOSTS -ne $ESCRIPT_NUM_NODES ]
301                  then                  then
302                      echo "number of hosts selected in the host file $ESCRIPT_HOSTFILE needs to match the requested number of nodes $ESCRIPT_NUM_NODES."                      die "Number of hosts selected in the host file $ESCRIPT_HOSTFILE needs to match the requested number of nodes $ESCRIPT_NUM_NODES!"
                     exit 1  
303                  fi                  fi
304               else               else
305                  ESCRIPT_NUM_NODES=$NUM_HOSTS                  ESCRIPT_NUM_NODES=$NUM_HOSTS
306               fi               fi
307          else          else
308             echo "cannot find hostfile $ESCRIPT_HOSTFILE."             die "Cannot find hostfile $ESCRIPT_HOSTFILE!"
            exit 1  
309          fi          fi
310      else      else
311          HOSTFILE=''          echo "localhost" > $HOSTFILE
312            HOSTLIST="localhost"
313      fi      fi
314    
315      if [ -z $ESCRIPT_NUM_NODES ]      if [ -z $ESCRIPT_NUM_NODES ]
316      then      then
317        ESCRIPT_NUM_NODES=1          ESCRIPT_NUM_NODES=1
318      fi      fi
319    
320      if [ -z $ESCRIPT_NUM_PROCS ]      if [ -z $ESCRIPT_NUM_PROCS ]
321      then      then
322        ESCRIPT_NUM_PROCS=1          ESCRIPT_NUM_PROCS=1
323      fi      fi
324    
325      if [ ! -z $ESCRIPT_VERBOSE ]      vlog "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES\nESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS"
     then  
           echo "ESCRIPT_NUM_NODES = $ESCRIPT_NUM_NODES "  
           echo "ESCRIPT_NUM_PROCS = $ESCRIPT_NUM_PROCS "  
     fi  
326  fi  fi
327    
328  if [ "$WITH_OPENMP" = "y" ]  if [ "$WITH_OPENMP" = "1" ]
329  then  then
330     if [ -z $ESCRIPT_NUM_THREADS ]      if [ -z $ESCRIPT_NUM_THREADS ]
331     then      then
332          ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS          ESCRIPT_NUM_THREADS=$OMP_NUM_THREADS
333          if [ -z $ESCRIPT_NUM_THREADS ]          if [ -z $ESCRIPT_NUM_THREADS ]
334          then          then
335             ESCRIPT_NUM_THREADS=1              ESCRIPT_NUM_THREADS=1
336          fi          fi
337     fi      fi
338     if [ ! -z $ESCRIPT_VERBOSE ]      vlog "ESCRIPT_NUM_THREADS = $ESCRIPT_NUM_THREADS"
    then  
         echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."  
    fi  
339  else  else
340     if [[ ( ! -z $ESCRIPT_NUM_THREADS ) && ( $ESCRIPT_NUM_THREADS != 1 ) ]]      if [ ! -z $ESCRIPT_NUM_THREADS ] && [ $ESCRIPT_NUM_THREADS != 1 ]
341     then      then
342         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. Option ignored."
343     fi      fi
344     ESCRIPT_NUM_THREADS=1      ESCRIPT_NUM_THREADS=1
345  fi  fi
346    
347  #  #
348  # Now we compute total number of Processes  # Now we compute total number of Processes
349  #  #
350  (( TOTPROC=$ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS))  TOTPROC=$((ESCRIPT_NUM_NODES * ESCRIPT_NUM_PROCS))
351  if [ $? -ne 0 ]     #Some compute error  if [ $? -ne 0 ] #Some compute error
352  then            #This could happen if the args were not a number  then            #This could happen if the args were not a number
353    echo "expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical."      die "Expression of total number of processors = $ESCRIPT_NUM_NODES * $ESCRIPT_NUM_PROCS is not numerical!"
354    exit 1  fi
355    
356    # set up thread binding if unset
357    if [ "$OMP_PROC_BIND" = "" ]; then
358        #Force OpenMP binding for Intel (and GCC, though GCC is on by default)
359        export OMP_PROC_BIND=true
360    fi
361    if [ "$KMP_AFFINITY" = "" ]; then
362        #Set the style of binding (overrides OMP_PROC_BIND in many cases)
363        export KMP_AFFINITY=verbose,compact
364  fi  fi
365    
366  #  #
367  # 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
368  #  #
369  if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]  if ([ ! -z $DO_INTERACTIVE ] || [ $# -eq 0 ]) && ([ $TOTPROC -gt 1 ])
370  then  then
371    echo "Interactive mode cannot be used with more than one process"      die "Interactive mode cannot be used with more than one process!"
   exit 1  
372  fi  fi
373    
374  if [ $TOTPROC -gt 1 ]  if [ $TOTPROC -gt 1 ]
375  then  then
376     if [ "$ESCRIPT_CREATESTDFILES" = "yes" ]      if [ "$ESCRIPT_CREATESTDFILES" = "y" ]
377     then      then
378         PYTHON_MPI=$PYTHON_MPI_REDIRECT          PYTHON_MPI=$PYTHON_MPI_REDIRECT
379     else      else
380         PYTHON_MPI=$PYTHON_MPI_NULL          PYTHON_MPI=$PYTHON_MPI_NULL
381     fi      fi
382  else  else
383      PYTHON_MPI=$PYTHON_MPI_NULL      PYTHON_MPI=$PYTHON_MPI_NULL
384  fi  fi
385  #=========================================================================================================  #==============================================================================
386  # Must have at least one command-line arg: the python script  # Must have at least one command-line arg: the python script
387  if [ $# -eq 0 ]  if [ $# -eq 0 ]
388  then  then
389    if [ ! -z $DOBINARY ]      if [ ! -z $DO_BINARY ]
390    then      then
391      echo "No program to run was specified. Exiting."          die "No program to run was specified!"
392      exit 1      else
393    else          DO_INTERACTIVE=y
394      DOINTERACTIVE="yes"      fi
   fi  
395  fi  fi
396    
397  #=========================================================================================================  #==============================================================================
398  if [ ! -z $DOBINARY ]  
399    if [ ! -z $DO_XTERM ]
400  then  then
401      EXEC_CMD="$@"      EXEC_CMD="xterm -e"
402  else  else
403      if [ "$MPI_FLAVOUR" = "none" ]      EXEC_CMD=""
404      then  fi
405          # Check to see if the python version we were compiled with matches the one of EXEC_CMD  
406          # We should only do this check if they are running a python script  if [ ! -z "$DO_VALGRIND" ]
407          if [ -f $ESCRIPT_ROOT/lib/pyversion ]  then
408        VALGRIND_BIN=$(which valgrind 2>/dev/null)
409        if [ $? -eq 0 ]; then
410            LOGDIR=$ESCRIPT_ROOT/valgrind_logs
411            [ -d $LOGDIR ] || mkdir $LOGDIR
412            VG_TOOL=$(echo $DO_VALGRIND | awk '{ s=substr($0,1,1);print s;}')
413            if [ $VG_TOOL = "c" ];
414            then
415                # run callgrind
416                LOGFILE=${LOGDIR}/callgrind.%p.xml
417                VALGRIND="valgrind --tool=callgrind --callgrind-out-file=$LOGFILE"
418                EXEC_CMD="$EXEC_CMD $VALGRIND"
419            elif [ $VG_TOOL = "h" ];
420          then          then
421             compversion=`cat $ESCRIPT_ROOT/lib/pyversion`              # run cachegrind
422         intversion=`$PYTHON_CMD -c 'import sys;print "%d.%d.%d"%(sys.version_info[0], sys.version_info[1], sys.version_info[2])'`              LOGFILE=${LOGDIR}/cachegrind.%p.xml
423             if [ "$compversion" != "$intversion" ]              VALGRIND="valgrind --tool=cachegrind --cachegrind-out-file=$LOGFILE"
424             then              EXEC_CMD="$EXEC_CMD $VALGRIND"
425                echo "Python versions do not match. Escript was compiled for "$compversion"."          else
426                echo "Current version of Python appears to be "$intversion"."              # run memcheck by default
427                exit 1              LAST_N=$(ls -1 $LOGDIR|grep "^memcheck"|tail -1|cut -d. -f2)
428             fi              NEW_N=$(printf "%04d" $((LAST_N + 1)))
429                LOGFILE=${LOGDIR}/memcheck.${NEW_N}.xml
430                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"
431                EXEC_CMD="$EXEC_CMD $VALGRIND"
432          fi          fi
433      if [ ! -z $DOINTERACTIVE ]      else
434            die "Execution with valgrind requested but valgrind not in path!"
435        fi
436    fi
437    
438    if [ ! -z $DO_BINARY ]
439    then
440        EXEC_CMD="$EXEC_CMD $@"
441    else
442        # Check to see if the python version we were compiled with matches the
443        # one of PYTHON_CMD.
444        compfull=$(get_buildvar python_version)
445        compversion=$(echo $compfull | cut -d. -f1,2)
446        compmajor=$(echo $compfull | cut -d. -f1)
447        if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they
448        then                                # might not want us changing it
449            if [ "$compmajor" = "3" ]
450            then
451                PYTHON_CMD=python3
452            fi
453        fi
454        intversion=$($PYTHON_CMD -c 'from __future__ import print_function;import sys;print("%d.%d"%(sys.version_info[0], sys.version_info[1]))')
455        if [ "$compversion" != "$intversion" ]
456        then
457            die "Python versions do not match. Escript was compiled for '$compversion'.
458    Current version of Python appears to be '$intversion'."
459        fi
460        if [ "$MPI_FLAVOUR" = "none" ]
461        then
462            if [ ! -z $DO_INTERACTIVE ]
463          then          then
464             EXEC_CMD="$PYTHON_CMD -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD -i $@"
465          else          else
466             EXEC_CMD="$PYTHON_CMD $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD $@"
467          fi          fi
468      else      else
469      if [ ! -z $DOINTERACTIVE ]          if [ ! -z $DO_INTERACTIVE ]
470          then          then
471             EXEC_CMD="$PYTHON_MPI -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI -i $@"
472          else          else
473             EXEC_CMD="$PYTHON_MPI $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI $@"
474          fi          fi
475      fi      fi
476  fi  fi
477  if [ ! -z $ESCRIPT_VERBOSE ]; then echo "Command to be executed is \"$EXEC_CMD\"."; fi  vlog "Command to be executed is \"$EXEC_CMD\""
478  #===============================================================================================  #==============================================================================
479  #  #
480  #   now we start to spwan things:  #   now we start to spawn things:
481  #  #
482  if [ "$WITH_OPENMP" = "y" ]  if [ "$WITH_OPENMP" = "1" ]
483  then  then
484     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
485     EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"     EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"
486  fi  fi
487  EXIT_CODE=1  
488  #=============== no MPI ===================================  vlog "Pre-launch command: \"@@PRELAUNCH\""
489  if [ "$MPI_FLAVOUR" = "none" ]  @@PRELAUNCH
490  then  vlog "Launch command: \"@@LAUNCH\""
491     $EXEC_CMD  @@LAUNCH
492     EXIT_CODE=$?  EXIT_CODE=$?
493  #=============== OpenMPI ===================================  vlog "Post-launch command: \"@@POSTLAUNCH\""
494  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]  @@POSTLAUNCH
495  then  
496     if [ ! -z $HOSTFILE ]  if [ ! -z "$DO_VALGRIND" ]; then
497     then     echo "Valgrind log file written to ${LOGFILE}"
       HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`  
       CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } --bynode -np $TOTPROC --host $HOST_LIST $EXEC_CMD"  
    else  
       CMD="mpirun --gmca mpi_warn_on_fork 0 -x ${EXPORT_ENV//,/ -x } -np $TOTPROC $EXEC_CMD"  
    fi  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi  
    $CMD  
    EXIT_CODE=$?  
   
 #=============== Intel MPI ===================================  
 elif [ "$MPI_FLAVOUR" = "INTELMPI" ]  
 then  
   
    if [ "$WITH_OPENMP" = "y" ]  
    then  
        export I_MPI_PIN_DOMAIN=omp  
        EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"  
    fi  
   
    if [ ! -z $HOSTFILE ]  
    then  
       mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE  
       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  
    else  
       mpdboot -n 1 -r ssh  
       if [ $? -ne 0 ]  
       then  
          echo "mpdboot failed."  
          exit 1  
       else  
           if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi  
       fi  
    fi  
    CMD="mpiexec -perhost $ESCRIPT_NUM_PROCS -envall -n $TOTPROC $EXEC_CMD"  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi  
    $CMD  
    EXIT_CODE=$?  
    mpdallexit  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi  
 #=============== SGI's MPIMPT ===================================  
 elif [ "$MPI_FLAVOUR" = "MPT" ]  
 then  
    export MPI_NUM_MEMORY_REGIONS=0  
    EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"  
    if [ ! -z $HOSTFILE ]  
    then  
       HOST_LIST=`awk 'BEGIN{S=""}{if (S == "") { S = $0 } else {S = S "," $0}}END{print S}' $HOSTFILE`  
       CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"  
    else  
       CMD="mpirun -np $TOTPROC $EXEC_CMD"  
    fi  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi  
    $CMD  
    EXIT_CODE=$?  
 #=============== MPICH ===================================  
 elif [ "$MPI_FLAVOUR" = "MPICH" ]  
 then  
    if [ ! -z $HOSTFILE ]  
    then  
       touch $HOSTFILE2  
       for (( i=1;i<=$ESCRIPT_NUM_PROCS;i+=1 )) ; do cat $HOSTFILE >> $HOSTFILE2  ; done  
       CMD="mpirun -machinefile $HOSTFILE2  -np $TOTPROC $EXEC_CMD"  
    else  
       CMD="mpirun -np $TOTPROC $EXEC_CMD"  
    fi  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi  
    $CMD  
    EXIT_CODE=$?  
 #=============== MPICH2 ===================================  
 elif [ "$MPI_FLAVOUR" = "MPICH2" ]  
 then  
    if [ ! -z $HOSTFILE ]  
    then  
          mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE  
          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  
    else  
       mpdboot -n 1 -r ssh  
       if [ $? -ne 0 ]  
       then  
          echo "mpdboot failed."  
          exit 1  
       else  
           if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdboot was started."; fi  
       fi  
    fi  
    CMD="mpiexec -genvlist $EXPORT_ENV -np $TOTPROC $EXEC_CMD"  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi  
    $CMD  
    EXIT_CODE=$?  
    mpdallexit  
    if [ ! -z $ESCRIPT_VERBOSE ]; then echo "mpdallexit executed."; fi  
 else  
    echo "unknown MPI flavour '$MPI_FLAVOUR'."  
498  fi  fi
499    
500    rm -f $HOSTFILE
501    
502  exit $EXIT_CODE  exit $EXIT_CODE
503    

Legend:
Removed from v.3162  
changed lines
  Added in v.5266

  ViewVC Help
Powered by ViewVC 1.1.26