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 17*5e71baefSBarry Smith s = data.split('\n') 18*5e71baefSBarry Smith ss = [] 19*5e71baefSBarry Smith for i in s: 20*5e71baefSBarry Smith if not i.startswith('MPI rank'): 21*5e71baefSBarry Smith ss.append(i) 22*5e71baefSBarry Smith data = '\n'.join(ss) 23d3ae85c4SBarry Smith hosts = {} 24d3ae85c4SBarry Smith triads = {} 25d3ae85c4SBarry Smith speedups = {} 26d3ae85c4SBarry Smith match = data.split('Number of MPI processes ') 27d3ae85c4SBarry Smith for i in match: 28d3ae85c4SBarry Smith if i: 29d3ae85c4SBarry Smith fields = i.split('\n') 30436f0324SBarry Smith size = int(fields[0].split()[0]) 31436f0324SBarry Smith hosts[size] = fields[0].split()[3:] 32436f0324SBarry Smith triads[size] = float(fields[1].split()[1]) 33d3ae85c4SBarry Smith 34293a2e3aSBarry Smith if len(hosts) < 2: return 35293a2e3aSBarry Smith 36a6cca095SBarry Smith ff = open('scaling.log','a') 37a6cca095SBarry Smith if fileoutput: print 'np speedup' 38a6cca095SBarry Smith if fileoutput: ff.write('np speedup\n') 39d3ae85c4SBarry Smith for sizes in hosts: 40d3ae85c4SBarry Smith speedups[sizes] = triads[sizes]/triads[1] 41a6cca095SBarry Smith if fileoutput: print sizes,round(triads[sizes]/triads[1],2) 42a6cca095SBarry Smith if fileoutput: ff.write(str(sizes)+' '+str(round(triads[sizes]/triads[1],2))+'\n') 431df1832dSBarry Smith 441df1832dSBarry Smith if fileoutput: print "Estimation of possible speedup of MPI programs based on Streams benchmark." 451df1832dSBarry Smith if fileoutput: ff.write("Estimation of possible speedup of MPI programs based on Streams benchmark.\n") 461df1832dSBarry Smith 471df1832dSBarry Smith if fileoutput: 481df1832dSBarry Smith import re 491df1832dSBarry Smith last = max(hosts.keys()) 501df1832dSBarry Smith lasthosts = hosts[last] 511df1832dSBarry Smith for i in range(0,len(lasthosts)): 521df1832dSBarry Smith lasthosts[i] = re.sub(r"Process [0-9]*", "", lasthosts[i]) 531df1832dSBarry Smith ulasthosts = list(set(lasthosts)) 5419623ac0SBarry Smith print "It appears you have "+str(len(ulasthosts))+" node(s)" 5519623ac0SBarry Smith ff.write("It appears you have "+str(len(ulasthosts))+" node(s)\n") 561df1832dSBarry Smith 5719623ac0SBarry Smith if len(ulasthosts) < 1: 581df1832dSBarry Smith testhosts = [] 591df1832dSBarry Smith for i in range(0,len(lasthosts)): 601df1832dSBarry Smith testhosts.append(ulasthosts[i % len(ulasthosts)]) 611df1832dSBarry Smith if testhosts == lasthosts: 621df1832dSBarry Smith print " distributed in a round robin order" 631df1832dSBarry Smith ff.write(" distributed in a round robin order\n") 641df1832dSBarry Smith else: 651df1832dSBarry Smith print " NOT distributed in a round robin order" 661df1832dSBarry Smith ff.write(" NOT distributed in a round robin order\n") 67d3ae85c4SBarry Smith 68d3ae85c4SBarry Smith try: 69d3ae85c4SBarry Smith import matplotlib 70d3ae85c4SBarry Smith except: 716a90b735SBarry Smith print "Unable to open matplotlib to plot speedup" 72d3ae85c4SBarry Smith return 73d3ae85c4SBarry Smith 74d3ae85c4SBarry Smith try: 75a6cca095SBarry Smith if fileoutput: matplotlib.use('Agg') 76d3ae85c4SBarry Smith import matplotlib.pyplot as plt 776a90b735SBarry Smith except: 786a90b735SBarry Smith print "Unable to open matplotlib to plot speedup" 796a90b735SBarry Smith return 80d3ae85c4SBarry Smith 81182d2d36SBarry Smith try: 827137e648SBarry Smith fig, ax1 = plt.subplots() 837137e648SBarry Smith plt.title('MPI Perfect and Streams Speedup') 847137e648SBarry Smith ax2 = ax1.twinx() 857137e648SBarry Smith ax1.set_autoscaley_on(False) 868473a99dSBarry Smith 878473a99dSBarry Smith # make sure that actual bandwidth values (as opposed to perfect speedup) takes 888473a99dSBarry Smith # at least a third of the y axis 898473a99dSBarry Smith ymax = min(max(hosts.keys()), 3*max(triads.values())/min(triads.values()) - 2) 908473a99dSBarry Smith 917137e648SBarry Smith ax1.set_xlim([min(hosts.keys()),max(hosts.keys())]) 928473a99dSBarry Smith ax1.set_ylim([min(hosts.keys()),ymax]) 937137e648SBarry Smith ax1.set_xlabel('Number of MPI processes') 947137e648SBarry Smith ax1.set_ylabel('Memory Bandwidth Speedup') 95576f62e6SBarry Smith ax1.plot(hosts.keys(),hosts.keys(),'b',hosts.keys(),speedups.values(),'r-o') 967137e648SBarry Smith ax2.set_autoscaley_on(False) 977137e648SBarry Smith ax2.set_xlim([min(hosts.keys()),max(hosts.keys())]) 988473a99dSBarry Smith ax2.set_ylim([min(triads.values())/1000.,min(triads.values())*ymax/1000.]) 997137e648SBarry Smith ax2.set_ylabel("Achieved Bandwidth. Gigabytes per Second") 1007137e648SBarry Smith 101d3ae85c4SBarry Smith plt.show() 102a6cca095SBarry Smith if fileoutput: plt.savefig('scaling.png') 1031df1832dSBarry Smith if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png" 1041df1832dSBarry Smith if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n") 1058473a99dSBarry Smith except Exception, e: 106182d2d36SBarry Smith if fileoutput: print "Unable to plot speedup to a file" 107182d2d36SBarry Smith else: print "Unable to display speedup plot" 108182d2d36SBarry Smith return 109d3ae85c4SBarry Smith 1101df1832dSBarry Smith ff.close() 1111df1832dSBarry Smith 112d3ae85c4SBarry Smith# 113d3ae85c4SBarry Smith# 114d3ae85c4SBarry Smithif __name__ == '__main__': 115d3ae85c4SBarry Smith import sys 116a6cca095SBarry Smith process(len(sys.argv)-1) 117d3ae85c4SBarry Smith 118d3ae85c4SBarry Smith 119