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