3 # Copyright (c) 2007-2022. 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="@GIT_VERSION@"
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"
17 DEFAULT_SPEED="100flops"
19 LOOPBACK_BANDWIDTH="${DEFAULT_LOOPBACK_BANDWIDTH}"
20 LOOPBACK_LATENCY="${DEFAULT_LOOPBACK_LATENCY}"
21 NETWORK_BANDWIDTH="${DEFAULT_NETWORK_BANDWIDTH}"
22 NETWORK_LATENCY="${DEFAULT_NETWORK_LATENCY}"
23 SPEED="${DEFAULT_SPEED}"
25 PRIVATIZE="--cfg=smpi/privatization:${SMPI_PRIVATIZATION:-@HAVE_PRIVATIZATION@}"
30 SIMOPTS="--cfg=surf/precision:1e-9 --cfg=network/model:SMPI"
32 SMPITMPDIR="$(dirname $(mktemp -u))"
34 #usage to print the way this script should be called
37 Usage: $0 [OPTIONS] -platform <xmldesc|so> -hostfile <hostfile> program [program-options]
38 $0 [OPTIONS] -platform <xmldesc|so> -hostfile <hostfile> -replay <tracefile> [program] [program-options]
40 -analyze # show information about allocations and timings at the end of execution
41 -keep-temps # don't remove the generated files after execution
42 -wrapper <command> # use command to run the program (e.g. "valgrind" or "gdb --args")
43 -gdb # run within GDB (-wrapper "gdb --args" -keep-temps)
44 -lldb # run within LLDB (-wrapper "lldb --" -keep-temps)
45 -vgdb # run within Valgrind+GDB (-wrapper "valgrind --vgdb=yes --vgdb-error=0" -keep-temps)
46 -map # display the machine on which each process rank is mapped
47 -np <numprocs> # use that amount of processes from the hostfile.
48 # By default, all processes of the hostfile are used.
49 -no-privatize # Disable the globals privatization, that is activated by default
50 -tmpdir # Directory used to store temporary files. Defaults to system's.
51 -trace-ti # activate time independent tracing (for replay, default in smpi_simgrid.txt)
52 -trace # activate tracing (Paje, default in smpi_simgrid.trace)
53 -trace-comment <comment> # put a comment on the top of the trace file
54 -trace-comment-file <file> # put file contents on the top of the trace file as comment
55 -trace-grouped # group MPI processes by location
56 -trace-resource # trace resource utilization
57 -trace-file <tracefile> # name of the tracefile (simgrid_smpi.trace)
58 -replay <tracefile> # replays a trace instead of actually executing an application
60 -version # Displays the SimGrid version (human readable)
61 -git-version # Displays the git hash of SimGrid
63 or (deprecated usage):
64 $0 [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]
69 #check if we have at least one parameter
82 trapped_signals="HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS"
85 printf '[%s] ** error: %s. Aborting.\n' "$(basename "$0")" "$*" >&2
91 if [ -z "${KEEP}" ] ; then
92 if [ -z "${PLATFORM}" ] && [ -n "$PLATFORMTMP" ]; then
93 rm -f "${PLATFORMTMP}"
96 if [ "${UNROLLEDHOSTFILETMP}" = 1 ] && [ -n "$UNROLLEDHOSTFILE" ] ; then
97 rm -f "${UNROLLEDHOSTFILE}"
107 # Cleanup and kill the child process:
109 if [ -n "$pid" ]; then
114 # Raise the same signal again (remove the traps first):
115 trap - $trapped_signals
118 # This should never happen:
123 for s in $trapped_signals; do
124 trap "smpirun_trap $s" "$s"
134 NETWORK_BANDWIDTH="$2"
143 if [ ! -f "${PLATFORM}" ]; then
144 die "the file '${PLATFORM}' does not exist"
148 "-hostfile" | "-machinefile")
150 if [ ! -f "${HOSTFILE}" ]; then
151 die "the file '${HOSTFILE}' does not exist"
157 if [ ! -f "${APP_TRACES}" ]; then
158 die "the file '${APP_TRACES}' does not exist"
160 DEPLOYOPTS="${DEPLOYOPTS} --cfg=smpi/replay:${APP_TRACES}"
164 PRIVATIZE="--cfg=smpi/privatization:no"
168 DEPLOYOPTS="${DEPLOYOPTS} --cfg=smpi/map:1"
181 TRACE_TI_ACTIVE="true"
188 "-trace-comment-file")
189 TRACE_COMMENT_FILE="$2"
201 TRACE_RESOURCE="true"
206 SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
220 SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
224 WRAPPER="valgrind --vgdb=yes --vgdb-error=0"
226 SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
232 SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
236 SIMOPTS="$SIMOPTS --cfg=smpi/display-timing:yes --cfg=smpi/display-allocs:yes --cfg=smpi/list-leaks:50 --cfg=smpi/pedantic:true"
239 "-help" | "--help" | "-h")
243 "-version" | "--version" | "-v")
244 printf '%b\n' "$SIMGRID_VERSION"
247 "-git-version" | "--git-version")
248 printf '%b\n' "$SIMGRID_GITHASH"
254 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
259 # Nothing to do, compatibility.
269 SIMOPTS="$SIMOPTS --cfg=smpi/tmpdir:$SMPITMPDIR"
270 export LD_LIBRARY_PATH="$SMPITMPDIR:$LD_LIBRARY_PATH"
272 if [ -n "${APP_TRACES}" ] ; then
273 if [ $# -eq 0 ] ; then
274 EXEC="@SMPIREPLAYMAIN@"
280 # check if we still have at least one parameter beyond options
283 echo "Error: no program to execute!"
292 # steal --cfg and --logs options
293 while [ $# -gt 0 ]; do
298 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
303 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
309 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
310 echo "No hostfile nor platform specified."
315 UNROLLEDHOSTFILETMP=0
317 # parse if our lines are terminated by :num_process
318 if [ -n "${HOSTFILE}" ] && grep -q ':' "${HOSTFILE}" ; then
319 UNROLLEDHOSTFILETMP=1
320 UNROLLEDHOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
321 @PYTHON_EXECUTABLE@ -c '
325 for line in sys.stdin:
326 m = re.match("(.*):(.*)", line)
328 for i in range(0, int(m.group(2))):
332 ' < "${HOSTFILE}" > "${UNROLLEDHOSTFILE}"
333 HOSTFILE=$UNROLLEDHOSTFILE
336 DEPLOYOPTS="${DEPLOYOPTS} --cfg=smpi/np:${NUMPROCS}"
337 DEPLOYOPTS="${DEPLOYOPTS} --cfg=smpi/hostfile:${HOSTFILE}"
339 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
340 if [ -z "${PLATFORM}" ]; then
341 PLATFORMTMP="$(mktemp smpitmp-platfXXXXXX)"
343 cat > "${PLATFORMTMP}" <<PLATFORMHEAD
344 <?xml version='1.0'?>
345 <!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
346 <platform version="4.1">
347 <zone id="AS0" routing="Full">
351 while [ "$i" -gt 0 ]; do
353 echo " <host id=\"host$i\" speed=\"${SPEED}\"/>"
354 echo " <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>"
355 echo " <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>"
356 } >> "${PLATFORMTMP}"
361 while [ "$i" -gt 0 ]; do
363 while [ "$j" -gt 0 ]; do
364 if [ "$i" -eq "$j" ]; then
365 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> "${PLATFORMTMP}"
367 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> "${PLATFORMTMP}"
374 cat >> "${PLATFORMTMP}" <<PLATFORMFOOT
380 PLATFORMTMP=${PLATFORM}
382 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
383 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
384 if [ -n "${TRACE_ACTIVE}" ]; then
385 #define trace filename
386 if [ -n "${TRACE_TI_ACTIVE}" ]; then
387 if [ -z "${TRACE_FILENAME}" ]; then
388 TRACE_FILENAME="smpi_simgrid.txt"
390 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes --cfg=tracing/smpi/format:TI --cfg=tracing/smpi/computing:yes"
392 if [ -z "${TRACE_FILENAME}" ]; then
393 TRACE_FILENAME="smpi_simgrid.trace"
395 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes"
398 if [ -n "${TRACE_COMMENT}" ]; then
399 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment:${TRACE_COMMENT}"
402 if [ -n "${TRACE_COMMENT_FILE}" ]; then
403 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment-file:${TRACE_COMMENT_FILE}"
406 if [ -n "${TRACE_GROUPED}" ]; then
407 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:yes"
410 if [ -n "${TRACE_RESOURCE}" ]; then
411 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:yes --cfg=tracing/uncategorized:yes"
414 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
416 # Do not remove, this variable may be used by user code (e.g. StarPU)
417 export SMPI_GLOBAL_SIZE=${NUMPROCS}
418 if [ -n "${KEEP}" ] && [ -z "${QUIET}" ] ; then
419 echo "${EXEC}" ${PRIVATIZE} "${TRACEOPTIONS}" "${SIMOPTS}" "${PLATFORMTMP}"
420 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
421 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
425 # Execute the process
427 # The shell still need to be alive for the duration in order to do some cleanup after the process.
429 # We are going through great lengths in order to both keep stdin and be able to handle signals:
431 # * The job is launched in the background in order to be able to handle signals.
433 # * The FD 3 is used to temporarily store FD 1. This is because the shell connects FD 1 to /dev/null when the command
434 # is launched in the background: this can be overridden in bash but not in standard bourne shell.
436 ${WRAPPER} "@SMPIMAIN@" "${EXEC}" ${PRIVATIZE} ${DEPLOYOPTS} ${TRACEOPTIONS} ${SIMOPTS} "${PLATFORMTMP}" ${PROC_ARGS} <&3 3>&- &
441 # With dash on Windows WSL/Ubuntu, "wait" sometimes returns early with an exit
442 # status of 128. Try again.
443 while test $status -eq 128 && kill -0 $pid 2>/dev/null; do
449 # Keep temporary files on failures to help debugging
451 if [ ${status} -ne 0 ] ; then
452 if [ -z "${KEEP}" ] && [ -z "${QUIET}" ]; then
453 echo "${EXEC}" ${PRIVATIZE} "${TRACEOPTIONS}" "${SIMOPTS}" "${PLATFORMTMP}"
454 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
455 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
459 echo "Execution failed with code ${status}."