Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bummer, that's not the way to change the network model
[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       if [ ! -f ${PLATFORM} ]; then
33                 echo "[$0] ** error: the file '${PLATFORM}' does not exist. Aborting."
34                 exit 1
35       fi
36         shift 2
37     ;;
38    "-hostfile")
39         HOSTFILE="$2"
40       if [ ! -f ${HOSTFILE} ]; then
41                 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
42                 exit 1
43       fi
44         shift 2
45     ;;
46    
47    "-map")
48         MAPOPT="true"
49       shift 1
50    ;;
51
52    "-keep-temps")
53         KEEP="true"
54       shift 1
55    ;;
56
57    "-help" | "--help" | "-h") 
58       echo "usage:"
59       echo "$0 [-quiet] [-keep-temps] [-np <numprocs>] -platform <xmldesc> -hostfile <hostfile> [-map] program [program-options]"
60       echo "or (deprecated usage):"
61       echo "$0 [-quiet] [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]"
62       echo
63       exit
64    ;;
65    
66    "--cfg="*|"--log="*)
67      SIMOPTS="$SIMOPTS '$1'"
68      shift 1
69    ;;
70     *)
71       break
72     ;;
73   esac
74 done
75
76 EXEC="$1"
77 shift
78
79 ##-----------------------------------
80
81
82
83
84 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
85 if [ -z "${PLATFORM}" ]; then  
86         PLATFORMTMP="$(mktemp tmpXXXXXX)"
87
88         cat > ${PLATFORMTMP} <<PLATFORMHEAD
89 <?xml version='1.0'?>
90 <!DOCTYPE platform SYSTEM "simgrid.dtd">
91 <platform version="2">
92 PLATFORMHEAD
93
94 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
95   echo "  <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
96   echo "  <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
97   echo "  <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
98 done
99
100 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
101   for (( j=${NUMPROCS}; $j ; j=$j-1 )) do
102     if [ $i -eq $j ]; then
103       echo "  <route src=\"host$i\" dst=\"host$j\"><link:ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
104     else
105       echo "  <route src=\"host$i\" dst=\"host$j\"><link:ctn id=\"link$i\"/><link:ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
106     fi
107   done
108 done
109
110 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
111 </platform>
112 PLATFORMFOOT
113
114 else
115         PLATFORMTMP=${PLATFORM}
116 fi
117 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
118
119 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
120 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
121 #APPLICATIONTMP="app.xml"
122
123
124 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
125 <?xml version='1.0'?>
126 <!DOCTYPE platform SYSTEM "simgrid.dtd">
127 <platform version="2">
128 APPLICATIONHEAD
129
130 ##---- cache hostnames of hostfile---------------
131 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
132         hostnames=(`cat ${HOSTFILE} | tr \\\n " "`)
133       NUMHOSTS=`cat ${HOSTFILE} | wc -l`
134 fi
135
136 ##----------------------------------------------------------
137 ##  generate application.xml with hostnames from hostfile:
138 ##  the name of host_i (1<=i<=p, where -np p) is the line i
139 ##  in hostfile (where -hostfile hostfile), or "host$i" if
140 ##  hostfile has less than i lines.
141 ##----------------------------------------------------------
142
143 HAVE_SEQ="`which seq`"
144 HAVE_JOT="`which jot`"
145
146 if [ -n "${HAVE_SEQ}" ]; then
147         SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
148 else
149       cnt=0
150         while (( $cnt < ${NUMPROCS} )) ; do
151             SEQ="$SEQ $cnt"
152             cnt=$((cnt + 1));
153         done
154 fi
155
156 ##---- generate <process> tags------------------------------
157
158 for i in ${SEQ} 
159 do
160   if [ -n "${HOSTFILE}" ]; then
161         j=$(( $i % ${NUMHOSTS} ))
162   fi 
163   ##---- optional display of ranks to process mapping
164   if [ -n "${MAPOPT}" ]; then
165         echo "[rank $i] -> ${hostnames[$j]}"  
166   fi
167
168   if [ -z "${hostnames[$j]}" ]; then
169         host="host"$(($j+1))
170   else
171         host="${hostnames[$j]}"
172   fi
173   echo "  <process host=\"${host}\" function=\"smpi_simulated_main\">" >> ${APPLICATIONTMP}
174   echo "    <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
175   for ARG in $*; do
176     echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
177   done
178   echo "  </process>" >> ${APPLICATIONTMP}
179 done
180
181 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
182 </platform>
183 APPLICATIONFOOT
184 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
185
186 if [ -n "${KEEP}" ] ; then
187   echo ${EXEC} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
188 fi
189 ${EXEC} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
190
191 if [ -z "${KEEP}" ] ; then
192    if [ -z "${PLATFORM}" ]; then
193         rm ${PLATFORMTMP} 
194    fi
195    rm ${APPLICATIONTMP}
196 fi