+##---- cache hostnames of hostfile---------------
+if [ -n "${HOSTFILE}" ] && [ -f ${HOSTFILE} ]; then
+ hostnames=(`cat ${HOSTFILE} | tr \\\n " "`)
+ NUMHOSTS=`cat ${HOSTFILE} | wc -l`
+fi
+
+##----------------------------------------------------------
+## generate application.xml with hostnames from hostfile:
+## the name of host_i (1<=i<=p, where -np p) is the line i
+## in hostfile (where -hostfile hostfile), or "host$i" if
+## hostfile has less than i lines.
+##----------------------------------------------------------
+
+HAVE_SEQ="`which seq 2>/dev/null`"
+
+if [ -n "${HAVE_SEQ}" ]; then
+ SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
+else
+ cnt=0
+ while (( $cnt < ${NUMPROCS} )) ; do
+ SEQ="$SEQ $cnt"
+ cnt=$((cnt + 1));
+ done
+fi
+
+##---- generate <process> tags------------------------------
+
+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+1))
+ else
+ host="${hostnames[$j]}"
+ fi
+ echo " <process host=\"${host}\" function=\"rank$i\"> <!-- function name used only for logging -->" >> ${APPLICATIONTMP}
+ echo " <argument value=\"$i\"/> <!-- rank -->" >> ${APPLICATIONTMP}