Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify smpirun script (and kill some perl)
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 9 Jul 2019 23:19:45 +0000 (01:19 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 10 Jul 2019 14:44:48 +0000 (16:44 +0200)
src/smpi/smpirun.in

index d095d29..72d3819 100755 (executable)
@@ -299,8 +299,6 @@ 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.
     @PYTHON_EXECUTABLE@ -c '
 import xml.etree.ElementTree as ET
 import sys
@@ -308,6 +306,9 @@ 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"]
@@ -319,16 +320,26 @@ for elem in tree.findall(".//cluster"):
                 print(prefix + str(i) + suffix)
         else:
             print(prefix + r + suffix)
-            ' < ${PLATFORM} >> ${HOSTFILE}
+            ' < ${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