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]) 25 hosts[size] = fields[1:size+1] 26 triads[size] = float(fields[size+5].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))+" nodes" 49 ff.write("It appears you have "+str(len(ulasthosts))+" nodes\n") 50 51 testhosts = [] 52 for i in range(0,len(lasthosts)): 53 testhosts.append(ulasthosts[i % len(ulasthosts)]) 54 if testhosts == lasthosts: 55 print " distributed in a round robin order" 56 ff.write(" distributed in a round robin order\n") 57 else: 58 print " NOT distributed in a round robin order" 59 ff.write(" NOT distributed in a round robin order\n") 60 61 try: 62 import matplotlib 63 except: 64 print "Unable to open matplotlib to plot speedup" 65 return 66 67 try: 68 if fileoutput: matplotlib.use('Agg') 69 import matplotlib.pyplot as plt 70 except: 71 print "Unable to open matplotlib to plot speedup" 72 return 73 74 try: 75 fig, ax1 = plt.subplots() 76 plt.title('MPI Perfect and Streams Speedup') 77 ax2 = ax1.twinx() 78 ax1.set_autoscaley_on(False) 79 80 # make sure that actual bandwidth values (as opposed to perfect speedup) takes 81 # at least a third of the y axis 82 ymax = min(max(hosts.keys()), 3*max(triads.values())/min(triads.values()) - 2) 83 84 ax1.set_xlim([min(hosts.keys()),max(hosts.keys())]) 85 ax1.set_ylim([min(hosts.keys()),ymax]) 86 ax1.set_xlabel('Number of MPI processes') 87 ax1.set_ylabel('Memory Bandwidth Speedup') 88 ax1.plot(hosts.keys(),hosts.keys(),'b',hosts.keys(),speedups.values(),'r-o') 89 ax2.set_autoscaley_on(False) 90 ax2.set_xlim([min(hosts.keys()),max(hosts.keys())]) 91 ax2.set_ylim([min(triads.values())/1000.,min(triads.values())*ymax/1000.]) 92 ax2.set_ylabel("Achieved Bandwidth. Gigabytes per Second") 93 94 plt.show() 95 if fileoutput: plt.savefig('scaling.png') 96 if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png" 97 if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n") 98 except Exception, e: 99 if fileoutput: print "Unable to plot speedup to a file" 100 else: print "Unable to display speedup plot" 101 return 102 103 ff.close() 104 105# 106# 107if __name__ == '__main__': 108 import sys 109 process(len(sys.argv)-1) 110 111 112