1#!/usr/bin/env python 2#!/bin/env python 3# 4# Computers speed up of Streams benchmark results generated by make streams and plots 5# 6# matplotlib can switch between different backends hence this needs to be run 7# twice to first generate a file and then display a window 8# 9from __future__ import print_function 10import os 11# 12def process(streamstype,fileoutput): 13 import re 14 15 ff = open('scaling.log') 16 data = ff.read() 17 ff.close() 18 19 s = data.split('\n') 20 triads = {} 21 speedups = {} 22 size = 0 23 for i in s[0:-1]: 24 i = i.split() 25 triads[size] = float(i[1]) 26 size = size + 1 27 28 if size < 2: return 29 30 triads = list(triads.values()) 31 speedups = {} 32 for i in range(0,size): 33 speedups[i] = triads[i]/triads[0] 34 35 try: 36 import matplotlib 37 except: 38 print("Unable to open matplotlib to plot speedup") 39 return 40 41 try: 42 if fileoutput: matplotlib.use('Agg') 43 import matplotlib.pyplot as plt 44 except: 45 print("Unable to open matplotlib to plot speedup") 46 return 47 48 try: 49 fig, ax1 = plt.subplots() 50 plt.title(streamstype+' Perfect and Streams Speedup') 51 ax2 = ax1.twinx() 52 ax1.set_autoscaley_on(False) 53 54 r = range(1,size+1) 55 speedups = speedups.values() 56 57 # make sure that actual bandwidth values (as opposed to perfect speedup) takes 58 # at least a third of the y axis 59 ymax = min(size, 3*max(speedups)) 60 ymin = min(1, min(speedups)) 61 if ymin < 1: ymin = 0 62 63 ax1.set_xlim(1,size) 64 ax1.set_ylim([ymin,ymax]) 65 ax1.set_xlabel('Number of processes/threads') 66 ax1.set_ylabel('Memory Bandwidth Speedup') 67 ax1.plot(r,r,'b',r,speedups,'r-o') 68 ax2.set_autoscaley_on(False) 69 ax2.set_xlim([1,size]) 70 ax2.set_ylim([min(triads),max(triads)]) 71 ax2.set_ylabel("Achieved Bandwidth. Megabytes per Second") 72 ax2.plot(r,triads,'g-o') 73 74 plt.show() 75 if fileoutput: plt.savefig(streamstype+'scaling.png') 76 if fileoutput: print("See graph in the file src/benchmarks/streams/"+streamstype+"scaling.png") 77 except Exception as e: 78 if fileoutput: print("Unable to plot speedup to a file") 79 else: print("Unable to display speedup plot") 80 return 81 82 ff.close() 83 84# 85# 86if __name__ == '__main__': 87 import sys 88 89 process(sys.argv[1],len(sys.argv)-2) 90 91 92