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