#!/usr/bin/env bash
#
# Run the mpiopenmp-life program with exactly 16 OpenMP threads
# using and 1, 2, 4, 8, and 16 MPI processes.  When using more
# than 1 MPI process, the threads per process is 16/numprocs.
#
# Each run is done 10 times and the minimum time is reported.
# The time is reported by the program in seconds in the last
# line of each run.  These times are then sorted and the minimum 
# time is reported for each number of MPI processes.
#
for numprocs in 1 2 4 8 16
do
  echo "Running with $numprocs MPI processes and $((16/numprocs)) OpenMP threads per process"
  export OMP_NUM_THREADS=$((16/numprocs))
  for i in {1..10}
  do
    mpirun -np $numprocs ./mpiopenmp-life 40960 .5 10 | tail -n 1 | awk '{print $5}' >> times.$numprocs
    done
    sort -n times.$numprocs | head -n 1
    rm times.$numprocs
  done
  