Skip to content

Instantly share code, notes, and snippets.

@sanromd
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanromd/9261a73d967fcb3debc7 to your computer and use it in GitHub Desktop.
Save sanromd/9261a73d967fcb3debc7 to your computer and use it in GitHub Desktop.
pyclaw_profiler.py
#!/usr/bin/env python
# This code is originally taken from
# http://matplotlib.sourceforge.net/mpl_examples/pylab_examples/table_demo.py
# It is modified here to generate the required plot.
# This code was originally developed by Amal AlGhamdi
import matplotlib
from matplotlib import pyplot
import os
from pylab import *
from matplotlib.colors import colorConverter
params = {'backend': 'ps',
'axes.labelsize': 10,
'text.fontsize': 10,
'legend.fontsize': 10,
'xtick.labelsize': 8,
'ytick.labelsize': 8,
'text.usetex': True,}
rcParams.update(params)
#Some simple functions to generate colours.
def pastel(colour, weight=2.4):
""" Convert colour into a nice pastel shade"""
rgb = asarray(colorConverter.to_rgb(colour))
# scale colour
maxc = max(rgb)
if maxc < 1.0 and maxc > 0:
# scale colour
scale = 1.0 / maxc
rgb = rgb * scale
# now decrease saturation
total = sum(rgb)
slack = 0
for x in rgb:
slack += 1.0 - x
# want to increase weight from total to weight
# pick x s.t. slack * x == weight - total
# x = (weight - total) / slack
x = (weight - total) / slack
rgb = [c + (x * (1.0-c)) for c in rgb]
return rgb
def get_colours(n):
""" Return n pastel colours. """
base = asarray([[1,0,0], [0,1,0], [0,0,1]])
if n <= 3:
return base[0:n]
# how many new colours to we need to insert between
# red and green and between green and blue?
needed = (((n - 3) + 1) / 2, (n - 3) / 2)
colours = []
for start in (0, 1):
for x in linspace(0, 1-(1.0/(needed[start]+1)), needed[start]+1):
colours.append((base[start] * (1.0 - x)) +
(base[start+1] * x))
colours.append([0,0,1])
return [pastel(c) for c in colours[0:n]]
axes([0.35, 0.25, 0.55, 0.35]) # leave room below the axes for the table
import pstats
cflReduce = []
parallelInit = []
globalToLocal = []
evolveToTime = []
serialComputations = []
colLabels = []
setup = []
dqHyperbolic=[]
stats_dir = './scalingwprof_3d_sharpclaw'
nproc = 0
for n in range(1,5):
p = pstats.Stats(os.path.join(stats_dir,'statst_'+str(2**(3*n))+'_'+str(2**(6+n))+'_'+str(nproc)))
prof = {}
for x in p.stats:
prof[x[2]] = p.stats[x]
cflReduce.append(round(prof["<method 'max' of 'petsc4py.PETSc.Vec' objects>"][3],1))
parallelInit.append(round(prof["<method 'create' of 'petsc4py.PETSc.DA' objects>"][3],1))
dqHyperbolic.append(round(prof["dq_hyperbolic"][3],1))
globalToLocal.append(round(prof["<method 'globalToLocal' of 'petsc4py.PETSc.DM' objects>"][3],1))
evolveToTime.append(round(prof["evolve_to_time"][3],1))
setup.append(round(prof["setup"][3],1))
colLabels.append(str(2**(3*n)))
serialComputations =[ evolveToTime[i]- cflReduce[i]- globalToLocal[i] for i in range(len(evolveToTime))]
data = [ cflReduce , parallelInit , dqHyperbolic , globalToLocal , serialComputations ]
rowLabels = ['CFL Reduce', 'Parallel Initialization', 'dqHyperbolic', 'Global to Local', 'Concurrent Computations']
# Get some pastel shades for the colours
colours = get_colours(len(rowLabels))
print colours
rows = len(data)
ind = arange(len(colLabels)) + 0.3 # the x locations for the groups
cellText = []
width = 0.4 # the width of the bars
yoff = array([0.0] * len(colLabels)) # the bottom values for stacked bar chart
for row in xrange(rows):
bar(ind, data[rows-row-1], width, bottom=yoff, color=colours[rows-row-1], linewidth=0)
yoff = yoff + data[rows-row-1]
cellText = data
# Add total efficiency to the data
data.append( [sum([row[i] for row in data]) for i in range(len(colLabels))])
data[-1] = data[-1][0]/data[-1]
data[-1] = [round(x,2) for x in data [-1]]
rowLabels.append('Total Efficiency')
colours.append([1,1,1])
# Add a table at the bottom of the axes
mytable = table(cellText=cellText,
rowLabels=rowLabels, rowColours=colours,
colLabels=colLabels,
loc='bottom').set_fontsize(8)
ylabel('Execution Time for Process '+ str(nproc)+' (s)')
figtext(.5, .02, "Number of Cores", fontsize=10)
vals = arange(0, 36, 5)
yticks(vals, ['%d' % val for val in vals])
xticks([])
draw()
f=gcf()
f.set_figheight(5)
f.set_figwidth(5)
savefig(os.path.join(stats_dir,'acoustics_weak_scaling.pdf'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment