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 28*293a2e3aSBarry Smith if len(hosts) < 2: return 29*293a2e3aSBarry Smith 30a6cca095SBarry Smith ff = open('scaling.log','a') 31a6cca095SBarry Smith if fileoutput: print 'np speedup' 32a6cca095SBarry Smith if fileoutput: ff.write('np speedup\n') 33d3ae85c4SBarry Smith for sizes in hosts: 34d3ae85c4SBarry Smith speedups[sizes] = triads[sizes]/triads[1] 35a6cca095SBarry Smith if fileoutput: print sizes,round(triads[sizes]/triads[1],2) 36a6cca095SBarry Smith if fileoutput: ff.write(str(sizes)+' '+str(round(triads[sizes]/triads[1],2))+'\n') 371df1832dSBarry Smith 381df1832dSBarry Smith if fileoutput: print "Estimation of possible speedup of MPI programs based on Streams benchmark." 391df1832dSBarry Smith if fileoutput: ff.write("Estimation of possible speedup of MPI programs based on Streams benchmark.\n") 401df1832dSBarry Smith 411df1832dSBarry Smith if fileoutput: 421df1832dSBarry Smith import re 431df1832dSBarry Smith last = max(hosts.keys()) 441df1832dSBarry Smith lasthosts = hosts[last] 451df1832dSBarry Smith for i in range(0,len(lasthosts)): 461df1832dSBarry Smith lasthosts[i] = re.sub(r"Process [0-9]*", "", lasthosts[i]) 471df1832dSBarry Smith ulasthosts = list(set(lasthosts)) 481df1832dSBarry Smith print "It appears you have "+str(len(ulasthosts))+" nodes" 491df1832dSBarry Smith ff.write("It appears you have "+str(len(ulasthosts))+" nodes\n") 501df1832dSBarry Smith 511df1832dSBarry Smith testhosts = [] 521df1832dSBarry Smith for i in range(0,len(lasthosts)): 531df1832dSBarry Smith testhosts.append(ulasthosts[i % len(ulasthosts)]) 541df1832dSBarry Smith if testhosts == lasthosts: 551df1832dSBarry Smith print " distributed in a round robin order" 561df1832dSBarry Smith ff.write(" distributed in a round robin order\n") 571df1832dSBarry Smith else: 581df1832dSBarry Smith print " NOT distributed in a round robin order" 591df1832dSBarry Smith ff.write(" NOT distributed in a round robin order\n") 60d3ae85c4SBarry Smith 61d3ae85c4SBarry Smith try: 62d3ae85c4SBarry Smith import matplotlib 63d3ae85c4SBarry Smith except: 646a90b735SBarry Smith print "Unable to open matplotlib to plot speedup" 65d3ae85c4SBarry Smith return 66d3ae85c4SBarry Smith 67d3ae85c4SBarry Smith try: 68a6cca095SBarry Smith if fileoutput: matplotlib.use('Agg') 69d3ae85c4SBarry Smith import matplotlib.pyplot as plt 706a90b735SBarry Smith except: 716a90b735SBarry Smith print "Unable to open matplotlib to plot speedup" 726a90b735SBarry Smith return 73d3ae85c4SBarry Smith 74182d2d36SBarry Smith try: 757137e648SBarry Smith fig, ax1 = plt.subplots() 767137e648SBarry Smith plt.title('MPI Perfect and Streams Speedup') 777137e648SBarry Smith ax2 = ax1.twinx() 787137e648SBarry Smith ax1.set_autoscaley_on(False) 798473a99dSBarry Smith 808473a99dSBarry Smith # make sure that actual bandwidth values (as opposed to perfect speedup) takes 818473a99dSBarry Smith # at least a third of the y axis 828473a99dSBarry Smith ymax = min(max(hosts.keys()), 3*max(triads.values())/min(triads.values()) - 2) 838473a99dSBarry Smith 847137e648SBarry Smith ax1.set_xlim([min(hosts.keys()),max(hosts.keys())]) 858473a99dSBarry Smith ax1.set_ylim([min(hosts.keys()),ymax]) 867137e648SBarry Smith ax1.set_xlabel('Number of MPI processes') 877137e648SBarry Smith ax1.set_ylabel('Memory Bandwidth Speedup') 88576f62e6SBarry Smith ax1.plot(hosts.keys(),hosts.keys(),'b',hosts.keys(),speedups.values(),'r-o') 897137e648SBarry Smith ax2.set_autoscaley_on(False) 907137e648SBarry Smith ax2.set_xlim([min(hosts.keys()),max(hosts.keys())]) 918473a99dSBarry Smith ax2.set_ylim([min(triads.values())/1000.,min(triads.values())*ymax/1000.]) 927137e648SBarry Smith ax2.set_ylabel("Achieved Bandwidth. Gigabytes per Second") 937137e648SBarry Smith 94d3ae85c4SBarry Smith plt.show() 95a6cca095SBarry Smith if fileoutput: plt.savefig('scaling.png') 961df1832dSBarry Smith if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png" 971df1832dSBarry Smith if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n") 988473a99dSBarry Smith except Exception, e: 99182d2d36SBarry Smith if fileoutput: print "Unable to plot speedup to a file" 100182d2d36SBarry Smith else: print "Unable to display speedup plot" 101182d2d36SBarry Smith return 102d3ae85c4SBarry Smith 1031df1832dSBarry Smith ff.close() 1041df1832dSBarry Smith 105d3ae85c4SBarry Smith# 106d3ae85c4SBarry Smith# 107d3ae85c4SBarry Smithif __name__ == '__main__': 108d3ae85c4SBarry Smith import sys 109a6cca095SBarry Smith process(len(sys.argv)-1) 110d3ae85c4SBarry Smith 111d3ae85c4SBarry Smith 112