Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
check that specified platform and hostfile exist.
[simgrid.git] / src / smpi / smpirun.in
index 5d25da1..a57e61a 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,29 @@ while true; do
       NETWORK_LATENCY="$2"
       shift 2
     ;;
+   "-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
+    ;;
+
+   "-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,12 +59,18 @@ done
 EXEC="$1"
 shift
 
-PLATFORMTMP="$(mktemp tmpXXXXXX)"
-#PLATFORMTMP="pla.xml"
+##-----------------------------------
+
+
+
 
-cat > ${PLATFORMTMP} <<PLATFORMHEAD
+##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
+if [ -z "${PLATFORM}" ]; then  
+       PLATFORMTMP="$(mktemp tmpXXXXXX)"
+
+       cat > ${PLATFORMTMP} <<PLATFORMHEAD
 <?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "surfxml.dtd">
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
 <platform version="2">
 PLATFORMHEAD
 
@@ -65,17 +94,42 @@ 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 "surfxml.dtd">
+<!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}
+    echo "    <argument value=\"$j\"/> <!-- rank -->" >> ${APPLICATIONTMP}
   for ARG in $*; do
     echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
   done
@@ -83,13 +137,24 @@ 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
 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}