Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
09ea663c3f98ce52f1f6c9f8fe0a5d67780632d7
[simgrid.git] / src / smpi / smpirun.in
1 #!/bin/bash
2
3 @CMAKE_SMPI_COMMAND@
4
5 DEFAULT_LOOPBACK_BANDWIDTH="498000000"
6 DEFAULT_LOOPBACK_LATENCY="0.000004"
7 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))"
8 DEFAULT_NETWORK_LATENCY="0.000005"
9 DEFAULT_NUMPROCS="4"
10 DEFAULT_POWER="100"
11
12 LOOPBACK_BANDWIDTH="${DEFAULT_LOOPBACK_BANDWIDTH}"
13 LOOPBACK_LATENCY="${DEFAULT_LOOPBACK_LATENCY}"
14 NETWORK_BANDWIDTH="${DEFAULT_NETWORK_BANDWIDTH}"
15 NETWORK_LATENCY="${DEFAULT_NETWORK_LATENCY}"
16 NUMPROCS="${DEFAULT_NUMPROCS}"
17 POWER="${DEFAULT_POWER}"
18
19 SIMOPTS="--cfg=maxmin/precision:1e-9 --cfg=network/model:SMPI --cfg=TCP_gamma:4194304"
20
21 while true; do
22   case "$1" in
23    "-np" | "-n")
24       NUMPROCS="$2"
25       shift 2
26     ;;
27    "-bandwidth")
28       NETWORK_BANDWIDTH="$2"
29       shift 2
30     ;;
31    "-latency")
32       NETWORK_LATENCY="$2"
33       shift 2
34     ;;
35    "-platform")
36         PLATFORM="$2"
37       if [ ! -f ${PLATFORM} ]; then
38                 echo "[$0] ** error: the file '${PLATFORM}' does not exist. Aborting."
39                 exit 1
40       fi
41         shift 2
42     ;;
43    "-hostfile")
44         HOSTFILE="$2"
45       if [ ! -f ${HOSTFILE} ]; then
46                 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
47                 exit 1
48       fi
49         shift 2
50     ;;
51
52    "-map")
53         MAPOPT="true"
54       shift 1
55    ;;
56
57    "-trace")
58         TRACEOPT="$2"
59           shift 2
60    ;;
61
62    "-triva")
63         TRIVA="true"
64           shift 1
65    ;;
66
67    "-keep-temps")
68         KEEP="true"
69       shift 1
70    ;;
71
72    "-help" | "--help" | "-h")
73       echo "usage:"
74       echo "$0 [-quiet] [-keep-temps] [-trace <tracefile>] [-np <numprocs>] -platform <xmldesc> -hostfile <hostfile> [-map] program [program-options]"
75       echo "or (deprecated usage):"
76       echo "$0 [-quiet] [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]"
77       echo
78       exit
79    ;;
80
81    "--cfg="*|"--log="*)
82      for OPT in ${1#*=}
83      do
84        SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
85      done
86      shift 1
87    ;;
88     *)
89       break
90     ;;
91   esac
92 done
93
94 EXEC="$1"
95 shift
96
97 ##-----------------------------------
98
99
100
101
102 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
103 if [ -z "${PLATFORM}" ]; then
104         PLATFORMTMP="$(mktemp tmpXXXXXX)"
105
106         cat > ${PLATFORMTMP} <<PLATFORMHEAD
107 <?xml version='1.0'?>
108 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
109 <platform version="3">
110 <AS id="AS0" routing="Full">
111 PLATFORMHEAD
112
113 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
114   echo "  <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
115   echo "  <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
116   echo "  <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
117 done
118
119 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
120   for (( j=${NUMPROCS}; $j ; j=$j-1 )) do
121     if [ $i -eq $j ]; then
122       echo "  <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
123     else
124       echo "  <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
125     fi
126   done
127 done
128
129 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
130 </AS>
131 </platform>
132 PLATFORMFOOT
133
134 else
135         PLATFORMTMP=${PLATFORM}
136 fi
137 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
138
139 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
140 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
141 #APPLICATIONTMP="app.xml"
142
143
144 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
145 <?xml version='1.0'?>
146 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
147 <platform version="3">
148 APPLICATIONHEAD
149
150 ##---- cache hostnames of hostfile---------------
151 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
152         hostnames=(`cat ${HOSTFILE} | tr \\\n " "`)
153       NUMHOSTS=`cat ${HOSTFILE} | wc -l`
154 fi
155
156 ##----------------------------------------------------------
157 ##  generate application.xml with hostnames from hostfile:
158 ##  the name of host_i (1<=i<=p, where -np p) is the line i
159 ##  in hostfile (where -hostfile hostfile), or "host$i" if
160 ##  hostfile has less than i lines.
161 ##----------------------------------------------------------
162
163 HAVE_SEQ="`which seq 2>/dev/null`"
164
165 if [ -n "${HAVE_SEQ}" ]; then
166         SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
167 else
168       cnt=0
169         while (( $cnt < ${NUMPROCS} )) ; do
170             SEQ="$SEQ $cnt"
171             cnt=$((cnt + 1));
172         done
173 fi
174
175 ##---- generate <process> tags------------------------------
176
177 for i in ${SEQ}
178 do
179   if [ -n "${HOSTFILE}" ]; then
180         j=$(( $i % ${NUMHOSTS} ))
181   fi
182   ##---- optional display of ranks to process mapping
183   if [ -n "${MAPOPT}" ]; then
184         echo "[rank $i] -> ${hostnames[$j]}"
185   fi
186
187   if [ -z "${hostnames[$j]}" ]; then
188         host="host"$(($j+1))
189   else
190         host="${hostnames[$j]}"
191   fi
192   echo "  <process host=\"${host}\" function=\"smpi_simulated_main\">" >> ${APPLICATIONTMP}
193   echo "    <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
194   for ARG in $*; do
195     echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
196   done
197   echo "  </process>" >> ${APPLICATIONTMP}
198 done
199
200 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
201 </platform>
202 APPLICATIONFOOT
203 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
204
205 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
206   if [ -n "${TRACEOPT}" ]; then
207     TRACEOPTIONS="--cfg=tracing:1 --cfg=tracing/filename:${TRACEOPT} --cfg=tracing/smpi:1 --cfg=tracing/categorized:1 --cfg=tracing/uncategorized:1"
208   else
209     TRACEOPTIONS=""
210   fi
211
212   if [ -n "${TRIVA}" ]; then
213     TRIVAOPTIONS="--cfg=triva/categorized:smpi_cat.plist --cfg=triva/uncategorized:smpi_uncat.plist"
214   else
215     TRIVAOPTIONS=""
216   fi
217 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
218
219 export SMPI_GLOBAL_SIZE=${NUMPROCS}
220 if [ -n "${KEEP}" ] ; then
221   echo ${EXEC} ${SIMOPTS} ${TRACEOPTIONS} ${TRIVAOPTIONS} ${PLATFORMTMP} ${APPLICATIONTMP}
222 fi
223 ${EXEC} ${SIMOPTS} ${TRACEOPTIONS} ${TRIVAOPTIONS} ${PLATFORMTMP} ${APPLICATIONTMP}
224
225 if [ -z "${KEEP}" ] ; then
226    if [ -z "${PLATFORM}" ]; then
227         rm ${PLATFORMTMP}
228    fi
229    rm ${APPLICATIONTMP}
230 fi