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 SIMGRID_VERSION="@SIMGRID_VERSION_STRING@"
13 DEFAULT_LOOPBACK_BANDWIDTH="498000000"
14 DEFAULT_LOOPBACK_LATENCY="0.000004"
15 DEFAULT_NETWORK_BANDWIDTH="$((26 * 1024 * 1024))"
16 DEFAULT_NETWORK_LATENCY="0.000005"
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 POWER="${DEFAULT_POWER}"
26 SIMOPTS="--cfg=surf/precision:1e-9 --cfg=network/model:SMPI --cfg=network/TCP_gamma:4194304"
28 #usage to print the way this script should be called
31 Usage: $0 [OPTIONS] -platform <xmldesc> -hostfile <hostfile> program [program-options]
33 -keep-temps # don't remove the generated files after execution
34 -wrapper <command> # use command to run the program (e.g. "valgrind")
35 -map # display the machine on which each process rank is mapped
36 -np <numprocs> # use that amount of processes from the hostfile.
37 # By default, all processes of the hostfile are used.
38 -trace-ti # activate time independant tracing (for replay, default in smpi_simgrid.txt)
39 -trace # activate tracing (Paje, default in smpi_simgrid.trace)
40 -trace-comment <comment> # put a comment on the top of the trace file
41 -trace-comment-file <file> # put file contents on the top of the trace file as comment
42 -trace-grouped # group MPI processes by location
43 -trace-resource # trace resource utilization
44 -trace-viva # generate configuration for Viva's GraphView
45 -trace-file <tracefile> # name of the tracefile (simgrid_smpi.trace)
46 -ext <value> # additional parameter (reserved)
48 or (deprecated usage):
49 $0 [-keep-temps] [-np <numprocs>] [-bandwidth <bytes/sec>] [-latency <secs>] program [program-options]
54 #check if we have at least one parameter
72 NETWORK_BANDWIDTH="$2"
81 if [ ! -f "${PLATFORM}" ]; then
82 echo "[`basename $0`] ** error: the file '${PLATFORM}' does not exist. Aborting."
89 if [ ! -f "${HOSTFILE}" ]; then
90 echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
98 if [ ! -f "${HOSTFILE}" ]; then
99 echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
122 TRACE_TI_ACTIVE="true"
131 "-trace-comment-file")
132 TRACE_COMMENT_FILE="$2"
147 TRACE_RESOURCE="true"
166 "-help" | "--help" | "-h")
171 "-version" | "--version" | "-v")
172 printf '%b\n' "$SIMGRID_VERSION"
179 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
189 if [ -n "$WRAPPER" ]; then
196 # steel --cfg and --logs options
197 while [ $# -gt 0 ]; do
202 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
207 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
214 ##-----------------------------------
217 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
218 echo "No hostfile nor platform specified."
224 if [ -z "${HOSTFILE}" ] ; then
226 HOSTFILE="$(mktemp tmphostXXXXXX)"
227 perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
229 UNROLLEDHOSTFILETMP=0
231 #parse if our lines are terminated by :num_process
232 multiple_processes=`grep -c ":" $HOSTFILE`
233 if [ "${multiple_processes}" -gt 0 ] ; then
234 UNROLLEDHOSTFILETMP=1
235 UNROLLEDHOSTFILE="$(mktemp tmphostXXXXXX)"
236 perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE}
237 if [ ${HOSTFILETMP} = 1 ] ; then
241 HOSTFILE=$UNROLLEDHOSTFILE
245 # Don't use wc -l to compute it to avoid issues with trailing \n at EOF
246 hostfile_procs=`grep -c "[a-zA-Z0-9]" $HOSTFILE`
247 if [ ${hostfile_procs} = 0 ] ; then
248 echo "[`basename $0`] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2
252 if [ -z "${NUMPROCS}" ] ; then
253 # Use the amount of processes in the hostfile as default value for the -np parameter
254 NUMPROCS=$hostfile_procs
258 if [ ${NUMPROCS} -gt ${hostfile_procs} ] ; then
259 echo "You requested to use ${NUMPROCS} processes, but there is only ${hostfile_procs} processes in your hostfile..." >&2
262 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
263 if [ -z "${PLATFORM}" ]; then
264 PLATFORMTMP="$(mktemp tmpXXXXXX)"
266 cat > ${PLATFORMTMP} <<PLATFORMHEAD
267 <?xml version='1.0'?>
268 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
269 <platform version="3">
270 <AS id="AS0" routing="Full">
274 while [ $i -gt 0 ]; do
275 echo " <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
276 echo " <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
277 echo " <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
282 while [ $i -gt 0 ]; do
284 while [ $j -gt 0 ]; do
285 if [ $i -eq $j ]; then
286 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
288 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
295 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
301 PLATFORMTMP=${PLATFORM}
303 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
305 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
306 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
307 #APPLICATIONTMP="app.xml"
310 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
311 <?xml version='1.0'?>
312 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
313 <platform version="3">
316 ##---- cache hostnames of hostfile---------------
317 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
318 hostnames=$(cat ${HOSTFILE} | tr '\n\r' ' ')
319 NUMHOSTS=$(cat ${HOSTFILE} | wc -l)
322 if [ "${EXTOPT}" = "smpi_replay" ]; then
323 APP_TRACES=$PROC_ARGS
324 if [ -n "${APP_TRACES}" ] && [ -f "${APP_TRACES}" ]; then
325 hosttraces=$(cat ${APP_TRACES} | tr '\n\r' ' ' )
326 NUMTRACES=$(cat ${APP_TRACES} | wc -l)
328 printf "File not found: %s\n", "${APP_TRACES:-\${APP_TRACES\}}" >&2
333 ##----------------------------------------------------------
334 ## generate application.xml with hostnames from hostfile:
335 ## the name of host_i (1<=i<=p, where -np p) is the line i
336 ## in hostfile (where -hostfile hostfile), or "host$i" if
337 ## hostfile has less than i lines.
338 ##----------------------------------------------------------
340 HAVE_SEQ="`which seq 2>/dev/null`"
342 if [ -n "${HAVE_SEQ}" ]; then
343 SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
346 while (( $cnt < ${NUMPROCS} )) ; do
352 ##---- generate <process> tags------------------------------
356 if [ -n "${HOSTFILE}" ]; then
357 j=$(( $i % ${NUMHOSTS} + 1 ))
359 ##---- optional display of ranks to process mapping
360 if [ -n "${MAPOPT}" ]; then
361 echo "[rank $i] -> $(echo $hostnames|cut -d' ' -f$j)"
364 if [ -z "$(echo $hostnames|cut -d' ' -f$j)" ]; then
367 host="$(echo $hostnames|cut -d' ' -f$j)"
369 echo " <process host=\"${host}\" function=\"$i\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
370 echo " <argument value=\"1\"/> <!-- instance -->" >> ${APPLICATIONTMP}
371 echo " <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
372 if [ "${EXTOPT}" = "smpi_replay" ]; then
373 if [ ${NUMTRACES} -gt 1 ]; then
374 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f$j)\"/>" >> ${APPLICATIONTMP}
376 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f1)\"/>" >> ${APPLICATIONTMP}
379 for ARG in $PROC_ARGS; do
380 echo " <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
383 echo " </process>" >> ${APPLICATIONTMP}
386 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
389 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
391 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
392 if [ -n "${TRACE_ACTIVE}" ]; then
393 #define trace filename
394 if [ -n "${TRACE_TI_ACTIVE}" ]; then
395 if [ -z "${TRACE_FILENAME}" ]; then
396 TRACE_FILENAME="smpi_simgrid.txt"
398 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes --cfg=tracing/smpi/format:TI --cfg=tracing/smpi/computing:yes"
400 if [ -z "${TRACE_FILENAME}" ]; then
401 TRACE_FILENAME="smpi_simgrid.trace"
403 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes"
406 if [ -n "${TRACE_COMMENT}" ]; then
407 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment:${TRACE_COMMENT}"
410 if [ -n "${TRACE_COMMENT_FILE}" ]; then
411 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment_file:${TRACE_COMMENT_FILE}"
414 if [ -n "${TRACE_GROUPED}" ]; then
415 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:yes"
418 if [ -n "${TRACE_RESOURCE}" ]; then
419 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:yes --cfg=tracing/uncategorized:yes"
422 if [ -n "${TRACE_VIVA}" ]; then
423 TRACEOPTIONS="${TRACEOPTIONS} --cfg=viva/categorized:smpi_cat.plist --cfg=viva/uncategorized:smpi_uncat.plist"
426 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
428 export SMPI_GLOBAL_SIZE=${NUMPROCS}
429 if [ -n "${KEEP}" ] ; then
430 echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
431 if [ ${HOSTFILETMP} = 1 ] ; then
432 echo "Generated hostfile ${HOSTFILE} keeped."
434 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
435 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} keeped."
438 ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
441 if [ -z "${KEEP}" ] ; then
442 if [ -z "${PLATFORM}" ]; then
445 if [ ${HOSTFILETMP} = 1 ] ; then
448 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
449 rm ${UNROLLEDHOSTFILE}