Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a flag to keep the temp files around, and pass configuration options to the simulator
[simgrid.git] / src / smpi / smpirun.in
index 9ad2663..0fda9b4 100755 (executable)
@@ -29,19 +29,49 @@ while true; do
     ;;
    "-platform")
        PLATFORM="$2"
+      if [ ! -f ${PLATFORM} ]; then
+               echo "[$0] ** error: the file '${PLATFORM}' does not exist. Aborting."
+               exit 1
+      fi
        shift 2
     ;;
    "-hostfile")
        HOSTFILE="$2"
+      if [ ! -f ${HOSTFILE} ]; then
+               echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
+               exit 1
+      fi
        shift 2
     ;;
 
+   "-map")
+       MAPOPT="on"
+      shift 1
+   ;;
+
+   "-quiet")
+       QUIET="true"
+      shift 1
+   ;;
+
+   "-keep-temps")
+       KEEP="true"
+      shift 1
+   ;;
+
    "-help" | "--help" | "-h") 
       echo "usage:"
-      echo "$0 [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] [-platform <xmldesc>] [-hostfile <hostfile>] program [program-options]"
+      echo "$0 [-quiet] [-keep-temps] [-np <numprocs>] -platform <xmldesc> -hostfile <hostfile> [-map] program [program-options]"
+      echo "or (deprecated usage):"
+      echo "$0 [-quiet] [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]"
       echo
       exit
    ;;
+   
+   "--cfg="*)
+     SIMOPTS="$SIMOPTS $1"
+     shift 1
+   ;;
     *)
       break
     ;;
@@ -51,10 +81,14 @@ done
 EXEC="$1"
 shift
 
+##-----------------------------------
+
+
+
+
 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
 if [ -z "${PLATFORM}" ]; then  
        PLATFORMTMP="$(mktemp tmpXXXXXX)"
-       #PLATFORMTMP="pla.xml"
 
        cat > ${PLATFORMTMP} <<PLATFORMHEAD
 <?xml version='1.0'?>
@@ -101,6 +135,7 @@ APPLICATIONHEAD
 ##---- cache hostnames of hostfile---------------
 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
        hostnames=(`cat ${HOSTFILE} | tr \\\n " "`)
+      NUMHOSTS=`cat ${HOSTFILE} | wc -l`
 fi
 
 ##----------------------------------------------------------
@@ -109,39 +144,48 @@ fi
 ##  in hostfile (where -hostfile hostfile), or "host$i" if
 ##  hostfile has less than i lines.
 ##----------------------------------------------------------
-for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
-  j=$(( $i-1 ))
+
+##---- generate <process> tags------------------------------
+
+for i in `seq 0 $((${NUMPROCS}-1))` 
+do
+  if [ -n "${HOSTFILE}" ]; then
+       j=$(( $i % ${NUMHOSTS} ))
+  fi 
+  ##---- optional display of ranks to process mapping
+  if [ -n ${MAPOPT} ]; then
+       echo "[rank $i] -> ${hostnames[$j]}"  
+  fi
+
   if [ -z "${hostnames[$j]}" ]; then
-       host="host"$i
+       host="host"$(($j+1))
   else
        host="${hostnames[$j]}"
   fi
   echo "  <process host=\"${host}\" function=\"smpi_simulated_main\">" >> ${APPLICATIONTMP}
+  echo "    <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
   for ARG in $*; do
     echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
   done
   echo "  </process>" >> ${APPLICATIONTMP}
 done
 
-for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
-  j=$(( $i-1 ))
-  if [ -z "${hostnames[$j]}" ]; then
-       host="host"$i
-  else
-       host="${hostnames[$j]}"
-  fi
-done
-
 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
 </platform>
 APPLICATIONFOOT
 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
 
-echo ${EXEC} ${PLATFORMTMP} ${APPLICATIONTMP}
-${EXEC} ${PLATFORMTMP} ${APPLICATIONTMP}
+if [ -z "${QUIET}" ] ; then
+  echo ${EXEC} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
+fi
+${EXEC} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
 
-echo "[$0] cleaning up temp files"
-if [ -z "${PLATFORM}" ]; then
+if [ "x$?" == "x0" ] && [ -n ${KEEP} ] ; then
+  if [ -z "${QUIET}" ] ; then
+    echo "[$0] cleaning up temp files" 
+  fi
+   if [ -z "${PLATFORM}" ]; then
        rm ${PLATFORMTMP} 
-fi
-#rm ${APPLICATIONTMP}
+   fi
+   rm ${APPLICATIONTMP}
+fi
\ No newline at end of file