1d3ae85c4SBarry Smith#!/usr/bin/env python 2d3ae85c4SBarry Smith#!/bin/env python 3d3ae85c4SBarry Smith# 4*a6cca095SBarry Smith# Computers speed up of Streams benchmark results generated by make streams and plots 5*a6cca095SBarry Smith# 6*a6cca095SBarry Smith# matplotlib can switch between different backends hence this needs to be run 7*a6cca095SBarry Smith# twice to first generate a file and then display a window 8d3ae85c4SBarry Smith# 9d3ae85c4SBarry Smithimport os 10d3ae85c4SBarry Smith# 11*a6cca095SBarry Smithdef process(fileoutput = 1): 12d3ae85c4SBarry Smith import re 13*a6cca095SBarry Smith ff = open('scaling.log') 14d3ae85c4SBarry Smith data = ff.read() 15d3ae85c4SBarry Smith ff.close() 16d3ae85c4SBarry Smith 17d3ae85c4SBarry Smith hosts = {} 18d3ae85c4SBarry Smith triads = {} 19d3ae85c4SBarry Smith speedups = {} 20d3ae85c4SBarry Smith match = data.split('Number of MPI processes ') 21d3ae85c4SBarry Smith for i in match: 22d3ae85c4SBarry Smith if i: 23d3ae85c4SBarry Smith fields = i.split('\n') 24d3ae85c4SBarry Smith size = int(fields[0]) 25d3ae85c4SBarry Smith hosts[size] = fields[1:size+1] 26d3ae85c4SBarry Smith triads[size] = float(fields[size+5].split()[1]) 27d3ae85c4SBarry Smith 28*a6cca095SBarry Smith ff = open('scaling.log','a') 29*a6cca095SBarry Smith if fileoutput: print 'np speedup' 30*a6cca095SBarry Smith if fileoutput: ff.write('np speedup\n') 31d3ae85c4SBarry Smith for sizes in hosts: 32d3ae85c4SBarry Smith speedups[sizes] = triads[sizes]/triads[1] 33*a6cca095SBarry Smith if fileoutput: print sizes,round(triads[sizes]/triads[1],2) 34*a6cca095SBarry Smith if fileoutput: ff.write(str(sizes)+' '+str(round(triads[sizes]/triads[1],2))+'\n') 35d3ae85c4SBarry Smith ff.close() 36d3ae85c4SBarry Smith 37d3ae85c4SBarry Smith try: 38d3ae85c4SBarry Smith import matplotlib 39d3ae85c4SBarry Smith except: 406a90b735SBarry Smith print "Unable to open matplotlib to plot speedup" 41d3ae85c4SBarry Smith return 42d3ae85c4SBarry Smith 43d3ae85c4SBarry Smith try: 44*a6cca095SBarry Smith if fileoutput: matplotlib.use('Agg') 45d3ae85c4SBarry Smith import matplotlib.pyplot as plt 466a90b735SBarry Smith except: 476a90b735SBarry Smith print "Unable to open matplotlib to plot speedup" 486a90b735SBarry Smith return 49d3ae85c4SBarry Smith 506a90b735SBarry Smith try: 51d3ae85c4SBarry Smith plt.title('Perfect and Streams Speedup') 52d3ae85c4SBarry Smith plt.plot(hosts.keys(),hosts.keys(),'b-o',hosts.keys(),speedups.values(),'r-o') 53d3ae85c4SBarry Smith plt.show() 54*a6cca095SBarry Smith if fileoutput: plt.savefig('scaling.png') 556a90b735SBarry Smith except: 56*a6cca095SBarry Smith if fileoutput: print "Unable to plot speedup to a file" 57*a6cca095SBarry Smith else: print "Unable to display speedup plot" 586a90b735SBarry Smith return 59d3ae85c4SBarry Smith 60d3ae85c4SBarry Smith# 61d3ae85c4SBarry Smith# 62d3ae85c4SBarry Smithif __name__ == '__main__': 63d3ae85c4SBarry Smith import sys 64*a6cca095SBarry Smith process(len(sys.argv)-1) 65d3ae85c4SBarry Smith 66d3ae85c4SBarry Smith 67