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=maxmin/precision:1e-3 --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 "[$0] ** error: the file '${PLATFORM}' does not exist. Aborting."
89 if [ ! -f "${HOSTFILE}" ]; then
90 echo "[$0] ** error: the file '${HOSTFILE}' does not exist. Aborting."
98 if [ ! -f "${HOSTFILE}" ]; then
99 echo "[$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 echo -e $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`
248 if [ -z "${NUMPROCS}" ] ; then
249 # Use the amount of processes in the hostfile as default value for the -np parameter
250 NUMPROCS=$hostfile_procs
254 if [ ${NUMPROCS} -gt ${hostfile_procs} ] ; then
255 echo "You requested to use ${NUMPROCS} processes, but there is only ${hostfile_procs} processes in your hostfile..." >&2
258 ##-------------------------------- DEFAULT or SPECIFIED PLATFORM --------------------------------------
259 if [ -z "${PLATFORM}" ]; then
260 PLATFORMTMP="$(mktemp tmpXXXXXX)"
262 cat > ${PLATFORMTMP} <<PLATFORMHEAD
263 <?xml version='1.0'?>
264 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
265 <platform version="3">
266 <AS id="AS0" routing="Full">
270 while [ $i -gt 0 ]; do
271 echo " <host id=\"host$i\" power=\"${POWER}\"/>" >> ${PLATFORMTMP}
272 echo " <link id=\"loop$i\" bandwidth=\"${LOOPBACK_BANDWIDTH}\" latency=\"${LOOPBACK_LATENCY}\"/>" >> ${PLATFORMTMP}
273 echo " <link id=\"link$i\" bandwidth=\"${NETWORK_BANDWIDTH}\" latency=\"${NETWORK_LATENCY}\"/>" >> ${PLATFORMTMP}
278 while [ $i -gt 0 ]; do
280 while [ $j -gt 0 ]; do
281 if [ $i -eq $j ]; then
282 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"loop$i\"/></route>" >> ${PLATFORMTMP}
284 echo " <route src=\"host$i\" dst=\"host$j\"><link_ctn id=\"link$i\"/><link_ctn id=\"link$j\"/></route>" >> ${PLATFORMTMP}
291 cat >> ${PLATFORMTMP} <<PLATFORMFOOT
297 PLATFORMTMP=${PLATFORM}
299 ##-------------------------------- end DEFAULT or SPECIFIED PLATFORM --------------------------------------
301 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
302 APPLICATIONTMP="$(mktemp tmpXXXXXX)"
303 #APPLICATIONTMP="app.xml"
306 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
307 <?xml version='1.0'?>
308 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
309 <platform version="3">
312 ##---- cache hostnames of hostfile---------------
313 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
314 hostnames=$(cat ${HOSTFILE} | tr '\n\r' ' ')
315 NUMHOSTS=$(cat ${HOSTFILE} | wc -l)
318 if [ "${EXTOPT}" = "smpi_replay" ]; then
319 APP_TRACES=$PROC_ARGS
320 if [ -n "${APP_TRACES}" ] && [ -f "${APP_TRACES}" ]; then
321 hosttraces=$(cat ${APP_TRACES} | tr '\n\r' ' ' )
322 NUMTRACES=$(cat ${APP_TRACES} | wc -l)
324 printf "File not found: %s\n", "${APP_TRACES:-\${APP_TRACES\}}" >&2
329 ##----------------------------------------------------------
330 ## generate application.xml with hostnames from hostfile:
331 ## the name of host_i (1<=i<=p, where -np p) is the line i
332 ## in hostfile (where -hostfile hostfile), or "host$i" if
333 ## hostfile has less than i lines.
334 ##----------------------------------------------------------
336 HAVE_SEQ="`which seq 2>/dev/null`"
338 if [ -n "${HAVE_SEQ}" ]; then
339 SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
342 while (( $cnt < ${NUMPROCS} )) ; do
348 ##---- generate <process> tags------------------------------
352 if [ -n "${HOSTFILE}" ]; then
353 j=$(( $i % ${NUMHOSTS} + 1 ))
355 ##---- optional display of ranks to process mapping
356 if [ -n "${MAPOPT}" ]; then
357 echo "[rank $i] -> $(echo $hostnames|cut -d' ' -f$j)"
360 if [ -z "$(echo $hostnames|cut -d' ' -f$j)" ]; then
363 host="$(echo $hostnames|cut -d' ' -f$j)"
365 echo " <process host=\"${host}\" function=\"$i\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
366 echo " <argument value=\"1\"/> <!-- instance -->" >> ${APPLICATIONTMP}
367 echo " <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}
368 if [ "${EXTOPT}" = "smpi_replay" ]; then
369 if [ ${NUMTRACES} -gt 1 ]; then
370 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f$j)\"/>" >> ${APPLICATIONTMP}
372 echo " <argument value=\"$(echo $hosttraces|cut -d' ' -f1)\"/>" >> ${APPLICATIONTMP}
375 for ARG in $PROC_ARGS; do
376 echo " <argument value=\"${ARG}\"/>" >> ${APPLICATIONTMP}
379 echo " </process>" >> ${APPLICATIONTMP}
382 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
385 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
387 ##---------------------- SMPI TRACING OPTIONS ---------------------------------
388 if [ -n "${TRACE_ACTIVE}" ]; then
389 #define trace filename
390 if [ -n "${TRACE_TI_ACTIVE}" ]; then
391 if [ -z "${TRACE_FILENAME}" ]; then
392 TRACE_FILENAME="smpi_simgrid.txt"
394 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes --cfg=tracing/smpi/format:TI --cfg=tracing/smpi/computing:yes"
396 if [ -z "${TRACE_FILENAME}" ]; then
397 TRACE_FILENAME="smpi_simgrid.trace"
399 TRACEOPTIONS="--cfg=tracing:yes --cfg=tracing/filename:${TRACE_FILENAME} --cfg=tracing/smpi:yes"
402 if [ -n "${TRACE_COMMENT}" ]; then
403 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment:${TRACE_COMMENT}"
406 if [ -n "${TRACE_COMMENT_FILE}" ]; then
407 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/comment_file:${TRACE_COMMENT_FILE}"
410 if [ -n "${TRACE_GROUPED}" ]; then
411 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/smpi/group:yes"
414 if [ -n "${TRACE_RESOURCE}" ]; then
415 TRACEOPTIONS="${TRACEOPTIONS} --cfg=tracing/categorized:yes --cfg=tracing/uncategorized:yes"
418 if [ -n "${TRACE_VIVA}" ]; then
419 TRACEOPTIONS="${TRACEOPTIONS} --cfg=viva/categorized:smpi_cat.plist --cfg=viva/uncategorized:smpi_uncat.plist"
422 ##---------------------- end SMPI TRACING OPTIONS ---------------------------------
424 export SMPI_GLOBAL_SIZE=${NUMPROCS}
425 if [ -n "${KEEP}" ] ; then
426 echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
427 if [ ${HOSTFILETMP} = 1 ] ; then
428 echo "Generated hostfile ${HOSTFILE} keeped."
430 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
431 echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} keeped."
434 ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP}
437 if [ -z "${KEEP}" ] ; then
438 if [ -z "${PLATFORM}" ]; then
441 if [ ${HOSTFILETMP} = 1 ] ; then
444 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
445 rm ${UNROLLEDHOSTFILE}