11b37a2a7SPierre Jolivet#!/usr/bin/env python3 2d3ae85c4SBarry Smith# 3a6cca095SBarry Smith# Computers speed up of Streams benchmark results generated by make streams and plots 4a6cca095SBarry Smith# 5a6cca095SBarry Smith# matplotlib can switch between different backends hence this needs to be run 6a6cca095SBarry Smith# twice to first generate a file and then display a window 7d3ae85c4SBarry Smith# 85b6bfdb9SJed Brownfrom __future__ import print_function 9d3ae85c4SBarry Smithimport os 10d3ae85c4SBarry Smith# 114198fb66SBarry Smithdef process(streamstype,fileoutput): 12d3ae85c4SBarry Smith import re 134198fb66SBarry Smith 14a6cca095SBarry Smith ff = open('scaling.log') 15d3ae85c4SBarry Smith data = ff.read() 16d3ae85c4SBarry Smith ff.close() 17d3ae85c4SBarry Smith 185e71baefSBarry Smith s = data.split('\n') 19*c6bff371SJunchao Zhang triads = {} # stream triad bandwidth data points 20d3ae85c4SBarry Smith speedups = {} 214198fb66SBarry Smith size = 0 224198fb66SBarry Smith for i in s[0:-1]: 234198fb66SBarry Smith i = i.split() 24*c6bff371SJunchao Zhang triads[size] = float(i[1])/1000 # MB/s to GB/s 254198fb66SBarry Smith size = size + 1 26d3ae85c4SBarry Smith 274198fb66SBarry Smith if size < 2: return 28293a2e3aSBarry Smith 29080f2f32SBarry Smith triads = list(triads.values()) 304198fb66SBarry Smith speedups = {} 314198fb66SBarry Smith for i in range(0,size): 324198fb66SBarry Smith speedups[i] = triads[i]/triads[0] 33d3ae85c4SBarry Smith 34d3ae85c4SBarry Smith try: 35d3ae85c4SBarry Smith import matplotlib 36*c6bff371SJunchao Zhang from matplotlib.ticker import MaxNLocator 37d3ae85c4SBarry Smith except: 385b6bfdb9SJed Brown print("Unable to open matplotlib to plot speedup") 39d3ae85c4SBarry Smith return 40d3ae85c4SBarry Smith 41d3ae85c4SBarry Smith try: 42a6cca095SBarry Smith if fileoutput: matplotlib.use('Agg') 43d3ae85c4SBarry Smith import matplotlib.pyplot as plt 446a90b735SBarry Smith except: 455b6bfdb9SJed Brown print("Unable to open matplotlib to plot speedup") 466a90b735SBarry Smith return 47d3ae85c4SBarry Smith 48182d2d36SBarry Smith try: 49a253b786SJosh Hope-Collins fig, ax1 = plt.subplots(layout='constrained') 504198fb66SBarry Smith plt.title(streamstype+' Perfect and Streams Speedup') 517137e648SBarry Smith ax2 = ax1.twinx() 527137e648SBarry Smith ax1.set_autoscaley_on(False) 538473a99dSBarry Smith 544198fb66SBarry Smith r = range(1,size+1) 554198fb66SBarry Smith speedups = speedups.values() 564198fb66SBarry Smith 578473a99dSBarry Smith # make sure that actual bandwidth values (as opposed to perfect speedup) takes 588473a99dSBarry Smith # at least a third of the y axis 594198fb66SBarry Smith ymax = min(size, 3*max(speedups)) 604198fb66SBarry Smith ymin = min(1, min(speedups)) 614198fb66SBarry Smith if ymin < 1: ymin = 0 628473a99dSBarry Smith 634198fb66SBarry Smith ax1.set_xlim(1,size) 64*c6bff371SJunchao Zhang ax1.xaxis.set_major_locator(MaxNLocator(integer=True)) 654198fb66SBarry Smith ax1.set_ylim([ymin,ymax]) 664198fb66SBarry Smith ax1.set_xlabel('Number of processes/threads') 67*c6bff371SJunchao Zhang ax1.set_ylabel('Achieved Speedup') 68a253b786SJosh Hope-Collins ax1.plot(r,r,'b',label='Ideal speedup') 69a253b786SJosh Hope-Collins ax1.plot(r,speedups,'r-o', label='Achieved speedup') 707137e648SBarry Smith ax2.set_autoscaley_on(False) 714198fb66SBarry Smith ax2.set_xlim([1,size]) 724198fb66SBarry Smith ax2.set_ylim([min(triads),max(triads)]) 73*c6bff371SJunchao Zhang ax2.set_ylabel("Achieved Bandwidth (GB/s)") 74a253b786SJosh Hope-Collins ax2.plot(r,triads,'g-o', label='Achieved bandwidth') 75a253b786SJosh Hope-Collins 76*c6bff371SJunchao Zhang lines1, labels1 = ax1.get_legend_handles_labels() 77*c6bff371SJunchao Zhang lines2, labels2 = ax2.get_legend_handles_labels() 78*c6bff371SJunchao Zhang ax1.legend(lines1 + lines2, labels1 + labels2, loc='best') 797137e648SBarry Smith 80d3ae85c4SBarry Smith plt.show() 814198fb66SBarry Smith if fileoutput: plt.savefig(streamstype+'scaling.png') 824198fb66SBarry Smith if fileoutput: print("See graph in the file src/benchmarks/streams/"+streamstype+"scaling.png") 835b6bfdb9SJed Brown except Exception as e: 845b6bfdb9SJed Brown if fileoutput: print("Unable to plot speedup to a file") 855b6bfdb9SJed Brown else: print("Unable to display speedup plot") 86182d2d36SBarry Smith return 87d3ae85c4SBarry Smith 881df1832dSBarry Smith ff.close() 891df1832dSBarry Smith 90*c6bff371SJunchao Zhang# plot bandwidth data in scaling.log under the current directory. 91d3ae85c4SBarry Smith# 92*c6bff371SJunchao Zhang# ./process.py arg1 arg2 93*c6bff371SJunchao Zhang# arg1: stream type, e.g., MPI, OpenMP, CUDA etc 94*c6bff371SJunchao Zhang# arg2: optional, can be anything, to indicate if a <stream type>scaling.png should be generated 95d3ae85c4SBarry Smithif __name__ == '__main__': 96d3ae85c4SBarry Smith import sys 974198fb66SBarry Smith 984198fb66SBarry Smith process(sys.argv[1],len(sys.argv)-2) 99