3 # Copyright (c) 2007-2015. 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 SIMGRID_VERSION="@SIMGRID_VERSION_STRING@"
12 SIMGRID_GITHASH="@SIMGRID_GITHASH@"
14 DEFAULT_LOOPBACK_BANDWIDTH="498000000Bps"
15 DEFAULT_LOOPBACK_LATENCY="0.000004s"
16 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))Bps"
17 DEFAULT_NETWORK_LATENCY="0.000005s"
19 DEFAULT_SPEED="100flops"
21 LOOPBACK_BANDWIDTH="${DEFAULT_LOOPBACK_BANDWIDTH}"
22 LOOPBACK_LATENCY="${DEFAULT_LOOPBACK_LATENCY}"
23 NETWORK_BANDWIDTH="${DEFAULT_NETWORK_BANDWIDTH}"
24 NETWORK_LATENCY="${DEFAULT_NETWORK_LATENCY}"
25 SPEED="${DEFAULT_SPEED}"
27 SIMOPTS="--cfg=surf/precision:1e-9 --cfg=network/model:SMPI --cfg=network/TCP-gamma:4194304"
29 #usage to print the way this script should be called
32 Usage: $0 [OPTIONS] -platform <xmldesc> -hostfile <hostfile> program [program-options]
34 -keep-temps # don't remove the generated files after execution
35 -wrapper <command> # use command to run the program (e.g. "valgrind")
36 -map # display the machine on which each process rank is mapped
37 -np <numprocs> # use that amount of processes from the hostfile.
38 # By default, all processes of the hostfile are used.
39 -trace-ti # activate time independant tracing (for replay, default in smpi_simgrid.txt)
40 -trace # activate tracing (Paje, default in smpi_simgrid.trace)
41 -trace-comment <comment> # put a comment on the top of the trace file
42 -trace-comment-file <file> # put file contents on the top of the trace file as comment
43 -trace-grouped # group MPI processes by location
44 -trace-resource # trace resource utilization
45 -trace-viva # generate configuration for Viva's GraphView
46 -trace-file <tracefile> # name of the tracefile (simgrid_smpi.trace)
47 -ext <value> # additional parameter (reserved)
49 -version # Displays the SimGrid version (human readable)
50 -git-version # Displays the git hash of SimGrid
52 or (deprecated usage):
53 $0 [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]
58 #check if we have at least one parameter
72 trapped_signals="HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS"
76 if [ -z "${KEEP}" ] ; then
77 if [ -z "${PLATFORM}" -a -n "$PLATFORMTMP" ]; then
81 if [ ${HOSTFILETMP} = 1 -a -n "$HOSTFILE" ] ; then
85 if [ ${UNROLLEDHOSTFILETMP} = 1 -a -n "$UNROLLEDHOSTFILE" ] ; then
86 rm -f ${UNROLLEDHOSTFILE}
89 if [ -n ${APPLICATIONTMP} ]; then
90 rm -f ${APPLICATIONTMP}
100 # Cleanup and kill the child process:
102 if ! [ -z "$pid" ]; then
107 # Raise the same signal again (remove the traps first):
108 trap - $trapped_signals
111 # This should never happen:
116 for s in $trapped_signals; do
117 trap "smpirun_trap $s" $s
127 NETWORK_BANDWIDTH="$2"
136 if [ ! -f "${PLATFORM}" ]; then
137 echo "[`basename $0`] ** error: the file '${PLATFORM}' does not exist. Aborting."
144 if [ ! -f "${HOSTFILE}" ]; then
145 echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
152 if [ ! -f "${HOSTFILE}" ]; then
153 echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
172 TRACE_TI_ACTIVE="true"
179 "-trace-comment-file")
180 TRACE_COMMENT_FILE="$2"
192 TRACE_RESOURCE="true"
207 "-help" | "--help" | "-h")
211 "-version" | "--version" | "-v")
212 printf '%b\n' "$SIMGRID_VERSION"
215 "-git-version" | "--git-version")
216 printf '%b\n' "$SIMGRID_GITHASH"
222 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
227 # Nothing to do, compatibility.
236 if [ -n "$WRAPPER" ]; then
243 # steel --cfg and --logs options
244 while [ $# -gt 0 ]; do
249 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
254 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
260 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
261 echo "No hostfile nor platform specified."
266 if [ -z "${HOSTFILE}" ] ; then
268 HOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
269 perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
270 perl -ne 'if (/.*<cluster.*?prefix="(.*?)".*?radical="(.*?)".*?suffix="(.*?)".*/) {
271 my ($pre,$rad,$post)=($1,$2,$3);
272 for my $elm (split(",",$rad)) {
273 if ($elm=~/^([^-]*?)-([^-]*)$/) {
274 for (my $i=$1; $i<=$2;$i++) {
275 print "$pre$i$post\n";
278 print "$pre$elm$post\n";
281 } elsif (/<cluster/) {
282 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)");
283 }' ${PLATFORM} >> ${HOSTFILE}
285 UNROLLEDHOSTFILETMP=0
287 #parse if our lines are terminated by :num_process
288 multiple_processes=`grep -c ":" $HOSTFILE`
289 if [ "${multiple_processes}" -gt 0 ] ; then
290 UNROLLEDHOSTFILETMP=1
291 UNROLLEDHOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
292 perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE}
293 if [ ${HOSTFILETMP} = 1 ] ; then
297 HOSTFILE=$UNROLLEDHOSTFILE
300 # Don't use wc -l to compute it to avoid issues with trailing \n at EOF
301 hostfile_procs=`grep -c "[a-zA-Z0-9]" $HOSTFILE`
302 if [ ${hostfile_procs} = 0 ] ; then
303 echo "[`basename $0`] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2
307 if [ -z "${NUMPROCS}" ] ; then
308 # Use the amount of processes in the hostfile as default value for the -np parameter
309 NUMPROCS=$hostfile_procs
312 if [ ${NUMPROCS} -gt ${hostfile_procs} ] ; then
313 echo "You requested to use ${NUMPROCS} processes, but there is only ${hostfile_procs} processes in your hostfile..." >&2
316 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
317 if [ -z "${PLATFORM}" ]; then
318 PLATFORMTMP="$(mktemp smpitmp-platfXXXXXX)"
320 cat > ${PLATFORMTMP} <<PLATFORMHEAD
321 <?xml version='1.0'?>
322 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
323 <platform version="4">
324 <AS id="AS0" routing="Full">
328 while [ $i -gt 0 ]; do
329 echo " <host id=\"host$i\" speed=\"${SPEED}\"/>" >> ${PLATFORMTMP}
330 echo " <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
331 echo " <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
336 while [ $i -gt 0 ]; do
338 while [ $j -gt 0 ]; do
339 if [ $i -eq $j ]; then
340 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
342 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
349 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
355 PLATFORMTMP=${PLATFORM}
357 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
358 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
359 APPLICATIONTMP="$(mktemp smpitmp-appXXXXXX)"
360 #APPLICATIONTMP="app.xml"
362 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
363 <?xml version='1.0'?>
364 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
365 <platform version="4">
368 ##---- cache hostnames of hostfile---------------
369 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
370 hostnames=$(cat ${HOSTFILE} | tr '\n\r' ' ')
371 NUMHOSTS=$(cat ${HOSTFILE} | wc -l)
374 if [ "${EXTOPT}" = "smpi_replay" ]; then
375 APP_TRACES=$PROC_ARGS
376 if [ -n "${APP_TRACES}" ] && [ -f "${APP_TRACES}" ]; then
377 hosttraces=$(cat ${APP_TRACES} | tr '\n\r' ' ' )
378 NUMTRACES=$(cat ${APP_TRACES} | wc -l)
380 printf "File not found: %s\n" "${APP_TRACES:-\${APP_TRACES\}}" >&2
385 ##----------------------------------------------------------
386 ## generate application.xml with hostnames from hostfile:
387 ## the name of host_i (1<=i<=p, where -np p) is the line i in hostfile (where -hostfile hostfile), or "host$i" if
388 ## hostfile has less than i lines.
389 ##----------------------------------------------------------
391 HAVE_SEQ="`which seq 2>/dev/null`"
393 if [ -n "${HAVE_SEQ}" ]; then
394 SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
397 while [ $cnt -lt ${NUMPROCS} ] ; do
403 ##---- generate <process> tags------------------------------
406 if [ -n "${HOSTFILE}" ]; then
407 j=$(( $i % ${NUMHOSTS} + 1 ))
409 ##---- optional display of ranks to process mapping
410 if [ -n "${MAPOPT}" ]; then
411 echo "[rank $i] -> $(echo $hostnames|cut -d' ' -f$j)"
414 if [ -z "$(echo $hostnames|cut -d' ' -f$j)" ]; then
417 host="$(echo $hostnames|cut -d' ' -f$j)"
419 echo " <process host=\"${host}\" function=\"$i\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
420 echo " <argument value=\"1\"/> <!-- instance -->" >> ${APPLICATIONTMP}
421 echo " <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
422 if [ "${EXTOPT}" = "smpi_replay" ]; then
423 if [ ${NUMTRACES} -gt 1 ]; then
424 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f$j)\"/>" >> ${APPLICATIONTMP}
426 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f1)\"/>" >> ${APPLICATIONTMP}
429 for ARG in $PROC_ARGS; do
430 echo " <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
433 echo " </process>" >> ${APPLICATIONTMP}
436 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
439 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
440 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
441 if [ -n "${TRACE_ACTIVE}" ]; then
442 #define trace filename
443 if [ -n "${TRACE_TI_ACTIVE}" ]; then
444 if [ -z "${TRACE_FILENAME}" ]; then
445 TRACE_FILENAME="smpi_simgrid.txt"
447 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes --cfg=tracing/smpi/format:TI --cfg=tracing/smpi/computing:yes"
449 if [ -z "${TRACE_FILENAME}" ]; then
450 TRACE_FILENAME="smpi_simgrid.trace"
452 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes"
455 if [ -n "${TRACE_COMMENT}" ]; then
456 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment:${TRACE_COMMENT}"
459 if [ -n "${TRACE_COMMENT_FILE}" ]; then
460 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment-file:${TRACE_COMMENT_FILE}"
463 if [ -n "${TRACE_GROUPED}" ]; then
464 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:yes"
467 if [ -n "${TRACE_RESOURCE}" ]; then
468 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:yes --cfg=tracing/uncategorized:yes"
471 if [ -n "${TRACE_VIVA}" ]; then
472 TRACEOPTIONS="${TRACEOPTIONS} --cfg=viva/categorized:smpi_cat.plist --cfg=viva/uncategorized:smpi_uncat.plist"
475 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
477 export SMPI_GLOBAL_SIZE=${NUMPROCS}
478 if [ -n "${KEEP}" ] ; then
479 echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
480 if [ ${HOSTFILETMP} = 1 ] ; then
481 echo "Generated hostfile ${HOSTFILE} kept."
483 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
484 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
488 # Execute the process
490 # The shell still need to be alive for the duration in order to do some cleanup after the process.
492 # We are going through great lengths in order to both keep stdin and be able to handle signals:
494 # * The job is launched in the background in order to be able to handle signals.
496 # * The FD 3 is used to temporarily store FD 1. This is because the shell connects FD 1 to /dev/null when the command
497 # is launched in the background: this can be overriden in bash but not in standard bourne shell.
499 ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP} <&3 3>&- &