5 DEFAULT_LOOPBACK_BANDWIDTH="498000000"
6 DEFAULT_LOOPBACK_LATENCY="0.000004"
7 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))"
8 DEFAULT_NETWORK_LATENCY="0.000005"
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 POWER="${DEFAULT_POWER}"
18 SIMOPTS="--cfg=maxmin/precision:1e-9 --cfg=network/model:SMPI --cfg=network/TCP_gamma:4194304"
20 #usage to print the way this script should be called
23 Usage: $0 [OPTIONS] -platform <xmldesc> -hostfile <hostfile> program [program-options]
25 -keep-temps # don't remove the generated files after execution
26 -wrapper <command> # use command to run the program (e.g. "valgrind")
27 -map # display the machine on which each process rank is mapped
28 -np <numprocs> # use that amount of processes from the hostfile.
29 # By default, all processes of the hostfile are used.
30 -trace-ti # activate time independant tracing (for replay, default in smpi_simgrid.txt)
31 -trace # activate tracing (Paje, default in smpi_simgrid.trace)
32 -trace-comment <comment> # put a comment on the top of the trace file
33 -trace-comment-file <file> # put file contents on the top of the trace file as comment
34 -trace-grouped # group MPI processes by location
35 -trace-resource # trace resource utilization
36 -trace-viva # generate configuration for Viva's GraphView
37 -trace-file <tracefile> # name of the tracefile (simgrid_smpi.trace)
38 -ext <value> # additional parameter (reserved)
40 or (deprecated usage):
41 $0 [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]
46 #check if we have at least one parameter
64 NETWORK_BANDWIDTH="$2"
73 if [ ! -f "${PLATFORM}" ]; then
74 echo "[$0] ** error: the file '${PLATFORM}' does not exist. Aborting."
81 if [ ! -f "${HOSTFILE}" ]; then
82 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
90 if [ ! -f "${HOSTFILE}" ]; then
91 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
114 TRACE_TI_ACTIVE="true"
123 "-trace-comment-file")
124 TRACE_COMMENT_FILE="$2"
139 TRACE_RESOURCE="true"
158 "-help" | "--help" | "-h")
166 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
176 if [ -n "$WRAPPER" ]; then
183 # steel --cfg and --logs options
184 while [ $# -gt 0 ]; do
189 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
194 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
201 ##-----------------------------------
204 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
205 echo "No hostfile nor platform specified."
211 if [ -z "${HOSTFILE}" ] ; then
213 HOSTFILE="$(mktemp tmphostXXXXXX)"
214 perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
216 UNROLLEDHOSTFILETMP=0
218 #parse if our lines are terminated by :num_process
219 multiple_processes=`grep -c ":" $HOSTFILE`
220 if [ "${multiple_processes}" -gt 0 ] ; then
221 UNROLLEDHOSTFILETMP=1
222 UNROLLEDHOSTFILE="$(mktemp tmphostXXXXXX)"
223 perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE}
224 if [ ${HOSTFILETMP} = 1 ] ; then
228 HOSTFILE=$UNROLLEDHOSTFILE
232 # Don't use wc -l to compute it to avoid issues with trailing \n at EOF
233 hostfile_procs=`grep -c "[a-zA-Z0-9]" $HOSTFILE`
235 if [ -z "${NUMPROCS}" ] ; then
236 # Use the amount of processes in the hostfile as default value for the -np parameter
237 NUMPROCS=$hostfile_procs
241 if [ ${NUMPROCS} -gt ${hostfile_procs} ] ; then
242 echo "You requested to use ${NUMPROCS} processes, but there is only ${hostfile_procs} processes in your hostfile..." >&2
245 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
246 if [ -z "${PLATFORM}" ]; then
247 PLATFORMTMP="$(mktemp tmpXXXXXX)"
249 cat > ${PLATFORMTMP} <<PLATFORMHEAD
250 <?xml version='1.0'?>
251 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
252 <platform version="3">
253 <AS id="AS0" routing="Full">
257 while [ $i -gt 0 ]; do
258 echo " <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
259 echo " <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
260 echo " <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
265 while [ $i -gt 0 ]; do
267 while [ $j -gt 0 ]; do
268 if [ $i -eq $j ]; then
269 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
271 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
278 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
284 PLATFORMTMP=${PLATFORM}
286 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
288 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
289 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
290 #APPLICATIONTMP="app.xml"
293 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
294 <?xml version='1.0'?>
295 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
296 <platform version="3">
299 ##---- cache hostnames of hostfile---------------
300 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
301 hostnames=$(cat ${HOSTFILE} | tr '\n\r' ' ')
302 NUMHOSTS=$(cat ${HOSTFILE} | wc -l)
305 if [ "${EXTOPT}" = "smpi_replay" ]; then
306 APP_TRACES=$PROC_ARGS
307 if [ -n "${APP_TRACES}" ] && [ -f "${APP_TRACES}" ]; then
308 hosttraces=$(cat ${APP_TRACES} | tr '\n\r' ' ' )
309 NUMTRACES=$(cat ${APP_TRACES} | wc -l)
311 printf "File not found: %s\n", "${APP_TRACES:-\${APP_TRACES\}}" >&2
316 ##----------------------------------------------------------
317 ## generate application.xml with hostnames from hostfile:
318 ## the name of host_i (1<=i<=p, where -np p) is the line i
319 ## in hostfile (where -hostfile hostfile), or "host$i" if
320 ## hostfile has less than i lines.
321 ##----------------------------------------------------------
323 HAVE_SEQ="`which seq 2>/dev/null`"
325 if [ -n "${HAVE_SEQ}" ]; then
326 SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
329 while (( $cnt < ${NUMPROCS} )) ; do
335 ##---- generate <process> tags------------------------------
339 if [ -n "${HOSTFILE}" ]; then
340 j=$(( $i % ${NUMHOSTS} + 1 ))
342 ##---- optional display of ranks to process mapping
343 if [ -n "${MAPOPT}" ]; then
344 echo "[rank $i] -> $(echo $hostnames|cut -d' ' -f$j)"
347 if [ -z "$(echo $hostnames|cut -d' ' -f$j)" ]; then
350 host="$(echo $hostnames|cut -d' ' -f$j)"
352 echo " <process host=\"${host}\" function=\"$i\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
353 echo " <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
354 if [ "${EXTOPT}" = "smpi_replay" ]; then
355 if [ ${NUMTRACES} -gt 1 ]; then
356 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f$j)\"/>" >> ${APPLICATIONTMP}
358 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f1)\"/>" >> ${APPLICATIONTMP}
361 for ARG in $PROC_ARGS; do
362 echo " <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
365 echo " </process>" >> ${APPLICATIONTMP}
368 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
371 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
373 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
374 if [ -n "${TRACE_ACTIVE}" ]; then
375 #define trace filename
376 if [ -n "${TRACE_TI_ACTIVE}" ]; then
377 if [ -z "${TRACE_FILENAME}" ]; then
378 TRACE_FILENAME="smpi_simgrid.txt"
380 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes --cfg=tracing/smpi/format:TI --cfg=tracing/smpi/computing:yes"
382 if [ -z "${TRACE_FILENAME}" ]; then
383 TRACE_FILENAME="smpi_simgrid.trace"
385 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes"
388 if [ -n "${TRACE_COMMENT}" ]; then
389 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment:${TRACE_COMMENT}"
392 if [ -n "${TRACE_COMMENT_FILE}" ]; then
393 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment_file:${TRACE_COMMENT_FILE}"
396 if [ -n "${TRACE_GROUPED}" ]; then
397 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:yes"
400 if [ -n "${TRACE_RESOURCE}" ]; then
401 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:yes --cfg=tracing/uncategorized:yes"
404 if [ -n "${TRACE_VIVA}" ]; then
405 TRACEOPTIONS="${TRACEOPTIONS} --cfg=viva/categorized:smpi_cat.plist --cfg=viva/uncategorized:smpi_uncat.plist"
408 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
410 export SMPI_GLOBAL_SIZE=${NUMPROCS}
411 if [ -n "${KEEP}" ] ; then
412 echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
413 if [ ${HOSTFILETMP} = 1 ] ; then
414 echo "Generated hostfile ${HOSTFILE} keeped."
416 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
417 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} keeped."
420 ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
423 if [ ${status} = 139 ]; then echo "ERROR: A segmentation fault was triggered.
424 A common cause in SimGrid may be the use of a too small stack size for the simulated processes (default 128KiB).
425 Please see contexts/stack_size parameter , or http://simgrid.org/simgrid/latest/doc/options.html#options_virt_stacksize "; fi
427 if [ -z "${KEEP}" ] ; then
428 if [ -z "${PLATFORM}" ]; then
431 if [ ${HOSTFILETMP} = 1 ] ; then
434 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
435 rm ${UNROLLEDHOSTFILE}