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.
10 #usage to print the way this script should be called
13 Usage: $0 [OPTIONS] -platform <xmldesc> -hostfile <hostfile> replay-file output-file
17 #check if we have at least one parameter
32 if [ ! -f "${PLATFORM}" ]; then
33 echo "[`basename $0`] ** error: the file '${PLATFORM}' does not exist. Aborting."
40 if [ ! -f "${HOSTFILE}" ]; then
41 echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
48 if [ ! -f "${HOSTFILE}" ]; then
49 echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
60 # steel --cfg and --logs options
61 while [ $# -gt 0 ]; do
66 SIMOPTS="$SIMOPTS ${1%%=*}=$OPT"
71 PROC_ARGS="${PROC_ARGS:+$PROC_ARGS }$1"
78 ##-----------------------------------
81 if [ -z "${HOSTFILE}" ] && [ -z "${PLATFORM}" ] ; then
82 echo "No hostfile nor platform specified."
88 if [ -z "${HOSTFILE}" ] ; then
90 HOSTFILE="$(mktemp tmphostXXXXXX)"
91 perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
95 #parse if our lines are terminated by :num_process
96 multiple_processes=`grep -c ":" $HOSTFILE`
97 if [ "${multiple_processes}" -gt 0 ] ; then
99 UNROLLEDHOSTFILE="$(mktemp tmphostXXXXXX)"
100 perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE}
101 if [ ${HOSTFILETMP} = 1 ] ; then
105 HOSTFILE=$UNROLLEDHOSTFILE
109 # Don't use wc -l to compute it to avoid issues with trailing \n at EOF
110 hostfile_procs=`grep -c "[a-zA-Z0-9]" $HOSTFILE`
111 if [ ${hostfile_procs} = 0 ] ; then
112 echo "[`basename $0`] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2
117 ##-------------------------------- DEFAULT APPLICATION --------------------------------------
119 APPLICATIONTMP=$(echo ${PROC_ARGS}|cut -d' ' -f2 -s)
121 cat > ${APPLICATIONTMP} <<APPLICATIONHEAD
122 <?xml version='1.0'?>
123 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
124 <platform version="3">
127 ##---- cache hostnames of hostfile---------------
128 if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
129 hostnames=$(cat ${HOSTFILE} | tr '\n\r' ' ')
130 NUMHOSTS=$(cat ${HOSTFILE} | wc -l)
134 DESCRIPTIONFILE=$(echo $PROC_ARGS|cut -d' ' -f1)
136 if [ -n "${DESCRIPTIONFILE}" ] && [ -f "${DESCRIPTIONFILE}" ]; then
137 NUMINSTANCES=$(cat ${DESCRIPTIONFILE} | wc -l)
138 replayinstances=$(cat ${DESCRIPTIONFILE})
143 while IFS= read -r line; do
145 # return IFS back if you need to split new line by spaces:
148 # generate three lists, one with instance id, ont with instance size, one with files
149 instance=$(echo "$line"|cut -d' ' -f1)
150 hosttrace=$(cat $(echo "$line"|cut -d' ' -f2)| tr '\n\r' ' ' )
151 NUMPROCSMINE=$(cat $(echo "$line"|cut -d' ' -f2) | wc -l)
153 if [ $NUMPROCSMINE != $(echo "$line"|cut -d' ' -f3) ];
155 echo "declared num of processes for instance $instance : ${array[2]} is not the same as the one in the replay files : $NUMPROCSMINE. Please check consistency of these information"
159 sleeptime=$(echo "$line"|cut -d' ' -f4)
160 HAVE_SEQ="`which seq 2>/dev/null`"
162 if [ -n "${HAVE_SEQ}" ]; then
163 SEQ1=`${HAVE_SEQ} 0 $((${NUMPROCSMINE}-1))`
166 while (( $cnt < ${NUMPROCSMINE} )) ; do
171 #NUMPROCS=$((${NUMPROCS}+${NUMPROCSMINE}));
175 ##----------------------------------------------------------
176 ## generate application.xml with hostnames from hostfile:
177 ## the name of host_i (1<=i<=p, where -np p) is the line i
178 ## in hostfile (where -hostfile hostfile), or "host$i" if
179 ## hostfile has less than i lines.
180 ##----------------------------------------------------------
182 ##---- generate <process> tags------------------------------
185 if [ -n "${HOSTFILE}" ]; then
186 j=$(( ${NUMPROCS} % ${NUMHOSTS} +1))
188 hostname=$(echo $hostnames|cut -d' ' -f$j)
189 if [ -z "${hostname}" ]; then
195 echo " <process host=\"${host}\" function=\"${instance}\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
196 echo " <argument value=\"${instance}\"/> <!-- instance -->" >> ${APPLICATIONTMP}
197 echo " <argument value=\"${i}\"/> <!-- rank -->" >> ${APPLICATIONTMP}
198 echo " <argument value=\"$(echo $hosttrace|cut -d' ' -f$(($i+1)))\"/>" >> ${APPLICATIONTMP}
200 echo " <argument value=\"${sleeptime}\"/> <!-- delay -->" >> ${APPLICATIONTMP}
201 echo " </process>" >> ${APPLICATIONTMP}
202 NUMPROCS=$(( ${NUMPROCS} +1))
204 # return IFS back to newline for "for" loop
207 done < ${DESCRIPTIONFILE}
209 # return delimiter to previous value
213 printf "File not found: %s\n", "${APP_TRACES[0]:-\${APP_TRACES[0]\}}" >&2
219 cat >> ${APPLICATIONTMP} <<APPLICATIONFOOT
222 ##-------------------------------- end DEFAULT APPLICATION --------------------------------------
225 if [ ${HOSTFILETMP} = 1 ] ; then
228 if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
229 rm ${UNROLLEDHOSTFILE}