3 # Copyright (c) 2007-2023. 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=precision/timing: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
62 -help # Displays this information
63 -help-coll # Displays all available collective algorithms
65 or (deprecated usage):
66 $0 [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]
71 #check if we have at least one parameter
84 trapped_signals="HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS"
87 printf '[%s] ** error: %s. Aborting.\n' "$(basename "$0")" "$*" >&2
93 if [ -z "${KEEP}" ] ; then
94 if [ -z "${PLATFORM}" ] && [ -n "$PLATFORMTMP" ]; then
95 rm -f "${PLATFORMTMP}"
98 if [ "${UNROLLEDHOSTFILETMP}" = 1 ] && [ -n "$UNROLLEDHOSTFILE" ] ; then
99 rm -f "${UNROLLEDHOSTFILE}"
109 # Cleanup and kill the child process:
111 if [ -n "$pid" ]; then
116 # Raise the same signal again (remove the traps first):
117 trap - $trapped_signals
120 # This should never happen:
125 for s in $trapped_signals; do
126 trap "smpirun_trap $s" "$s"
136 NETWORK_BANDWIDTH="$2"
145 if [ ! -f "${PLATFORM}" ]; then
146 die "the file '${PLATFORM}' does not exist"
150 "-hostfile" | "-machinefile")
152 if [ ! -f "${HOSTFILE}" ]; then
153 die "the file '${HOSTFILE}' does not exist"
159 if [ ! -f "${APP_TRACES}" ]; then
160 die "the file '${APP_TRACES}' does not exist"
162 DEPLOYOPTS="${DEPLOYOPTS} --cfg=smpi/replay:${APP_TRACES}"
166 PRIVATIZE="--cfg=smpi/privatization:no"
170 DEPLOYOPTS="${DEPLOYOPTS} --cfg=smpi/map:1"
183 TRACE_TI_ACTIVE="true"
190 "-trace-comment-file")
191 TRACE_COMMENT_FILE="$2"
203 TRACE_RESOURCE="true"
208 SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
222 SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
226 WRAPPER="valgrind --vgdb=yes --vgdb-error=0"
228 SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
234 SIMOPTS="$SIMOPTS --cfg=smpi/keep-temps:yes"
238 SIMOPTS="$SIMOPTS --cfg=smpi/display-timing:yes --cfg=smpi/display-allocs:yes --cfg=smpi/list-leaks:50 --cfg=smpi/pedantic:true --cfg=smpi/barrier-collectives:true"
241 "-help" | "--help" | "-h")
245 "-help-coll" | "--help-coll")
246 ${WRAPPER} "@SMPIMAIN@" --help-coll
249 "-version" | "--version" | "-v")
250 printf '%b\n' "$SIMGRID_VERSION"
253 "-git-version" | "--git-version")
254 printf '%b\n' "$SIMGRID_GITHASH"
260 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
265 # Nothing to do, compatibility.
275 SIMOPTS="$SIMOPTS --cfg=smpi/tmpdir:$SMPITMPDIR"
276 export LD_LIBRARY_PATH="$SMPITMPDIR:$LD_LIBRARY_PATH"
278 if [ -n "${APP_TRACES}" ] ; then
279 if [ $# -eq 0 ] ; then
280 EXEC="@SMPIREPLAYMAIN@"
286 # check if we still have at least one parameter beyond options
289 echo "Error: no program to execute!"
298 # steal --cfg and --logs options
299 while [ $# -gt 0 ]; do
304 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
309 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
315 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
316 echo "No hostfile nor platform specified."
321 UNROLLEDHOSTFILETMP=0
323 # parse if our lines are terminated by :num_process
324 if [ -n "${HOSTFILE}" ] && grep -q ':' "${HOSTFILE}" ; then
325 UNROLLEDHOSTFILETMP=1
326 UNROLLEDHOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
327 @PYTHON_EXECUTABLE@ -c '
331 for line in sys.stdin:
332 m = re.match("(.*):(.*)", line)
334 for i in range(0, int(m.group(2))):
338 ' < "${HOSTFILE}" > "${UNROLLEDHOSTFILE}"
339 HOSTFILE=$UNROLLEDHOSTFILE
342 DEPLOYOPTS="${DEPLOYOPTS} --cfg=smpi/np:${NUMPROCS}"
343 DEPLOYOPTS="${DEPLOYOPTS} --cfg=smpi/hostfile:${HOSTFILE}"
345 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
346 if [ -z "${PLATFORM}" ]; then
347 PLATFORMTMP="$(mktemp smpitmp-platfXXXXXX)"
349 cat > "${PLATFORMTMP}" <<PLATFORMHEAD
350 <?xml version='1.0'?>
351 <!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
352 <platform version="4.1">
353 <zone id="AS0" routing="Full">
357 while [ "$i" -gt 0 ]; do
359 echo " <host id=\"host$i\" speed=\"${SPEED}\"/>"
360 echo " <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>"
361 echo " <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>"
362 } >> "${PLATFORMTMP}"
367 while [ "$i" -gt 0 ]; do
369 while [ "$j" -gt 0 ]; do
370 if [ "$i" -eq "$j" ]; then
371 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> "${PLATFORMTMP}"
373 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> "${PLATFORMTMP}"
380 cat >> "${PLATFORMTMP}" <<PLATFORMFOOT
386 PLATFORMTMP=${PLATFORM}
388 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
389 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
390 if [ -n "${TRACE_ACTIVE}" ]; then
391 #define trace filename
392 if [ -n "${TRACE_TI_ACTIVE}" ]; then
393 if [ -z "${TRACE_FILENAME}" ]; then
394 TRACE_FILENAME="smpi_simgrid.txt"
396 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes --cfg=tracing/smpi/format:TI --cfg=tracing/smpi/computing:yes"
398 if [ -z "${TRACE_FILENAME}" ]; then
399 TRACE_FILENAME="smpi_simgrid.trace"
401 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes"
404 if [ -n "${TRACE_COMMENT}" ]; then
405 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment:${TRACE_COMMENT}"
408 if [ -n "${TRACE_COMMENT_FILE}" ]; then
409 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment-file:${TRACE_COMMENT_FILE}"
412 if [ -n "${TRACE_GROUPED}" ]; then
413 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:yes"
416 if [ -n "${TRACE_RESOURCE}" ]; then
417 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:yes --cfg=tracing/uncategorized:yes"
420 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
422 # Do not remove, this variable may be used by user code (e.g. StarPU)
423 export SMPI_GLOBAL_SIZE=${NUMPROCS}
424 if [ -n "${KEEP}" ] && [ -z "${QUIET}" ] ; then
425 echo "${EXEC}" ${PRIVATIZE} "${TRACEOPTIONS}" "${SIMOPTS}" "${PLATFORMTMP}"
426 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
427 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
431 # Execute the process
433 # The shell still need to be alive for the duration in order to do some cleanup after the process.
435 # We are going through great lengths in order to both keep stdin and be able to handle signals:
437 # * The job is launched in the background in order to be able to handle signals.
439 # * The FD 3 is used to temporarily store FD 1. This is because the shell connects FD 1 to /dev/null when the command
440 # is launched in the background: this can be overridden in bash but not in standard bourne shell.
442 ${WRAPPER} "@SMPIMAIN@" "${EXEC}" ${PRIVATIZE} ${DEPLOYOPTS} ${TRACEOPTIONS} ${SIMOPTS} "${PLATFORMTMP}" ${PROC_ARGS} <&3 3>&- &
447 # With dash on Windows WSL/Ubuntu, "wait" sometimes returns early with an exit
448 # status of 128. Try again.
449 while test $status -eq 128 && kill -0 $pid 2>/dev/null; do
455 # Keep temporary files on failures to help debugging
457 if [ ${status} -ne 0 ] ; then
458 if [ -z "${KEEP}" ] && [ -z "${QUIET}" ]; then
459 echo "${EXEC}" ${PRIVATIZE} "${TRACEOPTIONS}" "${SIMOPTS}" "${PLATFORMTMP}"
460 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
461 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
465 echo "Execution failed with code ${status}."