3 # Copyright (c) 2007-2017. 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.
8 #usage to print the way this script should be called
11 Usage: $0 [OPTIONS] -platform <xmldesc> -hostfile <hostfile> replay-file output-file
15 #check if we have at least one parameter
28 if [ ! -f "${PLATFORM}" ]; then
29 echo "[$(basename $0)] ** error: the file '${PLATFORM}' does not exist. Aborting."
36 if [ ! -f "${HOSTFILE}" ]; then
37 echo "[$(basename $0)] ** error: the file '${HOSTFILE}' does not exist. Aborting."
44 if [ ! -f "${HOSTFILE}" ]; then
45 echo "[$(basename $0)] ** error: the file '${HOSTFILE}' does not exist. Aborting."
56 # steel --cfg and --logs options
57 while [ $# -gt 0 ]; do
62 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
67 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
73 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
74 echo "No hostfile nor platform specified."
80 if [ -z "${HOSTFILE}" ] ; then
82 HOSTFILE="$(mktemp tmphostXXXXXX)"
83 perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
87 #parse if our lines are terminated by :num_process
88 multiple_processes=$(grep -c ":" $HOSTFILE)
89 if [ "${multiple_processes}" -gt 0 ] ; then
91 UNROLLEDHOSTFILE="$(mktemp tmphostXXXXXX)"
92 perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE}
93 if [ ${HOSTFILETMP} = 1 ] ; then
97 HOSTFILE=$UNROLLEDHOSTFILE
100 # Don't use wc -l to compute it to avoid issues with trailing \n at EOF
101 hostfile_procs=$(grep -c "[a-zA-Z0-9]" $HOSTFILE)
102 if [ ${hostfile_procs} = 0 ] ; then
103 echo "[$(basename $0)] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2
107 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
109 APPLICATIONTMP=$(echo ${PROC_ARGS}|cut -d' ' -f2 -s)
111 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
112 <?xml version='1.0'?>
113 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
114 <platform version="4.1">
117 ##---- cache hostnames of hostfile---------------
118 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
119 hostnames=$(tr '\n\r' ' ' < ${HOSTFILE})
120 NUMHOSTS=$(wc -l < ${HOSTFILE})
123 DESCRIPTIONFILE=$(echo $PROC_ARGS|cut -d' ' -f1)
125 if [ -n "${DESCRIPTIONFILE}" ] && [ -f "${DESCRIPTIONFILE}" ]; then
130 while IFS= read -r line; do
131 # return IFS back if you need to split new line by spaces:
134 # generate three lists, one with instance id, ont with instance size, one with files
135 instance=$(echo "$line"|cut -d' ' -f1)
136 hosttrace=$(tr '\n\r' ' ' < $(echo "$line"|cut -d' ' -f2))
137 NUMPROCSMINE=$(wc -l < $(echo "$line"|cut -d' ' -f2))
139 if [ $NUMPROCSMINE != $(echo "$line"|cut -d' ' -f3) ];
141 echo "declared num of processes for instance $instance : $(echo "$line"|cut -d' ' -f3) is not the same as the one in the replay files : $NUMPROCSMINE. Please check consistency of these information"
145 sleeptime=$(echo "$line"|cut -d' ' -f4)
146 HAVE_SEQ=$(which seq 2>/dev/null)
148 if [ -n "${HAVE_SEQ}" ]; then
149 SEQ1=$( ${HAVE_SEQ} 0 $(( NUMPROCSMINE - 1 )) )
152 while (( cnt < NUMPROCSMINE )) ; do
157 #NUMPROCS=$(( NUMPROCS + NUMPROCSMINE ));
159 ##----------------------------------------------------------
160 ## generate application.xml with hostnames from hostfile:
161 ## the name of host_i (1<=i<=p, where -np p) is the line i
162 ## in hostfile (where -hostfile hostfile), or "host$i" if
163 ## hostfile has less than i lines.
164 ##----------------------------------------------------------
166 ##---- generate <actor> tags------------------------------
168 if [ -n "${HOSTFILE}" ]; then
169 j=$(( NUMPROCS % NUMHOSTS + 1))
171 hostname=$(echo $hostnames|cut -d' ' -f$j)
172 if [ -z "${hostname}" ]; then
178 echo " <actor host=\"${host}\" function=\"${instance}\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
179 echo " <argument value=\"${instance}\"/> <!-- instance -->" >> ${APPLICATIONTMP}
180 echo " <argument value=\"${i}\"/> <!-- rank -->" >> ${APPLICATIONTMP}
181 echo " <argument value=\"$(echo $hosttrace|cut -d' ' -f$((i+1)))\"/>" >> ${APPLICATIONTMP}
183 echo " <argument value=\"${sleeptime}\"/> <!-- delay -->" >> ${APPLICATIONTMP}
184 echo " </actor>" >> ${APPLICATIONTMP}
185 NUMPROCS=$(( NUMPROCS + 1))
187 # return IFS back to newline for "for" loop
190 done < ${DESCRIPTIONFILE}
192 # return delimiter to previous value
196 printf "File not found: %s\n", ${DESCRIPTIONFILE} >&2
200 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
203 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
205 if [ ${HOSTFILETMP} = 1 ] ; then
208 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
209 rm ${UNROLLEDHOSTFILE}