Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] new smpi tracing options
[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 #usage to print the way this script should be called
22 function usage () {
23     echo "usage:"
24     echo "$0 [-quiet] [-keep-temps]"
25     echo "      [-np <numprocs>] -platform <xmldesc> -hostfile <hostfile> [-map] program [program-options]"
26     echo "      [-trace]                  # activate tracing"
27     echo "      [-trace-grouped]          # group MPI processes by location"
28     echo "      [-trace-resource]         # trace resource utilization"
29     echo "      [-trace-triva]            # generate configuration for Triva's GraphView"
30     echo "      [-trace-file <tracefile>] # name of the tracefile (simgrid_smpi.trace)"
31     echo "or (deprecated usage):"
32     echo "$0 [-quiet] [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]"
33     echo
34 }
35
36 #check if we have at least one parameter
37 if [ $# -eq 0 ]
38 then
39     usage
40     exit
41 fi
42
43 while true; do
44   case "$1" in
45    "-np" | "-n")
46       NUMPROCS="$2"
47       shift 2
48     ;;
49    "-bandwidth")
50       NETWORK_BANDWIDTH="$2"
51       shift 2
52     ;;
53    "-latency")
54       NETWORK_LATENCY="$2"
55       shift 2
56     ;;
57    "-platform")
58         PLATFORM="$2"
59       if [ ! -f ${PLATFORM} ]; then
60                 echo "[$0] ** error: the file '${PLATFORM}' does not exist. Aborting."
61                 exit 1
62       fi
63         shift 2
64     ;;
65    "-hostfile")
66         HOSTFILE="$2"
67       if [ ! -f ${HOSTFILE} ]; then
68                 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
69                 exit 1
70       fi
71         shift 2
72     ;;
73
74    "-map")
75         MAPOPT="true"
76       shift 1
77    ;;
78
79    "-trace")
80         TRACE_ACTIVE="true"
81           shift 1
82    ;;
83
84    "-trace-file")
85       TRACE_FILENAME="$2"
86       shift 2
87    ;;
88
89    "-trace-grouped")
90       TRACE_GROUPED="true"
91       shift 1
92    ;;
93
94    "-trace-resource")
95       TRACE_RESOURCE="true"
96       shift 1
97    ;;
98
99    "-trace-triva")
100         TRACE_TRIVA="true"
101           shift 1
102    ;;
103
104    "-keep-temps")
105         KEEP="true"
106       shift 1
107    ;;
108
109    "-help" | "--help" | "-h")
110       usage
111       exit
112    ;;
113
114    "--cfg="*|"--log="*)
115      for OPT in ${1#*=}
116      do
117        SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
118      done
119      shift 1
120    ;;
121     *)
122       break
123     ;;
124   esac
125 done
126
127 EXEC="$1"
128 shift
129
130 ##-----------------------------------
131
132 # test if we have something to execute, otherwise show usage and exit
133 if [ -z ${EXEC} ]
134 then
135     echo "Program is missing"
136     usage
137     exit 1
138 fi
139
140
141
142 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
143 if [ -z "${PLATFORM}" ]; then
144         PLATFORMTMP="$(mktemp tmpXXXXXX)"
145
146         cat > ${PLATFORMTMP} <<PLATFORMHEAD
147 <?xml version='1.0'?>
148 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
149 <platform version="3">
150 <AS id="AS0" routing="Full">
151 PLATFORMHEAD
152
153 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
154   echo "  <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
155   echo "  <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
156   echo "  <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
157 done
158
159 for (( i=${NUMPROCS}; $i ; i=$i-1 )) do
160   for (( j=${NUMPROCS}; $j ; j=$j-1 )) do
161     if [ $i -eq $j ]; then
162       echo "  <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
163     else
164       echo "  <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
165     fi
166   done
167 done
168
169 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
170 </AS>
171 </platform>
172 PLATFORMFOOT
173
174 else
175         PLATFORMTMP=${PLATFORM}
176 fi
177 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
178
179 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
180 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
181 #APPLICATIONTMP="app.xml"
182
183
184 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
185 <?xml version='1.0'?>
186 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
187 <platform version="3">
188 APPLICATIONHEAD
189
190 ##---- cache hostnames of hostfile---------------
191 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
192         hostnames=(`cat ${HOSTFILE} | tr \\\n " "`)
193       NUMHOSTS=`cat ${HOSTFILE} | wc -l`
194 fi
195
196 ##----------------------------------------------------------
197 ##  generate application.xml with hostnames from hostfile:
198 ##  the name of host_i (1<=i<=p, where -np p) is the line i
199 ##  in hostfile (where -hostfile hostfile), or "host$i" if
200 ##  hostfile has less than i lines.
201 ##----------------------------------------------------------
202
203 HAVE_SEQ="`which seq 2>/dev/null`"
204
205 if [ -n "${HAVE_SEQ}" ]; then
206         SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
207 else
208       cnt=0
209         while (( $cnt < ${NUMPROCS} )) ; do
210             SEQ="$SEQ $cnt"
211             cnt=$((cnt + 1));
212         done
213 fi
214
215 ##---- generate <process> tags------------------------------
216
217 for i in ${SEQ}
218 do
219   if [ -n "${HOSTFILE}" ]; then
220         j=$(( $i % ${NUMHOSTS} ))
221   fi
222   ##---- optional display of ranks to process mapping
223   if [ -n "${MAPOPT}" ]; then
224         echo "[rank $i] -> ${hostnames[$j]}"
225   fi
226
227   if [ -z "${hostnames[$j]}" ]; then
228         host="host"$(($j+1))
229   else
230         host="${hostnames[$j]}"
231   fi
232   echo "  <process host=\"${host}\" function=\"smpi_simulated_main\">" >> ${APPLICATIONTMP}
233   echo "    <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
234   for ARG in $*; do
235     echo "    <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
236   done
237   echo "  </process>" >> ${APPLICATIONTMP}
238 done
239
240 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
241 </platform>
242 APPLICATIONFOOT
243 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
244
245 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
246 if [ -n "${TRACE_ACTIVE}" ]; then
247   #define trace filename
248   if [ -z "${TRACE_FILENAME}" ]; then
249     TRACE_FILENAME="smpi_simgrid.trace"
250   fi
251   TRACEOPTIONS="--cfg=tracing:1 --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:1"
252
253   if [ -n "${TRACE_GROUPED}" ]; then
254     TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:1"
255   fi
256
257   if [ -n "${TRACE_RESOURCE}" ]; then
258     TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:1 --cfg=tracing/uncategorized:1"
259   fi
260
261   if [ -n "${TRACE_TRIVA}" ]; then
262     TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:smpi_cat.plist --cfg=tracing/uncategorized:smpi_uncat.plist"
263   fi
264 fi
265 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
266
267 export SMPI_GLOBAL_SIZE=${NUMPROCS}
268 if [ -n "${KEEP}" ] ; then
269   echo ${EXEC} ${SIMOPTS} ${TRACEOPTIONS} ${PLATFORMTMP} ${APPLICATIONTMP}
270 fi
271 ${EXEC} ${SIMOPTS} ${TRACEOPTIONS} ${PLATFORMTMP} ${APPLICATIONTMP}
272
273 if [ -z "${KEEP}" ] ; then
274    if [ -z "${PLATFORM}" ]; then
275         rm ${PLATFORMTMP}
276    fi
277    rm ${APPLICATIONTMP}
278 fi