/[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 2923 by jfenwick, Thu Feb 4 04:05:36 2010 UTC revision 4664 by caltinay, Mon Feb 10 01:57:11 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/usr/bin/env bash
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 22  CURDIR=`pwd` Line 22  CURDIR=`pwd`
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  HOSTFILE=/tmp/escript.$$  HOSTFILE=/tmp/escript.$USER.$$
26  HOSTFILE2=/tmp/escript2.$$  HOSTFILE2=/tmp/escript2.$USER.$$
27    
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 [[ $0 =~ / ]]
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 [ $? != 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
# Line 49  else Line 49  else
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
59  ##### 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  
60    
61  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"  PYTHON_MPI_NULL="$ESCRIPT_ROOT/lib/pythonMPI"
62  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"  PYTHON_MPI_REDIRECT="$ESCRIPT_ROOT/lib/pythonMPIredirect"
# Line 73  PYTHON_CMD=python Line 68  PYTHON_CMD=python
68  EXTRA_DYLD_LIBRARY_PATH=""  EXTRA_DYLD_LIBRARY_PATH=""
69  EXTRA_PATH=$ESCRIPT_ROOT/bin  EXTRA_PATH=$ESCRIPT_ROOT/bin
70  EXTRA_PYTHONPATH=$ESCRIPT_ROOT  EXTRA_PYTHONPATH=$ESCRIPT_ROOT
71  EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib  
72    if [ $STDLOCATION -eq 1 ]
73    then
74        EXTRA_LD_LIBRARY_PATH=/usr/lib/python-escript
75    else
76        EXTRA_LD_LIBRARY_PATH=$ESCRIPT_ROOT/lib
77    fi
78    
79    
80  if [ $STANDALONE -eq 1 ]  if [ $STANDALONE -eq 1 ]
81  then  then
82      EXTRA_PATH=$ESCRIPT_PARENT/pkg/python/bin:$EXTRA_PATH      EXTRA_PATH=$ESCRIPT_PARENT/pkg/python/bin:$ESCRIPT_PARENT/pkg/scons/bin:$EXTRA_PATH
83      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
84      EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH      EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH
85      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 87  then
87  fi  fi
88    
89    
90    BUILDINFO_FILE="$ESCRIPT_ROOT/lib/buildvars"
91    if [ "$STDLOCATION" = "1" ]
92    then
93        BUILDINFO_FILE=/usr/lib/python-escript/buildvars
94    fi
95    if [ ! -r "$BUILDINFO_FILE" ]; then
96        if [ "$1" = "-e" ]; then
97            echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
98            echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
99            echo "export PATH=$EXTRA_PATH:\$PATH"
100            if [ "`uname`" = "Darwin" ]
101            then
102                echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
103            fi  
104            exit 0
105        fi
106        echo "Error! Unable to read escript build information. Exiting."
107        exit 1
108    fi
109    
110    get_buildvar () {
111        echo `grep "^$1=" "$BUILDINFO_FILE" |cut -d= -f2`
112    }
113    
114    #
115    #   Add VisIt paths if required
116    #
117    WITH_VISIT=`get_buildvar visit`
118    if [ "$WITH_VISIT" = "1" ]; then
119        VISIT_BIN=`which visit 2>/dev/null`
120        if [ $? -eq 0 ]; then
121            VISIT_PY_PATH=`$VISIT_BIN -env | grep LIBPATH | cut -d= -f2`
122            EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH
123            EXTRA_LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:$VISIT_PY_PATH
124        elif [ ! -z $ESCRIPT_VERBOSE ]; then
125            echo "VisIt module enabled but VisIt not in path!"
126        fi
127    fi
128    
129  HELP_TEXT="  HELP_TEXT="
130  Usage: escript [options] script.py [arguments...]  Usage: run-escript [options] script.py [arguments...]
131      -n nn       number of nodes to use      -n nn       number of nodes to use
132      -p np       number of MPI processes to spawn      -p np       number of MPI processes to spawn per node
133      -t nt       number of OpenMP threads to use      -t nt       number of OpenMP threads to use
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      ..reserved for future use ..      -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 108  if [ "$1" = "--help" ]; then Line 149  if [ "$1" = "--help" ]; then
149    echo "$HELP_TEXT"    echo "$HELP_TEXT"
150    exit 0    exit 0
151  fi  fi
152  #=======================================================================================  #==============================================================================
   
 # Avoid bug in hybrid runs with MPT MPI  
   
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:h:ecVviox' option  
156  do  do
157      case "$option" in      case "$option" in
158        "b")  DOBINARY=yes        "b")  DO_BINARY=y
159          ;;          ;;
160        "n")  ESCRIPT_NUM_NODES=$OPTARG        "m")  DO_VALGRIND=$OPTARG
161          ;;          ;;
162        "p")  ESCRIPT_NUM_PROCS=$OPTARG        "n")  ESCRIPT_NUM_NODES=$OPTARG
163          ;;          ;;
164        "t")  ESCRIPT_NUM_THREADS=$OPTARG        "p")  ESCRIPT_NUM_PROCS=$OPTARG
165          ;;          ;;
166        "f")  ESCRIPT_HOSTFILE=$OPTARG        "t")  ESCRIPT_NUM_THREADS=$OPTARG
167          ;;          ;;
168        "c")  cat $ESCRIPT_ROOT/lib/buildvars        "f")  ESCRIPT_HOSTFILE=$OPTARG
169          exit 0          ;;
170          ;;        "c")  cat "$BUILDINFO_FILE"
171        "V")  echo "escript-development(build "`grep svn_revision $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`")"          exit 0
172          exit 0          ;;
173          ;;        "V")  echo "escript-development(build "`get_buildvar svn_revision`")"
174        "h")  echo "$HELPTEXT"          exit 0
175          exit 0          ;;
176          ;;        "h")  echo "$HELP_TEXT"
177        "i")  DOINTERACTIVE=yes          exit 0
178          ;;          ;;
179        "e")  echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"        "i")  DO_INTERACTIVE=y
180          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"          ;;
181          echo "export PATH=$EXTRA_PATH:\$PATH"        "e")  echo "export LD_LIBRARY_PATH=$EXTRA_LD_LIBRARY_PATH:\$LD_LIBRARY_PATH"
182          if [ "`uname`" = "Darwin" ]          echo "export PYTHONPATH=$EXTRA_PYTHONPATH:\$PYTHONPATH"
183          then          echo "export PATH=$EXTRA_PATH:\$PATH"
184              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"          if [ "`uname`" = "Darwin" ]
185          fi          then
186          exit 0              echo "export DYLD_LIBRARY_PATH=$EXTRA_DYLD_LIBRARY_PATH:$EXTRA_LD_LIBRARY_PATH:\$DYLD_LIBRARY_PATH"
187          ;;          fi
188        "o")  ESCRIPT_CREATESTDFILES="yes"          exit 0
189          ;;          ;;
190        "v")  ESCRIPT_VERBOSE="yes"        "o")  ESCRIPT_CREATESTDFILES=y
191          ;;          ;;
192        "x")  echo "-x not implemented yet"        "v")  ESCRIPT_VERBOSE=y
193          exit 1          ;;
194          ;;        "x")  DO_XTERM=y
195        ?)    echo "$HELP_TEXT"          ;;
196          exit 1        ?)    echo "$HELP_TEXT"
197          ;;          exit 1
198      esac          ;;
199        esac
200  done  done
201  shift `expr $OPTIND - 1`  shift `expr $OPTIND - 1`
202  #==============================================  #==============================================
203  #  #
204  #   Read the MPI_FLAVOUR from the buildvars  #   Read MPI_FLAVOUR and WITH_OPENMP from the buildvars
205  #  #
206  MPI_FLAVOUR=`grep mpi_flavour $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  MPI_FLAVOUR=`get_buildvar mpi`
207  WITH_OPENMP=`grep useopenmp $ESCRIPT_ROOT/lib/buildvars |cut -d= -f2`  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."
211      if [ "$WITH_OPENMP" = "y" ]; then echo "OpenMP enabled."; fi      if [ "$WITH_OPENMP" = "1" ]; then echo "OpenMP enabled."; fi
212  fi  fi
213    
214  #  #
# Line 198  fi Line 236  fi
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
253      ESCRIPT_NUM_NODES=1      ESCRIPT_NUM_NODES=1
254      ESCRIPT_NUM_PROCS=1      ESCRIPT_NUM_PROCS=1
255  else  else
256      if [ ! -z $ESCRIPT_HOSTFILE ]      # use the PBS_NODEFILE if not otherwise specified
257        if [ ! -z "$PBS_NODEFILE" ] && [ -z "$ESCRIPT_HOSTFILE" ]
258        then
259            ESCRIPT_HOSTFILE=$PBS_NODEFILE
260        fi
261    
262        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 ]
# Line 239  else Line 285  else
285    
286      if [ -z $ESCRIPT_NUM_NODES ]      if [ -z $ESCRIPT_NUM_NODES ]
287      then      then
288        ESCRIPT_NUM_NODES=1          ESCRIPT_NUM_NODES=1
289      fi      fi
290    
291      if [ -z $ESCRIPT_NUM_PROCS ]      if [ -z $ESCRIPT_NUM_PROCS ]
292      then      then
293        ESCRIPT_NUM_PROCS=1          ESCRIPT_NUM_PROCS=1
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
301  fi  fi
302    
303  if [ "$WITH_OPENMP" = "y" ]  if [ "$WITH_OPENMP" = "1" ]
304  then  then
305     if [ -z $ESCRIPT_NUM_THREADS ]     if [ -z $ESCRIPT_NUM_THREADS ]
306     then     then
# Line 269  then Line 315  then
315          echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."          echo "ESCRIPT_NUM_THREADS is $ESCRIPT_NUM_THREADS."
316     fi     fi
317  else  else
318     if [[ ( ! -z $ESCRIPT_NUM_THREADS ) && ( $ESCRIPT_NUM_THREADS != 1 ) ]]     if [ ! -z $ESCRIPT_NUM_THREADS ] && [ $ESCRIPT_NUM_THREADS != 1 ]
319     then     then
320         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."
321     fi     fi
# Line 278  fi Line 324  fi
324  #  #
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
332  fi  fi
333    
334  #  #
335  # 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
336  #  #
337  if [[ ( ( ! -z $DOINTERACTIVE ) || ( $# -eq 0 ) ) && ( $TOTPROC -gt 1) ]]  if ([ ! -z $DO_INTERACTIVE ] || [ $# -eq 0 ]) && ([ $TOTPROC -gt 1 ])
338  then  then
339    echo "Interactive mode cannot be used with more than one process"      echo "Interactive mode cannot be used with more than one process"
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
349         PYTHON_MPI=$PYTHON_MPI_NULL          PYTHON_MPI=$PYTHON_MPI_NULL
350     fi      fi
351  else  else
352      PYTHON_MPI=$PYTHON_MPI_NULL      PYTHON_MPI=$PYTHON_MPI_NULL
353  fi  fi
354  #=========================================================================================================  #==============================================================================
355  # Must have at least one command-line arg: the python script  # Must have at least one command-line arg: the python script
356  if [ $# -eq 0 ]  if [ $# -eq 0 ]
357  then  then
358    if [ ! -z $DOBINARY ]      if [ ! -z $DO_BINARY ]
359    then      then
360      echo "No program to run was specified. Exiting."          echo "No program to run was specified. Exiting."
361      exit 1          exit 1
362    fi      else
363            DO_INTERACTIVE=y
364        fi
365  fi  fi
366  if [ -z $@ ]  
367    #==============================================================================
368    
369    if [ ! -z $DO_XTERM ]
370  then  then
371     if [ ! -z $DOBINARY ]      EXEC_CMD="xterm -e"
372     then  else
373         echo "Program must be given."      EXEC_CMD=""
        exit 1  
    else  
       DOINTERACTIVE="yes"  
    fi  
374  fi  fi
375    
376  #=========================================================================================================  if [ ! -z "$DO_VALGRIND" ]
 if [ ! -z $DOBINARY ]  
377  then  then
378      EXEC_CMD="$@"      VALGRIND_BIN=`which valgrind 2>/dev/null`
379        if [ $? -eq 0 ]; then
380            LOGDIR=$ESCRIPT_ROOT/valgrind_logs
381            [ -d $LOGDIR ] || mkdir $LOGDIR
382            if [ ${DO_VALGRIND:0:1} = "c" ];
383            then
384                # run callgrind
385                LOGFILE=${LOGDIR}/callgrind.%p.xml
386                VALGRIND="valgrind --tool=callgrind --callgrind-out-file=$LOGFILE"
387                EXEC_CMD="$EXEC_CMD $VALGRIND"
388            else
389                # run memcheck by default
390                LAST_N=`ls -1 $LOGDIR|grep "^memcheck"|tail -1|cut -d. -f2`
391                NEW_N=`printf "%04d" $((10#$LAST_N + 1))`
392                LOGFILE=${LOGDIR}/memcheck.${NEW_N}.xml
393                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"
394                EXEC_CMD="$EXEC_CMD $VALGRIND"
395            fi
396        else
397            echo "Execution with valgrind requested but valgrind not in path!"
398            exit 1
399        fi
400    fi
401    
402    if [ ! -z $DO_BINARY ]
403    then
404        EXEC_CMD="$EXEC_CMD $@"
405  else  else
406      if [ "$MPI_FLAVOUR" = "none" ]      # Check to see if the python version we were compiled with matches the
407      then      # one of PYTHON_CMD.
408          # Check to see if the python version we were compiled with matches the one of EXEC_CMD      compfull=`get_buildvar python_version`
409          # We should only do this check if they are running a python script      compversion=`echo $compfull | cut -d. -f1,2`
410          if [ -f $ESCRIPT_ROOT/lib/pyversion ]      compmajor=`echo $compfull | cut -d. -f1`
411        if [ "$PYTHON_CMD" = "python" ] # if people have customised the command they
412        then                                # might not want us changing it
413            if [ "$compmajor" = "3" ]
414          then          then
415             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  
416          fi          fi
417      if [ ! -z $DOINTERACTIVE ]      fi
418        intversion=`$PYTHON_CMD -c 'from __future__ import print_function;import sys;print("%d.%d"%(sys.version_info[0], sys.version_info[1]))'`
419        if [ "$compversion" != "$intversion" ]
420        then
421            echo "Python versions do not match. Escript was compiled for "$compversion"."
422            echo "Current version of Python appears to be "$intversion"."
423            exit 1
424        fi
425        if [ "$MPI_FLAVOUR" = "none" ]
426        then
427            if [ ! -z $DO_INTERACTIVE ]
428          then          then
429             EXEC_CMD="$PYTHON_CMD -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD -i $@"
430          else          else
431             EXEC_CMD="$PYTHON_CMD $@"             EXEC_CMD="$EXEC_CMD $PYTHON_CMD $@"
432          fi          fi
433      else      else
434      if [ ! -z $DOINTERACTIVE ]          if [ ! -z $DO_INTERACTIVE ]
435          then          then
436             EXEC_CMD="$PYTHON_MPI -i $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI -i $@"
437          else          else
438             EXEC_CMD="$PYTHON_MPI $@"             EXEC_CMD="$EXEC_CMD $PYTHON_MPI $@"
439          fi          fi
440      fi      fi
441  fi  fi
442  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
443  #===============================================================================================  #==============================================================================
444  #  #
445  #   now we start to spwan things:  #   now we start to spawn things:
446  #  #
447  if [ "$WITH_OPENMP" = "y" ]  if [ "$WITH_OPENMP" = "1" ]
448  then  then
449     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS     export OMP_NUM_THREADS=$ESCRIPT_NUM_THREADS
450     EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"     EXPORT_ENV="$EXPORT_ENV,OMP_NUM_THREADS"
# Line 380  then Line 458  then
458  #=============== OpenMPI ===================================  #=============== OpenMPI ===================================
459  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]  elif [ "$MPI_FLAVOUR" = "OPENMPI" ]
460  then  then
461     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
462     then     then
463        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"`
464        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//,/ -x } --bynode -np $TOTPROC --bind-to-socket --cpus-per-rank $ESCRIPT_NUM_THREADS --host $HOST_LIST $EXEC_CMD"
465     else     else
466        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//,/ -x } --cpus-per-rank $ESCRIPT_NUM_THREADS -np $TOTPROC $EXEC_CMD"
467     fi     fi
468     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi     if [ ! -z $ESCRIPT_VERBOSE ]; then echo "MPI command is \"$CMD\"."; fi
469     $CMD     $CMD
# Line 395  then Line 473  then
473  elif [ "$MPI_FLAVOUR" = "INTELMPI" ]  elif [ "$MPI_FLAVOUR" = "INTELMPI" ]
474  then  then
475    
476     if [ "$WITH_OPENMP" = "y" ]     if [ "$WITH_OPENMP" = "1" ]
477     then     then
478         export I_MPI_PIN_DOMAIN=omp         export I_MPI_PIN_DOMAIN=omp
479         EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"         EXPORT_ENV="$EXPORT_ENV, I_MPI_PIN_DOMAIN"
480     fi     fi
481    
482     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
483     then     then
484        mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE        mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"
485        if [ $? -ne 0 ]        if [ $? -ne 0 ]
486        then        then
487           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."
# Line 432  elif [ "$MPI_FLAVOUR" = "MPT" ] Line 510  elif [ "$MPI_FLAVOUR" = "MPT" ]
510  then  then
511     export MPI_NUM_MEMORY_REGIONS=0     export MPI_NUM_MEMORY_REGIONS=0
512     EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"     EXPORT_ENV="$EXPORT_ENV,MPI_NUM_MEMORY_REGIONS"
513     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
514     then     then
515        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"`
516        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"        CMD="mpirun $HOST_LIST -np $ESCRIPT_NUM_PROCS $EXEC_CMD"
517     else     else
518        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
# Line 445  then Line 523  then
523  #=============== MPICH ===================================  #=============== MPICH ===================================
524  elif [ "$MPI_FLAVOUR" = "MPICH" ]  elif [ "$MPI_FLAVOUR" = "MPICH" ]
525  then  then
526     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
527     then     then
528        touch $HOSTFILE2        touch "$HOSTFILE2"
529        for (( i=1;i<=$ESCRIPT_NUM_PROCS;i+=1 )) ; do cat $HOSTFILE >> $HOSTFILE2  ; done        for (( i=1;i<=$ESCRIPT_NUM_PROCS;i+=1 )) ; do cat "$HOSTFILE" >> "$HOSTFILE2"  ; done
530        CMD="mpirun -machinefile $HOSTFILE2  -np $TOTPROC $EXEC_CMD"        CMD="mpirun -machinefile \"$HOSTFILE2\"  -np $TOTPROC $EXEC_CMD"
531     else     else
532        CMD="mpirun -np $TOTPROC $EXEC_CMD"        CMD="mpirun -np $TOTPROC $EXEC_CMD"
533     fi     fi
# Line 459  then Line 537  then
537  #=============== MPICH2 ===================================  #=============== MPICH2 ===================================
538  elif [ "$MPI_FLAVOUR" = "MPICH2" ]  elif [ "$MPI_FLAVOUR" = "MPICH2" ]
539  then  then
540     if [ ! -z $HOSTFILE ]     if [ ! -z "$HOSTFILE" ]
541     then     then
542           mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f $HOSTFILE           mpdboot -n $ESCRIPT_NUM_NODES -r ssh -f "$HOSTFILE"
543           if [ $? -ne 0 ]           if [ $? -ne 0 ]
544           then           then
545              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."
# Line 489  else Line 567  else
567     echo "unknown MPI flavour '$MPI_FLAVOUR'."     echo "unknown MPI flavour '$MPI_FLAVOUR'."
568  fi  fi
569  exit $EXIT_CODE  exit $EXIT_CODE
570    

Legend:
Removed from v.2923  
changed lines
  Added in v.4664

  ViewVC Help
Powered by ViewVC 1.1.26