3 # Copyright (c) 2007-2014. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
11 DEFAULT_LOOPBACK_BANDWIDTH="498000000"
12 DEFAULT_LOOPBACK_LATENCY="0.000004"
13 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))"
14 DEFAULT_NETWORK_LATENCY="0.000005"
18 LOOPBACK_BANDWIDTH="${DEFAULT_LOOPBACK_BANDWIDTH}"
19 LOOPBACK_LATENCY="${DEFAULT_LOOPBACK_LATENCY}"
20 NETWORK_BANDWIDTH="${DEFAULT_NETWORK_BANDWIDTH}"
21 NETWORK_LATENCY="${DEFAULT_NETWORK_LATENCY}"
22 POWER="${DEFAULT_POWER}"
24 SIMOPTS="--cfg=maxmin/precision:1e-9 --cfg=network/model:SMPI --cfg=network/TCP_gamma:4194304"
26 #usage to print the way this script should be called
29 Usage: $0 [OPTIONS] -platform <xmldesc> -hostfile <hostfile> program [program-options]
31 -keep-temps # don't remove the generated files after execution
32 -wrapper <command> # use command to run the program (e.g. "valgrind")
33 -map # display the machine on which each process rank is mapped
34 -np <numprocs> # use that amount of processes from the hostfile.
35 # By default, all processes of the hostfile are used.
36 -trace-ti # activate time independant tracing (for replay, default in smpi_simgrid.txt)
37 -trace # activate tracing (Paje, default in smpi_simgrid.trace)
38 -trace-comment <comment> # put a comment on the top of the trace file
39 -trace-comment-file <file> # put file contents on the top of the trace file as comment
40 -trace-grouped # group MPI processes by location
41 -trace-resource # trace resource utilization
42 -trace-viva # generate configuration for Viva's GraphView
43 -trace-file <tracefile> # name of the tracefile (simgrid_smpi.trace)
44 -ext <value> # additional parameter (reserved)
46 or (deprecated usage):
47 $0 [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]
52 #check if we have at least one parameter
70 NETWORK_BANDWIDTH="$2"
79 if [ ! -f "${PLATFORM}" ]; then
80 echo "[$0] ** error: the file '${PLATFORM}' does not exist. Aborting."
87 if [ ! -f "${HOSTFILE}" ]; then
88 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
96 if [ ! -f "${HOSTFILE}" ]; then
97 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
120 TRACE_TI_ACTIVE="true"
129 "-trace-comment-file")
130 TRACE_COMMENT_FILE="$2"
145 TRACE_RESOURCE="true"
164 "-help" | "--help" | "-h")
172 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
182 if [ -n "$WRAPPER" ]; then
189 # steel --cfg and --logs options
190 while [ $# -gt 0 ]; do
195 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
200 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
207 ##-----------------------------------
210 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
211 echo "No hostfile nor platform specified."
217 if [ -z "${HOSTFILE}" ] ; then
219 HOSTFILE="$(mktemp tmphostXXXXXX)"
220 perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
222 UNROLLEDHOSTFILETMP=0
224 #parse if our lines are terminated by :num_process
225 multiple_processes=`grep -c ":" $HOSTFILE`
226 if [ "${multiple_processes}" -gt 0 ] ; then
227 UNROLLEDHOSTFILETMP=1
228 UNROLLEDHOSTFILE="$(mktemp tmphostXXXXXX)"
229 perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE}
230 if [ ${HOSTFILETMP} = 1 ] ; then
234 HOSTFILE=$UNROLLEDHOSTFILE
238 # Don't use wc -l to compute it to avoid issues with trailing \n at EOF
239 hostfile_procs=`grep -c "[a-zA-Z0-9]" $HOSTFILE`
241 if [ -z "${NUMPROCS}" ] ; then
242 # Use the amount of processes in the hostfile as default value for the -np parameter
243 NUMPROCS=$hostfile_procs
247 if [ ${NUMPROCS} -gt ${hostfile_procs} ] ; then
248 echo "You requested to use ${NUMPROCS} processes, but there is only ${hostfile_procs} processes in your hostfile..." >&2
251 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
252 if [ -z "${PLATFORM}" ]; then
253 PLATFORMTMP="$(mktemp tmpXXXXXX)"
255 cat > ${PLATFORMTMP} <<PLATFORMHEAD
256 <?xml version='1.0'?>
257 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
258 <platform version="3">
259 <AS id="AS0" routing="Full">
263 while [ $i -gt 0 ]; do
264 echo " <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
265 echo " <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
266 echo " <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
271 while [ $i -gt 0 ]; do
273 while [ $j -gt 0 ]; do
274 if [ $i -eq $j ]; then
275 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
277 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
284 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
290 PLATFORMTMP=${PLATFORM}
292 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
294 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
295 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
296 #APPLICATIONTMP="app.xml"
299 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
300 <?xml version='1.0'?>
301 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
302 <platform version="3">
305 ##---- cache hostnames of hostfile---------------
306 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
307 hostnames=$(cat ${HOSTFILE} | tr '\n\r' ' ')
308 NUMHOSTS=$(cat ${HOSTFILE} | wc -l)
311 if [ "${EXTOPT}" = "smpi_replay" ]; then
312 APP_TRACES=$PROC_ARGS
313 if [ -n "${APP_TRACES}" ] && [ -f "${APP_TRACES}" ]; then
314 hosttraces=$(cat ${APP_TRACES} | tr '\n\r' ' ' )
315 NUMTRACES=$(cat ${APP_TRACES} | wc -l)
317 printf "File not found: %s\n", "${APP_TRACES:-\${APP_TRACES\}}" >&2
322 ##----------------------------------------------------------
323 ## generate application.xml with hostnames from hostfile:
324 ## the name of host_i (1<=i<=p, where -np p) is the line i
325 ## in hostfile (where -hostfile hostfile), or "host$i" if
326 ## hostfile has less than i lines.
327 ##----------------------------------------------------------
329 HAVE_SEQ="`which seq 2>/dev/null`"
331 if [ -n "${HAVE_SEQ}" ]; then
332 SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
335 while (( $cnt < ${NUMPROCS} )) ; do
341 ##---- generate <process> tags------------------------------
345 if [ -n "${HOSTFILE}" ]; then
346 j=$(( $i % ${NUMHOSTS} + 1 ))
348 ##---- optional display of ranks to process mapping
349 if [ -n "${MAPOPT}" ]; then
350 echo "[rank $i] -> $(echo $hostnames|cut -d' ' -f$j)"
353 if [ -z "$(echo $hostnames|cut -d' ' -f$j)" ]; then
356 host="$(echo $hostnames|cut -d' ' -f$j)"
358 echo " <process host=\"${host}\" function=\"$i\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
359 echo " <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
360 if [ "${EXTOPT}" = "smpi_replay" ]; then
361 if [ ${NUMTRACES} -gt 1 ]; then
362 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f$j)\"/>" >> ${APPLICATIONTMP}
364 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f1)\"/>" >> ${APPLICATIONTMP}
367 for ARG in $PROC_ARGS; do
368 echo " <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
371 echo " </process>" >> ${APPLICATIONTMP}
374 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
377 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
379 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
380 if [ -n "${TRACE_ACTIVE}" ]; then
381 #define trace filename
382 if [ -n "${TRACE_TI_ACTIVE}" ]; then
383 if [ -z "${TRACE_FILENAME}" ]; then
384 TRACE_FILENAME="smpi_simgrid.txt"
386 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes --cfg=tracing/smpi/format:TI --cfg=tracing/smpi/computing:yes"
388 if [ -z "${TRACE_FILENAME}" ]; then
389 TRACE_FILENAME="smpi_simgrid.trace"
391 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes"
394 if [ -n "${TRACE_COMMENT}" ]; then
395 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment:${TRACE_COMMENT}"
398 if [ -n "${TRACE_COMMENT_FILE}" ]; then
399 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment_file:${TRACE_COMMENT_FILE}"
402 if [ -n "${TRACE_GROUPED}" ]; then
403 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:yes"
406 if [ -n "${TRACE_RESOURCE}" ]; then
407 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:yes --cfg=tracing/uncategorized:yes"
410 if [ -n "${TRACE_VIVA}" ]; then
411 TRACEOPTIONS="${TRACEOPTIONS} --cfg=viva/categorized:smpi_cat.plist --cfg=viva/uncategorized:smpi_uncat.plist"
414 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
416 export SMPI_GLOBAL_SIZE=${NUMPROCS}
417 if [ -n "${KEEP}" ] ; then
418 echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
419 if [ ${HOSTFILETMP} = 1 ] ; then
420 echo "Generated hostfile ${HOSTFILE} keeped."
422 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
423 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} keeped."
426 ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
429 if [ ${status} = 139 ]; then echo "ERROR: A segmentation fault was triggered.
430 A common cause in SimGrid may be the use of a too small stack size for the simulated processes (default 128KiB).
431 Please see contexts/stack_size parameter , or http://simgrid.org/simgrid/latest/doc/options.html#options_virt_stacksize "; fi
433 if [ -z "${KEEP}" ] ; then
434 if [ -z "${PLATFORM}" ]; then
437 if [ ${HOSTFILETMP} = 1 ] ; then
440 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
441 rm ${UNROLLEDHOSTFILE}