#!/bin/sh
#
# Execute script for a module program of the EuroBen MPI Benchmark.
#
LOGDIR=Log.`hostname`
PROG=$1/x.$1

if test ! -d ${LOGDIR}
then
  mkdir ${LOGDIR}
fi

if [ $1 = "mod1h" ]; then
  NP=6
elif [ $1 = "mod1j" -o $1 = "mod1k" ]; then 
  NP=2
elif [ $1 = "mod2f" -o $1 = "mod2g" ]; then
  m=0
  NP=$NPROCS
  while [ "$NP" -gt 1 ]; do
    NP=`expr $NP / 2`
    m=`expr $m + 1`
  done
  while [ "$m" -gt 0 ]; do
    NP=`expr "$NP" \* 2`
    m=`expr $m - 1`
  done
  if [ "$NP" -ne "$NPROCS" ]; then
    echo "$1: NPROCS has been modified to Max(n) for which 2^n < NPROCS."
  fi
else
  NP=$NPROCS
fi

if [ "$NP" -lt 10 ]; then
  LOGFILE=${LOGDIR}/$1.p0${NP}.log
else
  LOGFILE=${LOGDIR}/$1.p${NP}.log
fi

if test -f ${PROG}; then
  exec 1>> ${LOGFILE} 2>&1
  echo ; echo ; echo start $1 at `date` id = $$
  (cd $1; time mpirun -np $NP ./x.$1)
  echo ; echo end $1 at `date` 'id =' $$
else
  exec 1>> ${LOGFILE} 2>&1
  echo "$1 not found"
fi
