+if [ -z "${HOSTFILE}" ] ; then
+ HOSTFILETMP=1
+ HOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
+ perl -ne 'print "$1\n" if /.*<host.*?id="(.*?)".*?\/>.*/' ${PLATFORM} > ${HOSTFILE}
+ perl -ne 'if (/.*<cluster.*?prefix="(.*?)".*?radical="(.*?)".*?suffix="(.*?)".*/) {
+ my ($pre,$rad,$post)=($1,$2,$3);
+ for my $elm (split(",",$rad)) {
+ if ($elm=~/^([^-]*?)-([^-]*)$/) {
+ for (my $i=$1; $i<=$2;$i++) {
+ print "$pre$i$post\n";
+ }
+ } else {
+ print "$pre$elm$post\n";
+ }
+ }
+ } elsif (/<cluster/) {
+ die ("Unparsable cluster tag. smpirun uses a primitive regular expression to parse cluster tags. Either provide a hostfile yourself or give the attributes prefix, radical and suffix IN THAT ORDER and ON THE SAME LINE as the opening tag (<cluster)");
+ }' ${PLATFORM} >> ${HOSTFILE}
+fi
+UNROLLEDHOSTFILETMP=0
+
+#parse if our lines are terminated by :num_process
+multiple_processes=$(grep -c ":" $HOSTFILE)
+if [ "${multiple_processes}" -gt 0 ] ; then
+ UNROLLEDHOSTFILETMP=1
+ UNROLLEDHOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
+ perl -ne ' do{ for ( 1 .. $2 ) { print "$1\n" } } if /(.*?):(\d+).*/' ${HOSTFILE} > ${UNROLLEDHOSTFILE}
+ if [ ${HOSTFILETMP} = 1 ] ; then
+ 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
+ die "the hostfile '${HOSTFILE}' is empty"
+fi
+
+if [ -z "${NUMPROCS}" ] ; then
+ # Use the amount of processes in the hostfile as default value for the -np parameter
+ NUMPROCS=$hostfile_procs
+fi