Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SMPI: get the main process launch the sender and receiver ones (will ease passing...
[simgrid.git] / src / smpi / smpirun.in
index 78aba19..29e4c87 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 DEFAULT_LOOPBACK_BANDWIDTH="498000000"
 DEFAULT_LOOPBACK_LATENCY="0.000004"
 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))"
@@ -15,7 +15,7 @@ POWER="${DEFAULT_POWER}"
 
 while true; do
   case "$1" in
-   "-np")
+   "-np" | "-n")
       NUMPROCS="$2"
       shift 2
     ;;
@@ -27,6 +27,21 @@ while true; do
       NETWORK_LATENCY="$2"
       shift 2
     ;;
+   "-platform")
+       PLATFORM="$2"
+       shift 2
+    ;;
+   "-hostfile")
+       HOSTFILE="$2"
+       shift 2
+    ;;
+
+   "-help" | "--help" | "-h") 
+      echo "usage:"
+      echo "$0 [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] [-platform <xmldesc>] [-hostfile <hostfile>] program [program-options]"
+      echo
+      exit
+   ;;
     *)
       break
     ;;
@@ -36,46 +51,72 @@ done
 EXEC="$1"
 shift
 
-PLATFORMTMP="$(mktemp tmpXXXXXX)"
-#PLATFORMTMP="pla.xml"
+##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
+if [ -z "${PLATFORM}" ]; then  
+       PLATFORMTMP="$(mktemp tmpXXXXXX)"
+       #PLATFORMTMP="pla.xml"
 
-cat > ${PLATFORMTMP} <<PLATFORMHEAD
+       cat > ${PLATFORMTMP} <<PLATFORMHEAD
 <?xml version='1.0'?>
-<!DOCTYPE platform_description SYSTEM "surfxml.dtd">
-<platform_description version="1">
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
 PLATFORMHEAD
 
 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
-  echo "  <cpu name=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
-  echo "  <network_link name=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
-  echo "  <network_link name=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
+  echo "  <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
+  echo "  <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
+  echo "  <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
 done
 
 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
   for (( j=${NUMPROCS}; $j ; j=$j-1 )) do
     if [ $i -eq $j ]; then
-      echo "  <route src=\"host$i\" dst=\"host$j\"><route_element name=\"loop$i\"/></route>" >> ${PLATFORMTMP}
+      echo "  <route src=\"host$i\" dst=\"host$j\"><link:ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
     else
-      echo "  <route src=\"host$i\" dst=\"host$j\"><route_element name=\"link$i\"/><route_element name=\"link$j\"/></route>" >> ${PLATFORMTMP}
+      echo "  <route src=\"host$i\" dst=\"host$j\"><link:ctn id=\"link$i\"/><link:ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
     fi
   done
 done
 
 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
-</platform_description>
+</platform>
 PLATFORMFOOT
 
+else
+       PLATFORMTMP=${PLATFORM}
+fi
+##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
+
+##-------------------------------- DEFAULT APPLICATION --------------------------------------
 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
 #APPLICATIONTMP="app.xml"
 
+
 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
 <?xml version='1.0'?>
-<!DOCTYPE platform_description SYSTEM "surfxml.dtd">
-<platform_description version="1">
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
 APPLICATIONHEAD
 
+##---- cache hostnames of hostfile---------------
+if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
+       hostnames=(`cat ${HOSTFILE} | tr \\\n " "`)
+fi
+
+##----------------------------------------------------------
+##  generate application.xml with hostnames from hostfile:
+##  the name of host_i (1<=i<=p, where -np p) is the line i
+##  in hostfile (where -hostfile hostfile), or "host$i" if
+##  hostfile has less than i lines.
+##----------------------------------------------------------
 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
-  echo "  <process host=\"host$i\" function=\"smpi_simulated_main\">" >> ${APPLICATIONTMP}
+  j=$(( $i-1 ))
+  if [ -z "${hostnames[$j]}" ]; then
+       host="host"$i
+  else
+       host="${hostnames[$j]}"
+  fi
+  echo "  <process host=\"${host}\" function=\"smpi_simulated_main\">" >> ${APPLICATIONTMP}
   for ARG in $*; do
     echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
   done
@@ -83,13 +124,27 @@ for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
 done
 
 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
-  echo "  <process host=\"host$i\" function=\"smpi_sender\"/>" >> ${APPLICATIONTMP}
-  echo "  <process host=\"host$i\" function=\"smpi_receiver\"/>" >> ${APPLICATIONTMP}
+  j=$(( $i-1 ))
+  if [ -z "${hostnames[$j]}" ]; then
+       host="host"$i
+  else
+       host="${hostnames[$j]}"
+  fi
+#  echo "  <process host=\"${host}\" function=\"smpi_sender\"/>" >> ${APPLICATIONTMP}
+#  echo "  <process host=\"${host}\" function=\"smpi_receiver\"/>" >> ${APPLICATIONTMP}
 done
 
 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
-</platform_description>
+</platform>
 APPLICATIONFOOT
+##-------------------------------- end DEFAULT APPLICATION --------------------------------------
 
+echo ${EXEC} ${PLATFORMTMP} ${APPLICATIONTMP}
 ${EXEC} ${PLATFORMTMP} ${APPLICATIONTMP}
-rm ${PLATFORMTMP} ${APPLICATIONTMP}
+
+echo "[$0] cleaning up temp files"
+if [ -z "${PLATFORM}" ]; then
+       rm ${PLATFORMTMP} 
+fi
+#rm ${APPLICATIONTMP}