Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / smpi / smpirun.in
index 80611b0..65b9c1b 100755 (executable)
@@ -68,6 +68,8 @@ EXTOPT=""
 WRAPPER=""
 HOSTFILE=""
 HOSTFILETMP=0
+MAPOPT=0
+REPLAY=0
 
 unset pid
 
@@ -166,7 +168,7 @@ while true; do
            shift 1
            ;;
         "-map")
-           MAPOPT="true"
+           MAPOPT=1
             shift 1
             ;;
         "-trace")
@@ -239,6 +241,14 @@ while true; do
     esac
 done
 
+# check if we still have at least one parameter beyond options
+if [ $# -eq 0 ]
+then
+    echo "Error: no program to execute!"
+    usage
+    exit
+fi
+
 if [ -n "$WRAPPER" ]; then
     EXEC="$WRAPPER $1"
 else
@@ -374,7 +384,6 @@ APPLICATIONHEAD
 ##---- cache hostnames of hostfile---------------
 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
     hostnames=$(cat ${HOSTFILE} | tr '\n\r' '  ')
-    NUMHOSTS=$(cat ${HOSTFILE} | wc -l)
 fi
 
 if [ "${EXTOPT}" = "smpi_replay" ]; then
@@ -382,6 +391,7 @@ if [ "${EXTOPT}" = "smpi_replay" ]; then
     if [ -n "${APP_TRACES}" ] && [ -f "${APP_TRACES}" ]; then
         hosttraces=$(cat ${APP_TRACES} | tr '\n\r' '  ' )
         NUMTRACES=$(cat ${APP_TRACES} | wc -l)
+        REPLAY=1
     else
         printf "File not found: %s\n" "${APP_TRACES:-\${APP_TRACES\}}" >&2
         exit 1
@@ -406,35 +416,36 @@ else
     done
 fi
 
+set -- $hostnames
+
 ##---- generate <process> tags------------------------------
+#prepare arguments at once
+for ARG in $PROC_ARGS; do
+  XML_ARGS="${XML_ARGS}""<argument value=\"${ARG}\"/>
+"
+done
+
 for i in ${SEQ}
 do
-    if [ -n "${HOSTFILE}" ]; then
-       j=$(( $i % ${NUMHOSTS} + 1 ))
-    fi
+    j=$(( $i % ${hostfile_procs} + 1 ))
+    host=$(eval "echo \${$j}")
+
     ##---- optional display of ranks to process mapping
-    if [ -n "${MAPOPT}" ]; then
-       echo "[rank $i] -> $(echo $hostnames|cut -d' ' -f$j)"
+    if [ ${MAPOPT} = 1 ]; then
+      echo "[rank $i] -> $host"
     fi
 
-    if [ -z "$(echo $hostnames|cut -d' ' -f$j)" ]; then
-       host="host"$($j)
-    else
-       host="$(echo $hostnames|cut -d' ' -f$j)"
-    fi
-    echo "  <process host=\"${host}\" function=\"$i\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
-    echo "    <argument value=\"1\"/> <!-- instance -->" >> ${APPLICATIONTMP}
-    echo "    <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
-    if [ "${EXTOPT}" = "smpi_replay" ]; then
+    echo "  <process host=\"${host}\" function=\"$i\"> <!-- function name used only for logging -->
+    <argument value=\"1\"/> <!-- instance -->
+    <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
+    if [ ${REPLAY} = 1 ]; then
         if  [ ${NUMTRACES} -gt 1 ]; then
             echo "    <argument value=\"$(echo $hosttraces|cut -d' ' -f$j)\"/>" >> ${APPLICATIONTMP}
         else
             echo "    <argument value=\"$(echo $hosttraces|cut -d' ' -f1)\"/>" >> ${APPLICATIONTMP}
         fi
     else 
-        for ARG in $PROC_ARGS; do
-            echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
-        done
+    echo ${XML_ARGS} >> ${APPLICATIONTMP}
     fi
     echo "  </process>" >> ${APPLICATIONTMP}
 done
@@ -509,6 +520,22 @@ wait $pid
 status=$?
 pid=""
 
+# Keep temporary files on failures to help debugging
+#
+if [ ${status} -ne 0 ] ; then
+    if [ -z ${KEEP} ]; then
+        echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PRIVATIZE} ${PLATFORMTMP} ${APPLICATIONTMP}
+        if [ ${HOSTFILETMP} = 1 ] ; then
+            echo "Generated hostfile ${HOSTFILE} kept."
+        fi
+        if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
+            echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
+        fi
+    fi
+    echo "Execution failed with code ${status}."
+    KEEP=true
+fi
+
 smpirun_cleanup
 
 exit $status