1d3ae85c4SBarry Smith#!/usr/bin/env python 2d3ae85c4SBarry Smith#!/bin/env python 3d3ae85c4SBarry Smith# 4a6cca095SBarry Smith# Computers speed up of Streams benchmark results generated by make streams and plots 5a6cca095SBarry Smith# 6a6cca095SBarry Smith# matplotlib can switch between different backends hence this needs to be run 7a6cca095SBarry Smith# twice to first generate a file and then display a window 8d3ae85c4SBarry Smith# 9d3ae85c4SBarry Smithimport os 10d3ae85c4SBarry Smith# 11a6cca095SBarry Smithdef process(fileoutput = 1): 12d3ae85c4SBarry Smith import re 13a6cca095SBarry 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 28a6cca095SBarry Smith ff = open('scaling.log','a') 29a6cca095SBarry Smith if fileoutput: print 'np speedup' 30a6cca095SBarry Smith if fileoutput: ff.write('np speedup\n') 31d3ae85c4SBarry Smith for sizes in hosts: 32d3ae85c4SBarry Smith speedups[sizes] = triads[sizes]/triads[1] 33a6cca095SBarry Smith if fileoutput: print sizes,round(triads[sizes]/triads[1],2) 34a6cca095SBarry Smith if fileoutput: ff.write(str(sizes)+' '+str(round(triads[sizes]/triads[1],2))+'\n') 35*1df1832dSBarry Smith 36*1df1832dSBarry Smith if fileoutput: print "Estimation of possible speedup of MPI programs based on Streams benchmark." 37*1df1832dSBarry Smith if fileoutput: ff.write("Estimation of possible speedup of MPI programs based on Streams benchmark.\n") 38*1df1832dSBarry Smith 39*1df1832dSBarry Smith if fileoutput: 40*1df1832dSBarry Smith import re 41*1df1832dSBarry Smith last = max(hosts.keys()) 42*1df1832dSBarry Smith lasthosts = hosts[last] 43*1df1832dSBarry Smith for i in range(0,len(lasthosts)): 44*1df1832dSBarry Smith lasthosts[i] = re.sub(r"Process [0-9]*", "", lasthosts[i]) 45*1df1832dSBarry Smith ulasthosts = list(set(lasthosts)) 46*1df1832dSBarry Smith print "It appears you have "+str(len(ulasthosts))+" nodes" 47*1df1832dSBarry Smith ff.write("It appears you have "+str(len(ulasthosts))+" nodes\n") 48*1df1832dSBarry Smith 49*1df1832dSBarry Smith testhosts = [] 50*1df1832dSBarry Smith for i in range(0,len(lasthosts)): 51*1df1832dSBarry Smith testhosts.append(ulasthosts[i % len(ulasthosts)]) 52*1df1832dSBarry Smith if testhosts == lasthosts: 53*1df1832dSBarry Smith print " distributed in a round robin order" 54*1df1832dSBarry Smith ff.write(" distributed in a round robin order\n") 55*1df1832dSBarry Smith else: 56*1df1832dSBarry Smith print " NOT distributed in a round robin order" 57*1df1832dSBarry Smith ff.write(" NOT distributed in a round robin order\n") 58d3ae85c4SBarry Smith 59d3ae85c4SBarry Smith try: 60d3ae85c4SBarry Smith import matplotlib 61d3ae85c4SBarry Smith except: 626a90b735SBarry Smith print "Unable to open matplotlib to plot speedup" 63d3ae85c4SBarry Smith return 64d3ae85c4SBarry Smith 65d3ae85c4SBarry Smith try: 66a6cca095SBarry Smith if fileoutput: matplotlib.use('Agg') 67d3ae85c4SBarry Smith import matplotlib.pyplot as plt 686a90b735SBarry Smith except: 696a90b735SBarry Smith print "Unable to open matplotlib to plot speedup" 706a90b735SBarry Smith return 71d3ae85c4SBarry Smith 726a90b735SBarry Smith try: 73d3ae85c4SBarry Smith plt.title('Perfect and Streams Speedup') 74d3ae85c4SBarry Smith plt.plot(hosts.keys(),hosts.keys(),'b-o',hosts.keys(),speedups.values(),'r-o') 75d3ae85c4SBarry Smith plt.show() 76a6cca095SBarry Smith if fileoutput: plt.savefig('scaling.png') 77*1df1832dSBarry Smith if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png" 78*1df1832dSBarry Smith if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n") 796a90b735SBarry Smith except: 80a6cca095SBarry Smith if fileoutput: print "Unable to plot speedup to a file" 81a6cca095SBarry Smith else: print "Unable to display speedup plot" 826a90b735SBarry Smith return 83d3ae85c4SBarry Smith 84*1df1832dSBarry Smith ff.close() 85*1df1832dSBarry Smith 86d3ae85c4SBarry Smith# 87d3ae85c4SBarry Smith# 88d3ae85c4SBarry Smithif __name__ == '__main__': 89d3ae85c4SBarry Smith import sys 90a6cca095SBarry Smith process(len(sys.argv)-1) 91d3ae85c4SBarry Smith 92d3ae85c4SBarry Smith 93