Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SMPI: Pass the rank from smpirun to processes through their command line in deploymen...
[simgrid.git] / src / smpi / smpirun.in
1 #!/bin/bash
2 DEFAULT_LOOPBACK_BANDWIDTH="498000000"
3 DEFAULT_LOOPBACK_LATENCY="0.000004"
4 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))"
5 DEFAULT_NETWORK_LATENCY="0.000005"
6 DEFAULT_NUMPROCS="4"
7 DEFAULT_POWER="100"
8
9 LOOPBACK_BANDWIDTH="${DEFAULT_LOOPBACK_BANDWIDTH}"
10 LOOPBACK_LATENCY="${DEFAULT_LOOPBACK_LATENCY}"
11 NETWORK_BANDWIDTH="${DEFAULT_NETWORK_BANDWIDTH}"
12 NETWORK_LATENCY="${DEFAULT_NETWORK_LATENCY}"
13 NUMPROCS="${DEFAULT_NUMPROCS}"
14 POWER="${DEFAULT_POWER}"
15
16 while true; do
17   case "$1" in
18    "-np" | "-n")
19       NUMPROCS="$2"
20       shift 2
21     ;;
22    "-bandwidth")
23       NETWORK_BANDWIDTH="$2"
24       shift 2
25     ;;
26    "-latency")
27       NETWORK_LATENCY="$2"
28       shift 2
29     ;;
30    "-platform")
31         PLATFORM="$2"
32         shift 2
33     ;;
34    "-hostfile")
35         HOSTFILE="$2"
36         shift 2
37     ;;
38
39    "-help" | "--help" | "-h") 
40       echo "usage:"
41       echo "$0 [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] [-platform <xmldesc>] [-hostfile <hostfile>] program [program-options]"
42       echo
43       exit
44    ;;
45     *)
46       break
47     ;;
48   esac
49 done
50
51 EXEC="$1"
52 shift
53
54 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
55 if [ -z "${PLATFORM}" ]; then  
56         PLATFORMTMP="$(mktemp tmpXXXXXX)"
57
58         cat > ${PLATFORMTMP} <<PLATFORMHEAD
59 <?xml version='1.0'?>
60 <!DOCTYPE platform SYSTEM "simgrid.dtd">
61 <platform version="2">
62 PLATFORMHEAD
63
64 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
65   echo "  <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
66   echo "  <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
67   echo "  <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
68 done
69
70 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
71   for (( j=${NUMPROCS}; $j ; j=$j-1 )) do
72     if [ $i -eq $j ]; then
73       echo "  <route src=\"host$i\" dst=\"host$j\"><link:ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
74     else
75       echo "  <route src=\"host$i\" dst=\"host$j\"><link:ctn id=\"link$i\"/><link:ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
76     fi
77   done
78 done
79
80 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
81 </platform>
82 PLATFORMFOOT
83
84 else
85         PLATFORMTMP=${PLATFORM}
86 fi
87 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
88
89 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
90 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
91 #APPLICATIONTMP="app.xml"
92
93
94 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
95 <?xml version='1.0'?>
96 <!DOCTYPE platform SYSTEM "simgrid.dtd">
97 <platform version="2">
98 APPLICATIONHEAD
99
100 ##---- cache hostnames of hostfile---------------
101 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
102         hostnames=(`cat ${HOSTFILE} | tr \\\n " "`)
103 fi
104
105 ##----------------------------------------------------------
106 ##  generate application.xml with hostnames from hostfile:
107 ##  the name of host_i (1<=i<=p, where -np p) is the line i
108 ##  in hostfile (where -hostfile hostfile), or "host$i" if
109 ##  hostfile has less than i lines.
110 ##----------------------------------------------------------
111 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
112   j=$(( $i-1 ))
113   if [ -z "${hostnames[$j]}" ]; then
114         host="host"$i
115   else
116         host="${hostnames[$j]}"
117   fi
118   echo "  <process host=\"${host}\" function=\"smpi_simulated_main\">" >> ${APPLICATIONTMP}
119     echo "    <argument value=\"$j\"/> <!-- rank -->" >> ${APPLICATIONTMP}
120   for ARG in $*; do
121     echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
122   done
123   echo "  </process>" >> ${APPLICATIONTMP}
124 done
125
126 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
127   j=$(( $i-1 ))
128   if [ -z "${hostnames[$j]}" ]; then
129         host="host"$i
130   else
131         host="${hostnames[$j]}"
132   fi
133 done
134
135 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
136 </platform>
137 APPLICATIONFOOT
138 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
139
140 echo ${EXEC} ${PLATFORMTMP} ${APPLICATIONTMP}
141 ${EXEC} ${PLATFORMTMP} ${APPLICATIONTMP}
142
143 echo "[$0] cleaning up temp files"
144 if [ -z "${PLATFORM}" ]; then
145         rm ${PLATFORMTMP} 
146 fi
147 #rm ${APPLICATIONTMP}