X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c8d557e2067d5510c0c1f349699dba4294d3486c..5ed37babb2fa9097abe82df299c0aa259ed84d5a:/examples/smpi/replay_multiple/generate_multiple_deployment.sh?ds=sidebyside diff --git a/examples/smpi/replay_multiple/generate_multiple_deployment.sh b/examples/smpi/replay_multiple/generate_multiple_deployment.sh index edc24d9c3d..56da4ad919 100755 --- a/examples/smpi/replay_multiple/generate_multiple_deployment.sh +++ b/examples/smpi/replay_multiple/generate_multiple_deployment.sh @@ -1,12 +1,10 @@ -#! /bin/sh +#!/usr/bin/env sh -# Copyright (c) 2007-2014. The SimGrid Team. -# All rights reserved. +# Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. # This program is free software; you can redistribute it and/or modify it # under the terms of the license (GNU LGPL) which comes with this package. - #usage to print the way this script should be called usage () { cat <.*/' ${PLATFORM} > ${HOSTFILE} + perl -ne 'print "$1\n" if /.*.*/' "${PLATFORM}" > "${HOSTFILE}" fi UNROLLEDHOSTFILETMP=0 #parse if our lines are terminated by :num_process -multiple_processes=`grep -c ":" $HOSTFILE` +multiple_processes=$(grep -c ":" "$HOSTFILE") if [ "${multiple_processes}" -gt 0 ] ; then UNROLLEDHOSTFILETMP=1 UNROLLEDHOSTFILE="$(mktemp tmphostXXXXXX)" - perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE} + perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' "${HOSTFILE}" > "${UNROLLEDHOSTFILE}" if [ ${HOSTFILETMP} = 1 ] ; then - rm ${HOSTFILE} + rm "${HOSTFILE}" HOSTFILETMP=0 fi HOSTFILE=$UNROLLEDHOSTFILE fi - # Don't use wc -l to compute it to avoid issues with trailing \n at EOF -hostfile_procs=`grep -c "[a-zA-Z0-9]" $HOSTFILE` -if [ ${hostfile_procs} = 0 ] ; then - echo "[`basename $0`] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2 +hostfile_procs=$(grep -c "[a-zA-Z0-9]" "$HOSTFILE") +if [ "${hostfile_procs}" = 0 ] ; then + echo "[$(basename "$0")] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2 exit 1 fi -APP_TRACES=($PROC_ARGS) ##-------------------------------- DEFAULT APPLICATION -------------------------------------- -APPLICATIONTMP=${APP_TRACES[1]} +APPLICATIONTMP=$(echo "${PROC_ARGS}"|cut -d' ' -f2 -s) -cat > ${APPLICATIONTMP} < "${APPLICATIONTMP}" < - - + + APPLICATIONHEAD ##---- cache hostnames of hostfile--------------- -if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then - hostnames=$(cat ${HOSTFILE} | tr '\n\r' ' ') - NUMHOSTS=$(cat ${HOSTFILE} | wc -l) +if [ -n "${HOSTFILE}" ] && [ -f "${HOSTFILE}" ]; then + hostnames=$(tr '\n\r' ' ' < "${HOSTFILE}") + NUMHOSTS=$(wc -l < "${HOSTFILE}") fi +DESCRIPTIONFILE=$(echo "$PROC_ARGS"|cut -d' ' -f1) - if [ -n "${APP_TRACES[0]}" ] && [ -f "${APP_TRACES[0]}" ]; then - NUMINSTANCES=$(cat ${APP_TRACES[0]} | wc -l) - replayinstances=$(cat ${APP_TRACES[0]}) - IFS_OLD=$IFS - IFS=$'\n' - NUMPROCS=0 - for line in $replayinstances; do +if [ -n "${DESCRIPTIONFILE}" ] && [ -f "${DESCRIPTIONFILE}" ]; then + IFS_OLD=$IFS + IFS=$(printf '\n_'); IFS=${IFS%_} # protect trailing \n + set -f + NUMPROCS=0 + while IFS= read -r line; do # return IFS back if you need to split new line by spaces: IFS=$IFS_OLD IFS_OLD= - array=( $line ) # generate three lists, one with instance id, ont with instance size, one with files - instance=${array[0]} - hosttraces="$hosttraces$(cat ${array[1]}| tr '\n\r' ' ' )" - NUMPROCSMINE=$(cat ${array[1]} | wc -l) - - if [ $NUMPROCSMINE != ${array[2]} ]; + instance=$(echo "$line"|cut -d' ' -f1) + hosttrace=$(tr '\n\r' ' ' < $(echo "$line"|cut -d' ' -f2)) + NUMPROCSMINE=$(wc -l < $(echo "$line"|cut -d' ' -f2)) + + if [ $NUMPROCSMINE != $(echo "$line"|cut -d' ' -f3) ]; then - 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" + 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" exit 1 fi - - sleeptime=${array[3]} - HAVE_SEQ="`which seq 2>/dev/null`" + + sleeptime=$(echo "$line"|cut -d' ' -f4) + HAVE_SEQ=$(which seq 2>/dev/null) if [ -n "${HAVE_SEQ}" ]; then - SEQ1=`${HAVE_SEQ} 0 $((${NUMPROCSMINE}-1))` + SEQ1=$( ${HAVE_SEQ} 0 $(( NUMPROCSMINE - 1 )) ) else cnt=0 - while (( $cnt < ${NUMPROCSMINE} )) ; do - SEQ1="$SEQ1 $cnt" - cnt=$((cnt + 1)); + while [ $(( cnt < NUMPROCSMINE )) -ne 0 ]; do + SEQ1="$SEQ1 $cnt" + cnt=$((cnt + 1)) done fi - NUMPROCS=$((${NUMPROCS}+${NUMPROCSMINE})); + #NUMPROCS=$(( NUMPROCS + NUMPROCSMINE )); for i in $SEQ1 - do - instances="$instances$instance " - ranks="$ranks$SEQ1 " - sleeptimes="$sleeptimes$sleeptime " - done - # return IFS back to newline for "for" loop - IFS_OLD=$IFS - IFS=$'\n' - done - - # return delimiter to previous value - IFS=$IFS_OLD - IFS_OLD= - else - printf "File not found: %s\n", "${APP_TRACES[0]:-\${APP_TRACES[0]\}}" >&2 - exit 1 - fi - - ##---------------------------------------------------------- ## generate application.xml with hostnames from hostfile: ## the name of host_i (1<=i<=p, where -np p) is the line i @@ -193,64 +163,51 @@ fi ## hostfile has less than i lines. ##---------------------------------------------------------- -HAVE_SEQ="`which seq 2>/dev/null`" +##---- generate tags------------------------------ + do + if [ -n "${HOSTFILE}" ]; then + j=$(( NUMPROCS % NUMHOSTS + 1)) + fi + hostname=$(echo "$hostnames"|cut -d' ' -f$j) + if [ -z "${hostname}" ]; then + host="host"$($j) + else + host="${hostname}" + fi + { + echo " " + echo " " + echo " " + echo " " + + echo " " + echo " " + } >> "${APPLICATIONTMP}" + NUMPROCS=$(( NUMPROCS + 1)) + done + # return IFS back to newline for "for" loop + IFS_OLD=$IFS + IFS=$(printf '\n_'); IFS=${IFS%_} # protect trailing \n + done < "${DESCRIPTIONFILE}" -if [ -n "${HAVE_SEQ}" ]; then - SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))` + # return delimiter to previous value + IFS=$IFS_OLD + IFS_OLD= else - cnt=0 - while (( $cnt < ${NUMPROCS} )) ; do - SEQ="$SEQ $cnt" - cnt=$((cnt + 1)); - done + printf "File not found: %s\n", "${DESCRIPTIONFILE}" >&2 + exit 1 fi -##---- generate tags------------------------------ - -hostnames=($hostnames) -instances=($instances) -hosttraces=($hosttraces) -sleeptimes=($sleeptimes) -ranks=($ranks) -for i in ${SEQ} -do - if [ -n "${HOSTFILE}" ]; then - j=$(( $i % ${NUMHOSTS} )) - fi - ##---- optional display of ranks to process mapping - if [ -n "${MAPOPT}" ]; then - echo "[rank $i] -> ${hostnames[j]}" - fi - - if [ -z "${hostnames[j]}" ]; then - host="host"$($j) - else - host="${hostnames[j]}" - fi - echo " " >> ${APPLICATIONTMP} - echo " " >> ${APPLICATIONTMP} - echo " " >> ${APPLICATIONTMP} - if [ ${NUMPROCS} -gt 1 ]; then - echo " " >> ${APPLICATIONTMP} - else - echo " " >> ${APPLICATIONTMP} - fi - echo " " >> ${APPLICATIONTMP} - echo " " >> ${APPLICATIONTMP} -done - -cat >> ${APPLICATIONTMP} <> "${APPLICATIONTMP}" < APPLICATIONFOOT ##-------------------------------- end DEFAULT APPLICATION -------------------------------------- - - if [ ${HOSTFILETMP} = 1 ] ; then - rm ${HOSTFILE} - fi - if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then - rm ${UNROLLEDHOSTFILE} - fi - +if [ ${HOSTFILETMP} = 1 ] ; then + rm "${HOSTFILE}" +fi +if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then + rm "${UNROLLEDHOSTFILE}" +fi exit 0