3 # Copyright (c) 2007-2016, The SimGrid Team. All rights reserved.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the license (GNU LGPL) which comes with this package.
10 SIMGRID_VERSION="@SIMGRID_VERSION_STRING@"
11 SIMGRID_GITHASH="@SIMGRID_GITHASH@"
13 DEFAULT_LOOPBACK_BANDWIDTH="498000000Bps"
14 DEFAULT_LOOPBACK_LATENCY="0.000004s"
15 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))Bps"
16 DEFAULT_NETWORK_LATENCY="0.000005s"
18 DEFAULT_SPEED="100flops"
20 LOOPBACK_BANDWIDTH="${DEFAULT_LOOPBACK_BANDWIDTH}"
21 LOOPBACK_LATENCY="${DEFAULT_LOOPBACK_LATENCY}"
22 NETWORK_BANDWIDTH="${DEFAULT_NETWORK_BANDWIDTH}"
23 NETWORK_LATENCY="${DEFAULT_NETWORK_LATENCY}"
24 SPEED="${DEFAULT_SPEED}"
26 PRIVATIZE="--cfg=smpi/privatize-global-variables:@HAVE_PRIVATIZATION@"
28 SIMOPTS="--cfg=surf/precision:1e-9 --cfg=network/model:SMPI --cfg=network/TCP-gamma:4194304"
30 #usage to print the way this script should be called
33 Usage: $0 [OPTIONS] -platform <xmldesc> -hostfile <hostfile> program [program-options]
35 -keep-temps # don't remove the generated files after execution
36 -wrapper <command> # use command to run the program (e.g. "valgrind")
37 -map # display the machine on which each process rank is mapped
38 -np <numprocs> # use that amount of processes from the hostfile.
39 # By default, all processes of the hostfile are used.
40 -no-privatize # Disable the globals privatization, that is activated by default
41 -trace-ti # activate time independant tracing (for replay, default in smpi_simgrid.txt)
42 -trace # activate tracing (Paje, default in smpi_simgrid.trace)
43 -trace-comment <comment> # put a comment on the top of the trace file
44 -trace-comment-file <file> # put file contents on the top of the trace file as comment
45 -trace-grouped # group MPI processes by location
46 -trace-resource # trace resource utilization
47 -trace-viva # generate configuration for Viva's GraphView
48 -trace-file <tracefile> # name of the tracefile (simgrid_smpi.trace)
49 -ext <value> # additional parameter (reserved)
51 -version # Displays the SimGrid version (human readable)
52 -git-version # Displays the git hash of SimGrid
54 or (deprecated usage):
55 $0 [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]
60 #check if we have at least one parameter
76 trapped_signals="HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS"
80 if [ -z "${KEEP}" ] ; then
81 if [ -z "${PLATFORM}" -a -n "$PLATFORMTMP" ]; then
85 if [ ${HOSTFILETMP} = 1 -a -n "$HOSTFILE" ] ; then
89 if [ ${UNROLLEDHOSTFILETMP} = 1 -a -n "$UNROLLEDHOSTFILE" ] ; then
90 rm -f ${UNROLLEDHOSTFILE}
93 if [ -n ${APPLICATIONTMP} ]; then
94 rm -f ${APPLICATIONTMP}
104 # Cleanup and kill the child process:
106 if ! [ -z "$pid" ]; then
111 # Raise the same signal again (remove the traps first):
112 trap - $trapped_signals
115 # This should never happen:
120 for s in $trapped_signals; do
121 trap "smpirun_trap $s" $s
131 NETWORK_BANDWIDTH="$2"
140 if [ ! -f "${PLATFORM}" ]; then
141 echo "[`basename $0`] ** error: the file '${PLATFORM}' does not exist. Aborting."
148 if [ ! -f "${HOSTFILE}" ]; then
149 echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
156 if [ ! -f "${HOSTFILE}" ]; then
157 echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
180 TRACE_TI_ACTIVE="true"
187 "-trace-comment-file")
188 TRACE_COMMENT_FILE="$2"
200 TRACE_RESOURCE="true"
215 "-help" | "--help" | "-h")
219 "-version" | "--version" | "-v")
220 printf '%b\n' "$SIMGRID_VERSION"
223 "-git-version" | "--git-version")
224 printf '%b\n' "$SIMGRID_GITHASH"
230 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
235 # Nothing to do, compatibility.
244 # check if we still have at least one parameter beyond options
247 echo "Error: no program to execute!"
252 if [ -n "$WRAPPER" ]; then
259 # steel --cfg and --logs options
260 while [ $# -gt 0 ]; do
265 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
270 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
276 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
277 echo "No hostfile nor platform specified."
282 if [ -z "${HOSTFILE}" ] ; then
284 HOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
285 perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
286 perl -ne 'if (/.*<cluster.*?prefix="(.*?)".*?radical="(.*?)".*?suffix="(.*?)".*/) {
287 my ($pre,$rad,$post)=($1,$2,$3);
288 for my $elm (split(",",$rad)) {
289 if ($elm=~/^([^-]*?)-([^-]*)$/) {
290 for (my $i=$1; $i<=$2;$i++) {
291 print "$pre$i$post\n";
294 print "$pre$elm$post\n";
297 } elsif (/<cluster/) {
298 die ("Unparsable cluster tag. smpirun uses a primitive regular expression to parse cluster tags. Either provide a hostfile yourself or give the attributes prefix, radical and suffix IN THAT ORDER and ON THE SAME LINE as the opening tag (<cluster)");
299 }' ${PLATFORM} >> ${HOSTFILE}
301 UNROLLEDHOSTFILETMP=0
303 #parse if our lines are terminated by :num_process
304 multiple_processes=`grep -c ":" $HOSTFILE`
305 if [ "${multiple_processes}" -gt 0 ] ; then
306 UNROLLEDHOSTFILETMP=1
307 UNROLLEDHOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
308 perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE}
309 if [ ${HOSTFILETMP} = 1 ] ; then
313 HOSTFILE=$UNROLLEDHOSTFILE
316 # Don't use wc -l to compute it to avoid issues with trailing \n at EOF
317 hostfile_procs=`grep -c "[a-zA-Z0-9]" $HOSTFILE`
318 if [ ${hostfile_procs} = 0 ] ; then
319 echo "[`basename $0`] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2
323 if [ -z "${NUMPROCS}" ] ; then
324 # Use the amount of processes in the hostfile as default value for the -np parameter
325 NUMPROCS=$hostfile_procs
328 if [ ${NUMPROCS} -gt ${hostfile_procs} ] ; then
329 echo "You requested to use ${NUMPROCS} processes, but there is only ${hostfile_procs} processes in your hostfile..." >&2
332 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
333 if [ -z "${PLATFORM}" ]; then
334 PLATFORMTMP="$(mktemp smpitmp-platfXXXXXX)"
336 cat > ${PLATFORMTMP} <<PLATFORMHEAD
337 <?xml version='1.0'?>
338 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
339 <platform version="4">
340 <AS id="AS0" routing="Full">
344 while [ $i -gt 0 ]; do
345 echo " <host id=\"host$i\" speed=\"${SPEED}\"/>" >> ${PLATFORMTMP}
346 echo " <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
347 echo " <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
352 while [ $i -gt 0 ]; do
354 while [ $j -gt 0 ]; do
355 if [ $i -eq $j ]; then
356 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
358 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
365 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
371 PLATFORMTMP=${PLATFORM}
373 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
374 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
375 APPLICATIONTMP="$(mktemp smpitmp-appXXXXXX)"
376 #APPLICATIONTMP="app.xml"
378 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
379 <?xml version='1.0'?>
380 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
381 <platform version="4">
384 ##---- cache hostnames of hostfile---------------
385 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
386 hostnames=$(cat ${HOSTFILE} | tr '\n\r' ' ')
389 if [ "${EXTOPT}" = "smpi_replay" ]; then
390 APP_TRACES=$PROC_ARGS
391 if [ -n "${APP_TRACES}" ] && [ -f "${APP_TRACES}" ]; then
392 hosttraces=$(cat ${APP_TRACES} | tr '\n\r' ' ' )
393 NUMTRACES=$(cat ${APP_TRACES} | wc -l)
396 printf "File not found: %s\n" "${APP_TRACES:-\${APP_TRACES\}}" >&2
401 ##----------------------------------------------------------
402 ## generate application.xml with hostnames from hostfile:
403 ## the name of host_i (1<=i<=p, where -np p) is the line i in hostfile (where -hostfile hostfile), or "host$i" if
404 ## hostfile has less than i lines.
405 ##----------------------------------------------------------
407 HAVE_SEQ="`which seq 2>/dev/null`"
409 if [ -n "${HAVE_SEQ}" ]; then
410 SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
413 while [ $cnt -lt ${NUMPROCS} ] ; do
421 ##---- generate <process> tags------------------------------
422 #prepare arguments at once
423 for ARG in $PROC_ARGS; do
424 XML_ARGS="${XML_ARGS}""<argument value=\"${ARG}\"/>
430 j=$(( $i % ${hostfile_procs} + 1 ))
431 host=$(eval "echo \${$j}")
433 ##---- optional display of ranks to process mapping
434 if [ ${MAPOPT} = 1 ]; then
435 echo "[rank $i] -> $host"
438 echo " <process host=\"${host}\" function=\"$i\"> <!-- function name used only for logging -->
439 <argument value=\"1\"/> <!-- instance -->
440 <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
441 if [ ${REPLAY} = 1 ]; then
442 if [ ${NUMTRACES} -gt 1 ]; then
443 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f$j)\"/>" >> ${APPLICATIONTMP}
445 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f1)\"/>" >> ${APPLICATIONTMP}
448 echo ${XML_ARGS} >> ${APPLICATIONTMP}
450 echo " </process>" >> ${APPLICATIONTMP}
453 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
456 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
457 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
458 if [ -n "${TRACE_ACTIVE}" ]; then
459 #define trace filename
460 if [ -n "${TRACE_TI_ACTIVE}" ]; then
461 if [ -z "${TRACE_FILENAME}" ]; then
462 TRACE_FILENAME="smpi_simgrid.txt"
464 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes --cfg=tracing/smpi/format:TI --cfg=tracing/smpi/computing:yes"
466 if [ -z "${TRACE_FILENAME}" ]; then
467 TRACE_FILENAME="smpi_simgrid.trace"
469 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes"
472 if [ -n "${TRACE_COMMENT}" ]; then
473 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment:${TRACE_COMMENT}"
476 if [ -n "${TRACE_COMMENT_FILE}" ]; then
477 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment-file:${TRACE_COMMENT_FILE}"
480 if [ -n "${TRACE_GROUPED}" ]; then
481 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:yes"
484 if [ -n "${TRACE_RESOURCE}" ]; then
485 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:yes --cfg=tracing/uncategorized:yes"
488 if [ -n "${TRACE_VIVA}" ]; then
489 TRACEOPTIONS="${TRACEOPTIONS} --cfg=viva/categorized:smpi_cat.plist --cfg=viva/uncategorized:smpi_uncat.plist"
492 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
494 export SMPI_GLOBAL_SIZE=${NUMPROCS}
495 if [ -n "${KEEP}" ] ; then
496 echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PRIVATIZE} ${PLATFORMTMP} ${APPLICATIONTMP}
497 if [ ${HOSTFILETMP} = 1 ] ; then
498 echo "Generated hostfile ${HOSTFILE} kept."
500 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
501 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
505 # Execute the process
507 # The shell still need to be alive for the duration in order to do some cleanup after the process.
509 # We are going through great lengths in order to both keep stdin and be able to handle signals:
511 # * The job is launched in the background in order to be able to handle signals.
513 # * The FD 3 is used to temporarily store FD 1. This is because the shell connects FD 1 to /dev/null when the command
514 # is launched in the background: this can be overriden in bash but not in standard bourne shell.
516 ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PRIVATIZE} ${PLATFORMTMP} ${APPLICATIONTMP} <&3 3>&- &
523 # Keep temporary files on failures to help debugging
525 if [ ${status} -ne 0 ] ; then
526 if [ -z ${KEEP} ]; then
527 echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PRIVATIZE} ${PLATFORMTMP} ${APPLICATIONTMP}
528 if [ ${HOSTFILETMP} = 1 ] ; then
529 echo "Generated hostfile ${HOSTFILE} kept."
531 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
532 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
535 echo "Execution failed with code ${status}."