xref: /petsc/src/benchmarks/streams/process.py (revision 080f2f3202a4378b3da8ab0449daef3a82a55a5b)
1d3ae85c4SBarry Smith#!/usr/bin/env python
2d3ae85c4SBarry Smith#!/bin/env python
3d3ae85c4SBarry Smith#
4a6cca095SBarry Smith#    Computers speed up of Streams benchmark results generated by make streams and plots
5a6cca095SBarry Smith#
6a6cca095SBarry Smith#    matplotlib can switch between different backends hence this needs to be run
7a6cca095SBarry Smith#    twice to first generate a file and then display a window
8d3ae85c4SBarry Smith#
95b6bfdb9SJed Brownfrom __future__ import print_function
10d3ae85c4SBarry Smithimport os
11d3ae85c4SBarry Smith#
124198fb66SBarry Smithdef process(streamstype,fileoutput):
13d3ae85c4SBarry Smith  import re
144198fb66SBarry Smith
15a6cca095SBarry Smith  ff = open('scaling.log')
16d3ae85c4SBarry Smith  data = ff.read()
17d3ae85c4SBarry Smith  ff.close()
18d3ae85c4SBarry Smith
195e71baefSBarry Smith  s = data.split('\n')
20d3ae85c4SBarry Smith  triads = {}
21d3ae85c4SBarry Smith  speedups = {}
224198fb66SBarry Smith  size = 0
234198fb66SBarry Smith  for i in s[0:-1]:
244198fb66SBarry Smith      i = i.split()
254198fb66SBarry Smith      triads[size] = float(i[1])
264198fb66SBarry Smith      size = size + 1
27d3ae85c4SBarry Smith
284198fb66SBarry Smith  if size < 2: return
29293a2e3aSBarry Smith
30*080f2f32SBarry Smith  triads = list(triads.values())
314198fb66SBarry Smith  speedups = {}
324198fb66SBarry Smith  for i in range(0,size):
334198fb66SBarry Smith    speedups[i] = triads[i]/triads[0]
34d3ae85c4SBarry Smith
35d3ae85c4SBarry Smith  try:
36d3ae85c4SBarry Smith    import matplotlib
37d3ae85c4SBarry Smith  except:
385b6bfdb9SJed Brown    print("Unable to open matplotlib to plot speedup")
39d3ae85c4SBarry Smith    return
40d3ae85c4SBarry Smith
41d3ae85c4SBarry Smith  try:
42a6cca095SBarry Smith    if fileoutput: matplotlib.use('Agg')
43d3ae85c4SBarry Smith    import matplotlib.pyplot as plt
446a90b735SBarry Smith  except:
455b6bfdb9SJed Brown    print("Unable to open matplotlib to plot speedup")
466a90b735SBarry Smith    return
47d3ae85c4SBarry Smith
48182d2d36SBarry Smith  try:
497137e648SBarry Smith    fig, ax1 = plt.subplots()
504198fb66SBarry Smith    plt.title(streamstype+' Perfect and Streams Speedup')
517137e648SBarry Smith    ax2 = ax1.twinx()
527137e648SBarry Smith    ax1.set_autoscaley_on(False)
538473a99dSBarry Smith
544198fb66SBarry Smith    r = range(1,size+1)
554198fb66SBarry Smith    speedups = speedups.values()
564198fb66SBarry Smith
578473a99dSBarry Smith    # make sure that actual bandwidth values (as opposed to perfect speedup) takes
588473a99dSBarry Smith    # at least a third of the y axis
594198fb66SBarry Smith    ymax = min(size, 3*max(speedups))
604198fb66SBarry Smith    ymin = min(1, min(speedups))
614198fb66SBarry Smith    if ymin < 1: ymin = 0
628473a99dSBarry Smith
634198fb66SBarry Smith    ax1.set_xlim(1,size)
644198fb66SBarry Smith    ax1.set_ylim([ymin,ymax])
654198fb66SBarry Smith    ax1.set_xlabel('Number of processes/threads')
667137e648SBarry Smith    ax1.set_ylabel('Memory Bandwidth Speedup')
674198fb66SBarry Smith    ax1.plot(r,r,'b',r,speedups,'r-o')
687137e648SBarry Smith    ax2.set_autoscaley_on(False)
694198fb66SBarry Smith    ax2.set_xlim([1,size])
704198fb66SBarry Smith    ax2.set_ylim([min(triads),max(triads)])
714198fb66SBarry Smith    ax2.set_ylabel("Achieved Bandwidth. Megabytes per Second")
724198fb66SBarry Smith    ax2.plot(r,triads,'g-o')
737137e648SBarry Smith
74d3ae85c4SBarry Smith    plt.show()
754198fb66SBarry Smith    if fileoutput: plt.savefig(streamstype+'scaling.png')
764198fb66SBarry Smith    if fileoutput: print("See graph in the file src/benchmarks/streams/"+streamstype+"scaling.png")
775b6bfdb9SJed Brown  except Exception as e:
785b6bfdb9SJed Brown    if fileoutput: print("Unable to plot speedup to a file")
795b6bfdb9SJed Brown    else: print("Unable to display speedup plot")
80182d2d36SBarry Smith    return
81d3ae85c4SBarry Smith
821df1832dSBarry Smith  ff.close()
831df1832dSBarry Smith
84d3ae85c4SBarry Smith#
85d3ae85c4SBarry Smith#
86d3ae85c4SBarry Smithif __name__ ==  '__main__':
87d3ae85c4SBarry Smith  import sys
884198fb66SBarry Smith
894198fb66SBarry Smith  process(sys.argv[1],len(sys.argv)-2)
90d3ae85c4SBarry Smith
91d3ae85c4SBarry Smith
92