Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
extended smpirun accepting -platform and -hostfile
[simgrid.git] / src / smpi / smpirun.in
index 24168a0..bcd1e93 100755 (executable)
@@ -15,7 +15,7 @@ POWER="${DEFAULT_POWER}"
 
 while true; do
   case "$1" in
-   "-np")
+   "-np" | "-n")
       NUMPROCS="$2"
       shift 2
     ;;
@@ -27,9 +27,18 @@ while true; do
       NETWORK_LATENCY="$2"
       shift 2
     ;;
-   "-help")
+   "-platform")
+       PLATFORM="$2"
+       shift 2
+    ;;
+   "-hostfile")
+       HOSTFILE="$2"
+       shift 2
+    ;;
+
+   "-help" | "--help" | "-h") 
       echo "usage:"
-      echo "$0 [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]"
+      echo "$0 [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] [-platform <xmldesc>] [-hostfile <hostfile>] program [program-options]"
       echo
       exit
    ;;
@@ -42,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">
@@ -71,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
@@ -89,13 +124,26 @@ 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 --------------------------------------
 
 ${EXEC} ${PLATFORMTMP} ${APPLICATIONTMP}
-rm ${PLATFORMTMP} ${APPLICATIONTMP}
+
+echo "[$0] cleaning up temp files"
+if [ -z "${PLATFORM}" ]; then
+       rm ${PLATFORMTMP} 
+fi
+rm ${APPLICATIONTMP}