xref: /petsc/src/benchmarks/streams/process.py (revision 34c645fd3b0199e05bec2fcc32d3597bfeb7f4f2)
1#!/usr/bin/env python3
2#
3#    Computers speed up of Streams benchmark results generated by make streams and plots
4#
5#    matplotlib can switch between different backends hence this needs to be run
6#    twice to first generate a file and then display a window
7#
8from __future__ import print_function
9import os
10#
11def process(streamstype,fileoutput):
12  import re
13
14  ff = open('scaling.log')
15  data = ff.read()
16  ff.close()
17
18  s = data.split('\n')
19  triads = {}
20  speedups = {}
21  size = 0
22  for i in s[0:-1]:
23      i = i.split()
24      triads[size] = float(i[1])
25      size = size + 1
26
27  if size < 2: return
28
29  triads = list(triads.values())
30  speedups = {}
31  for i in range(0,size):
32    speedups[i] = triads[i]/triads[0]
33
34  try:
35    import matplotlib
36  except:
37    print("Unable to open matplotlib to plot speedup")
38    return
39
40  try:
41    if fileoutput: matplotlib.use('Agg')
42    import matplotlib.pyplot as plt
43  except:
44    print("Unable to open matplotlib to plot speedup")
45    return
46
47  try:
48    fig, ax1 = plt.subplots()
49    plt.title(streamstype+' Perfect and Streams Speedup')
50    ax2 = ax1.twinx()
51    ax1.set_autoscaley_on(False)
52
53    r = range(1,size+1)
54    speedups = speedups.values()
55
56    # make sure that actual bandwidth values (as opposed to perfect speedup) takes
57    # at least a third of the y axis
58    ymax = min(size, 3*max(speedups))
59    ymin = min(1, min(speedups))
60    if ymin < 1: ymin = 0
61
62    ax1.set_xlim(1,size)
63    ax1.set_ylim([ymin,ymax])
64    ax1.set_xlabel('Number of processes/threads')
65    ax1.set_ylabel('Memory Bandwidth Speedup')
66    ax1.plot(r,r,'b',r,speedups,'r-o')
67    ax2.set_autoscaley_on(False)
68    ax2.set_xlim([1,size])
69    ax2.set_ylim([min(triads),max(triads)])
70    ax2.set_ylabel("Achieved Bandwidth. Megabytes per Second")
71    ax2.plot(r,triads,'g-o')
72
73    plt.show()
74    if fileoutput: plt.savefig(streamstype+'scaling.png')
75    if fileoutput: print("See graph in the file src/benchmarks/streams/"+streamstype+"scaling.png")
76  except Exception as e:
77    if fileoutput: print("Unable to plot speedup to a file")
78    else: print("Unable to display speedup plot")
79    return
80
81  ff.close()
82
83#
84#
85if __name__ ==  '__main__':
86  import sys
87
88  process(sys.argv[1],len(sys.argv)-2)
89
90
91