Calc testjobs linux.sh

From Biowerkzeug Wiki
Revision as of 13:37, 7 December 2008 by Oliver (talk | contribs) (benchmarking and testing script)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This script allows running Hippo benchmarks.

#!/bin/bash
# Running Hippo tests (Linux)
# Copyright (c) 2008 Biowerkzeug
# Oliver Beckstein <orbeckst@gmail.com>
#set -x

prog=$(basename $0)
CURDIR=${PWD}

# defaults (: can be set in environment)
: ${HIPPO_DIR:="${CURDIR}/.."}
HIPPO_TESTS="hexane_NVT_dp_MD octane_NPT_sp_MC pentadecane_NPT_sp_MD tip3p_NPT_sp_MD trpzip2_GBSA_MC vpu_GBIM_MC walp_octane_NPT_sp_MD"
RUN_TESTS=${HIPPO_TESTS}
USE_MPI=0

usage="usage $prog [opts] [tests]

Run Hippo tests. By default it runs all of them:
 ${HIPPO_TESTS}

OPTIONS:
-h               help
-n               number of threads (not possible for all tests)
-D               directory where we look for Hippo executables [${HIPPO_DIR}]
-M               use mpi (replica exchange) binaries [${USE_MPI}]

Environment variables:
HIPPO_DIR        overrides -D [${HIPPO_DIR}]
"

function die () {
 local msg="$1" err=${2:-1}
 echo 1>&2 "ERROR: failed in $PWD: ${msg}"
 cd ${CURDIR}
 exit $err
} 

NSLOTS=1
# opt processing
while getopts hn:D:M: opt; do
    case $opt in
	h) echo "$usage"; exit 0;;
	n) NSLOTS=${OPTARG};;
	D) HIPPO_DIR=${OPTARG};;
	M) USE_MPI=${OPTARG};;
	*) die "Unknown option" 1;;
    esac
done

#echo "OPTIND=$OPTIND OPTARG=$OPTARG  argv=$*"
shift $((OPTIND - 1))
if [ -n "$*" ]; then
    RUN_TESTS="$*"
fi

echo "Running the following tests using ${NSLOTS} threads: ${RUN_TESTS}"


# find working executable 
# we'll use the first one that only complain about missing input file
#
if [ ${USE_MPI} = 0 ]; then
  echo "Only trying single cpu binaries"
  _HIPPO_BINARIES="hippo hippo_p3"
else
  _HIPPO_BINARIES="hippo_mpi hippo hippo_p3_mpi hippo_p3"
fi
HIPPO="not_found"
rm -f hippo_input.txt  # clean any input files
for h in ${_HIPPO_BINARIES}; do
  exe="${HIPPO_DIR}/${h}"
  if ${exe} 2>&1 | egrep "^Hippo.*Copyright.*Biowerkzeug" >/dev/null; then
     HIPPO=${exe}
     break
  fi
done
if [ "${HIPPO}" = "not_found" ]; then
   ARCH=$(uname -m); 
   OS=$(uname -s);
   die "No usable hippo executable found; see if there is one at
http://www.biowerkzeug.com for your architecture ${ARCH} and operating
system ${OS}. "
fi

echo "Using executable ${HIPPO}"
 
TOPOLOGY=${HIPPO_DIR}/hippo_protein_database.dat
FF=${HIPPO_DIR}/oplsaa_forcefield.dat

echo "Setting up test directory"
rm -rf test
mkdir test
cd test

topdir="${CURDIR}/test"



function setup_hippo () {
  local numthreads=${1:-1}
  local input=hippo_input.txt
  cp ${HIPPO} ./hippo || return $?
  cp ${TOPOLOGY} .    || return $?
  cp ${FF} .          || return $?
  test -e $input || die "Missing run input file $input in $PWD"
  if [ $NSLOTS -gt 1 ]; then
      # adjusting for OpenMP run
      sed -i.orig -e "s/[[:space:]]*openMP numthreads.*/openMP numthreads                       ${numthreads}/" $input
  fi
  return 0 
}

function run_test () {
  local testdir="$1" numthreads="${2:-1}"
  echo "---------------------------------------------------------"
  cd ${testdir} || die "Cannot 'cd ${testdir}'"
  setup_hippo ${numthreads} || die "setup_hippo() failed"
  echo "Set up all files for NSLOTS=${numthreads}"
  echo "Running hippo test case ${testdir}..."
  t_start=$(date +%s)
  ./hippo
  t_stop=$(date +%s)
  delta_t=$(( t_stop-t_start ))
  echo "Completed hippo test case ${testdir} in ${delta_t} seconds, running ${numthreads} threads"
  echo "BENCHMARK: ${testdir} ${numthreads} ${delta_t}"
  cd  ${topdir}
}

cp -r ../jobs/* .


for t in ${RUN_TESTS};
 do run_test $t ${NSLOTS}
done

echo "Finished running hippo test suite"