1#!/usr/bin/env python 2import os 3from benchmarkExample import PETScExample 4 5def processSummary(moduleName, times, events): 6 '''Process the Python log summary into plot data''' 7 m = __import__(moduleName) 8 reload(m) 9 # Total Time 10 times.append(m.Time[0]) 11 # Common events 12 # Add the time and flop rate 13 for name in ['MatCUSPSetValBch', 'ElemAssembly']: 14 if not name in events: 15 events[name] = [] 16 events[name].append((m.Main_Stage.event[name].Time[0], m.Main_Stage.event[name].Flops[0]/(m.Main_Stage.event[name].Time[0] * 1e6))) 17 return 18 19def plotSummary(library, num, sizes, times, events): 20 from pylab import legend, plot, show, title, xlabel, ylabel 21 import numpy as np 22 showEventTime = True 23 print events 24 if showEventTime: 25 data = [] 26 names = [] 27 for event, style in [('MatCUSPSetValBch', 'b-'), ('ElemAssembly', 'b:')]: 28 names.append(event) 29 data.append(sizes) 30 data.append(np.array(events[event])[:,0]) 31 data.append(style) 32 plot(*data) 33 title('Performance on '+library+' Example '+str(num)) 34 xlabel('Number of Dof') 35 ylabel('Time (s)') 36 legend(names, 'upper left', shadow = True) 37 show() 38 return 39 40if __name__ == '__main__': 41 library = 'KSP' 42 num = 4 43 ex = PETScExample(library, num, log_summary_python='summary.py', preload='off') 44 sizes = [] 45 times = [] 46 events = {} 47 for n in [10, 20, 50, 100, 150, 200, 250, 300, 350]: 48 ex.run(da_grid_x=n, da_grid_y=n, cusp_synchronize=1) 49 sizes.append(n*n) 50 processSummary('summary', times, events) 51 plotSummary(library, num, sizes, times, events) 52