#!/bin/bash

# get info on the testcase to run
[ -n "$SLURM_NTASKS" ] || { echo "Invalid SLURM allocation" >&2; exit 1; }
NTASKS=${ntasks:-$SLURM_NTASKS}
NNODES=$SLURM_NNODES
NODELIST=$SLURM_NODELIST

# setup environment for MPI
. /opt/intel/impi/4.0.0.028/bin64/mpivars.sh
export OMPI_MCA_btl="^openib"


# clear client cache
clush -l root -bw "$NODELIST" "echo '3' > /proc/sys/vm/drop_caches"

# read the file
echo "Starting test with $NTASKS tasks"
count=${count:-"4k"}
bs=${bs:-"1M"}
out=$(mpirun -n $NTASKS dd if=/fsperf/pichong/stripe_all/large_file of=/dev/null bs=$bs count=$count 2>&1)
echo "$out"
echo "$out" | awk 'BEGIN { printf("   %6s %8s %8s (MB/s)\n", "tasks", "Mean", "Total") } /MB\/s$/ { n++; sum+=$(NF-1) } END { printf("dd %6d %8d %8d\n", n, sum/n, sum) }'

