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 e18b271..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,10 +51,12 @@ 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 SYSTEM "simgrid.dtd">
 <platform version="2">
@@ -65,17 +82,41 @@ cat >> ${PLATFORMTMP} <<PLATFORMFOOT
 </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 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>
 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}