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 if 1: 45 sizes = [] 46 times = [] 47 events = {} 48 for n in [10, 20, 50, 100, 150, 200, 250, 300, 350]: 49 ex.run(da_grid_x=n, da_grid_y=n, cusp_synchronize=1) 50 sizes.append(n*n) 51 processSummary('summary', times, events) 52 plotSummary(library, num, sizes, times, events) 53 else: 54 times = [] 55 sizes = [] 56 for n in range(150, 1350, 100): 57 sizes.append(n*n) 58 baconostEvents = {'ElemAssembly': [(0.040919999999999998, 0.0), (0.1242, 0.0), (0.24410000000000001, 0.0), (0.374, 0.0), (0.56259999999999999, 0.0), (0.79049999999999998, 0.0), (1.0880000000000001, 0.0), (1.351, 0.0), (1.6930000000000001, 0.0), (2.0609999999999999, 0.0), (2.4820000000000002, 0.0), (3.0640000000000001, 0.0)], 'MatCUSPSetValBch': [(0.0123, 0.0), (0.023429999999999999, 0.0), (0.043540000000000002, 0.0), (0.06608, 0.0), (0.09579, 0.0), (0.12920000000000001, 0.0), (0.17169999999999999, 0.0), (0.2172, 0.0), (0.27179999999999999, 0.0), (0.48309999999999997, 0.0), (0.44180000000000003, 0.0), (0.51529999999999998, 0.0)]} 59 plotSummary(library, num, sizes, times, baconostEvents) 60