Test scaling.py
From Biowerkzeug Wiki
Jump to navigationJump to search
Python script that uses calc_testjobs_linux.sh to benchmark scaling using the walp_octane_NPT_sp_MD test case. See Talk:Performance#Scaling for details.
#!/usr/bin/env python
# $Id: test_scaling.py 2534 2008-12-07 15:59:59Z www-data $
# Testing scaling of hippo
# Copyright (c) 2008 Biowerkzeug
# Oliver Beckstein <orbeckst@gmail.com>
from subprocess import Popen,PIPE
import sys,re
calc_test_jobs = '/home/oliver/Library/Hippo/Benchmark/calc_testjobs_linux.sh'
hippo_test_case = 'walp_octane_NPT_sp_MD'
filename = "scaling.xvg"
figname = "scaling.png"
try:
maxslots = int(sys.argv[1])
except:
print "usage: %s NSLOTS" % sys.argv[0]
sys.exit(1)
slotrange = (1,maxslots+1) # <--- 1-4 !!
benchmark_pattern = re.compile(r'BENCHMARK:\s*(\w+)\s+(?P<NUMTHREADS>[0-9]+)\s+(?P<T_SECONDS>[0-9.]+)')
runtime = {}
out = open(filename,'w')
out.write("# scaling for Hippo\n# numthreads walltime/s scaling\n")
for NSLOTS in xrange(*slotrange):
print "-- running NSLOTS = %(NSLOTS)d" % vars()
p1 = Popen([calc_test_jobs, '-n', str(NSLOTS), hippo_test_case],stdout=PIPE)
p2 = Popen(['grep','BENCHMARK:'],stdin=p1.stdout,stdout=PIPE)
output = p2.communicate()[0]
m = benchmark_pattern.match(output)
print "output: ",output,
if not m:
print "ERROR: no benchmark data found"
continue
numthreads = int(m.group('NUMTHREADS'))
walltime = float(m.group('T_SECONDS'))
runtime[numthreads] = walltime
scaling = runtime[1]/walltime # runtime[1] is known after the first iteration!
out.write("%(numthreads)d %(walltime)f %(scaling)f\n" % vars())
out.close()
# Analysis
import numpy
import pylab
N = numpy.sort(runtime.keys())
T = numpy.array([runtime[n] for n in N],dtype=float)
S = T[0]/T
pylab.clf()
pylab.subplot(211)
pylab.title('Hippo test case: '+hippo_test_case)
pylab.xlabel('cpus')
pylab.ylabel('walltime/s')
pylab.plot(N,T,'ro-')
pylab.subplot(212)
pylab.xlabel('cpus')
pylab.ylabel('scaling')
pylab.plot(N,S,'ro-')
pylab.plot([N[0],N[-1]], [1,N[-1]], 'k--')
pylab.savefig(figname)
print "Saved figure "+figname