1#!/usr/bin/env python 2#!/bin/env python 3# 4# Computers speed up of Streams benchmark results generated by make streams and plots 5# 6# matplotlib can switch between different backends hence this needs to be run 7# twice to first generate a file and then display a window 8# 9import os 10# 11def process(fileoutput = 1): 12 import re 13 ff = open('scaling.log') 14 data = ff.read() 15 ff.close() 16 17 hosts = {} 18 triads = {} 19 speedups = {} 20 match = data.split('Number of MPI processes ') 21 for i in match: 22 if i: 23 fields = i.split('\n') 24 size = int(fields[0].split()[0]) 25 hosts[size] = fields[0].split()[3:] 26 triads[size] = float(fields[1].split()[1]) 27 28 if len(hosts) < 2: return 29 30 ff = open('scaling.log','a') 31 if fileoutput: print 'np speedup' 32 if fileoutput: ff.write('np speedup\n') 33 for sizes in hosts: 34 speedups[sizes] = triads[sizes]/triads[1] 35 if fileoutput: print sizes,round(triads[sizes]/triads[1],2) 36 if fileoutput: ff.write(str(sizes)+' '+str(round(triads[sizes]/triads[1],2))+'\n') 37 38 if fileoutput: print "Estimation of possible speedup of MPI programs based on Streams benchmark." 39 if fileoutput: ff.write("Estimation of possible speedup of MPI programs based on Streams benchmark.\n") 40 41 if fileoutput: 42 import re 43 last = max(hosts.keys()) 44 lasthosts = hosts[last] 45 for i in range(0,len(lasthosts)): 46 lasthosts[i] = re.sub(r"Process [0-9]*", "", lasthosts[i]) 47 ulasthosts = list(set(lasthosts)) 48 print "It appears you have "+str(len(ulasthosts))+" node(s)" 49 ff.write("It appears you have "+str(len(ulasthosts))+" node(s)\n") 50 51 if len(ulasthosts) < 1: 52 testhosts = [] 53 for i in range(0,len(lasthosts)): 54 testhosts.append(ulasthosts[i % len(ulasthosts)]) 55 if testhosts == lasthosts: 56 print " distributed in a round robin order" 57 ff.write(" distributed in a round robin order\n") 58 else: 59 print " NOT distributed in a round robin order" 60 ff.write(" NOT distributed in a round robin order\n") 61 62 try: 63 import matplotlib 64 except: 65 print "Unable to open matplotlib to plot speedup" 66 return 67 68 try: 69 if fileoutput: matplotlib.use('Agg') 70 import matplotlib.pyplot as plt 71 except: 72 print "Unable to open matplotlib to plot speedup" 73 return 74 75 try: 76 fig, ax1 = plt.subplots() 77 plt.title('MPI Perfect and Streams Speedup') 78 ax2 = ax1.twinx() 79 ax1.set_autoscaley_on(False) 80 81 # make sure that actual bandwidth values (as opposed to perfect speedup) takes 82 # at least a third of the y axis 83 ymax = min(max(hosts.keys()), 3*max(triads.values())/min(triads.values()) - 2) 84 85 ax1.set_xlim([min(hosts.keys()),max(hosts.keys())]) 86 ax1.set_ylim([min(hosts.keys()),ymax]) 87 ax1.set_xlabel('Number of MPI processes') 88 ax1.set_ylabel('Memory Bandwidth Speedup') 89 ax1.plot(hosts.keys(),hosts.keys(),'b',hosts.keys(),speedups.values(),'r-o') 90 ax2.set_autoscaley_on(False) 91 ax2.set_xlim([min(hosts.keys()),max(hosts.keys())]) 92 ax2.set_ylim([min(triads.values())/1000.,min(triads.values())*ymax/1000.]) 93 ax2.set_ylabel("Achieved Bandwidth. Gigabytes per Second") 94 95 plt.show() 96 if fileoutput: plt.savefig('scaling.png') 97 if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png" 98 if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n") 99 except Exception, e: 100 if fileoutput: print "Unable to plot speedup to a file" 101 else: print "Unable to display speedup plot" 102 return 103 104 ff.close() 105 106# 107# 108if __name__ == '__main__': 109 import sys 110 process(len(sys.argv)-1) 111 112 113