Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Actor: make the refcount observable, and improve debug messages
[simgrid.git] / src / smpi / smpirun.in
index 8d28059..72d3819 100755 (executable)
@@ -35,6 +35,9 @@ Usage: $0 [OPTIONS] -platform <xmldesc> -hostfile <hostfile> program [program-op
 Options:
   -keep-temps                # don't remove the generated files after execution
   -wrapper <command>         # use command to run the program (e.g. "valgrind" or "gdb --args")
+  -gdb                       # run within GDB (-wrapper "gdb --args" -keep-temps)
+  -lldb                      # run within LLDB (-wrapper "lldb --" -keep-temps)
+  -vgdb                      # run within Valgrind+GDB (-wrapper "valgrind --vgdb=yes --vgdb-error=0" -keep-temps)
   -map                       # display the machine on which each process rank is mapped
   -np <numprocs>             # use that amount of processes from the hostfile.
                              # By default, all processes of the hostfile are used.
@@ -195,14 +198,32 @@ while true; do
             shift 1
             ;;
         "-keep-temps")
-           KEEP="true"
-           SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
+            KEEP="true"
+            SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
             shift 1
             ;;
         "-wrapper")
             WRAPPER="$2"
             shift 2
             ;;
+        "-gdb")
+            WRAPPER="gdb --args"
+            KEEP="true"
+            SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
+            shift 1
+            ;;
+        "-vgdb")
+            WRAPPER="valgrind --vgdb=yes --vgdb-error=0"
+            KEEP="true"
+            SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
+            shift 1
+            ;;
+        "-lldb")
+            WRAPPER="lldb --"
+            KEEP="true"
+            SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
+            shift 1
+            ;;
         "-help" | "--help" | "-h")
             usage
             exit 0
@@ -278,32 +299,47 @@ fi
 if [ -z "${HOSTFILE}" ] ; then
     HOSTFILETMP=1
     HOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
-    perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
-    # put all <cluster tag on its own line.
-    cat ${PLATFORM} | tr '\n' ' ' | sed 's/<cluster/\n<cluster/' | \
-      perl -ne 'if (m/.*<cluster.*?prefix="(.*?)".*?radical="(.*?)".*?suffix="(.*?)".*/s) {
-                my ($pre,$rad,$post)=($1,$2,$3);
-               for my $elm (split(",",$rad)) {
-                 if ($elm=~/^([^-]*?)-([^-]*)$/) {
-                    for (my $i=$1; $i<=$2;$i++) {
-                       print "$pre$i$post\n";
-                    }
-                 } else {
-                    print "$pre$elm$post\n";
-                 }
-               }
-             } elsif (/<cluster/) {
-            die ("Unparsable cluster tag. smpirun uses a primitive regular expression to parse cluster tags. Either provide a hostfile yourself or give the attributes prefix, radical and suffix IN THAT ORDER.");
-             }' ${PLATFORM} >> ${HOSTFILE}
+    @PYTHON_EXECUTABLE@ -c '
+import xml.etree.ElementTree as ET
+import sys
+import re
+
+tree = ET.parse(sys.stdin)
+
+for elem in tree.findall(".//host"):
+    print(elem.attrib["id"])
+
+for elem in tree.findall(".//cluster"):
+    prefix = elem.attrib["prefix"]
+    radical = elem.attrib["radical"]
+    suffix = elem.attrib["suffix"]
+    for r in radical.split(","):
+        m = re.match("^([^-]*?)-([^-]*)$", r)
+        if m:
+            for i in range(int(m.group(1)), int(m.group(2))):
+                print(prefix + str(i) + suffix)
+        else:
+            print(prefix + r + suffix)
+            ' < ${PLATFORM} > ${HOSTFILE}
 fi
 UNROLLEDHOSTFILETMP=0
 
-#parse if our lines are terminated by :num_process
-multiple_processes=$(grep -c ":" $HOSTFILE)
-if [ "${multiple_processes}" -gt 0 ] ; then
+# parse if our lines are terminated by :num_process
+if grep -q ':' $HOSTFILE ; then
     UNROLLEDHOSTFILETMP=1
     UNROLLEDHOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
-    perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/'  ${HOSTFILE}  > ${UNROLLEDHOSTFILE}
+    @PYTHON_EXECUTABLE@ -c '
+import sys
+import re
+
+for line in sys.stdin:
+    m = re.match("(.*):(.*)", line)
+    if m:
+        for i in range(0, int(m.group(2))):
+            print(m.group(1))
+    else:
+        print(line.strip())
+' < ${HOSTFILE}  > ${UNROLLEDHOSTFILE}
     if [ ${HOSTFILETMP} = 1 ] ; then
         rm ${HOSTFILE}
         HOSTFILETMP=0
@@ -484,6 +520,7 @@ if [ -n "${TRACE_ACTIVE}" ]; then
 fi
 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
 
+# Do not remove, this variable may be used by user code (e.g. StarPU)
 export SMPI_GLOBAL_SIZE=${NUMPROCS}
 if [ -n "${KEEP}" ] ; then
     echo ${EXEC} ${PRIVATIZE} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}