xref: /petsc/src/benchmarks/streams/process.py (revision 1b37a2a7cc4a4fb30c3e967db1c694c0a1013f51)
1*1b37a2a7SPierre Jolivet#!/usr/bin/env python3
2d3ae85c4SBarry Smith#
3a6cca095SBarry Smith#    Computers speed up of Streams benchmark results generated by make streams and plots
4a6cca095SBarry Smith#
5a6cca095SBarry Smith#    matplotlib can switch between different backends hence this needs to be run
6a6cca095SBarry Smith#    twice to first generate a file and then display a window
7d3ae85c4SBarry Smith#
85b6bfdb9SJed Brownfrom __future__ import print_function
9d3ae85c4SBarry Smithimport os
10d3ae85c4SBarry Smith#
114198fb66SBarry Smithdef process(streamstype,fileoutput):
12d3ae85c4SBarry Smith  import re
134198fb66SBarry Smith
14a6cca095SBarry Smith  ff = open('scaling.log')
15d3ae85c4SBarry Smith  data = ff.read()
16d3ae85c4SBarry Smith  ff.close()
17d3ae85c4SBarry Smith
185e71baefSBarry Smith  s = data.split('\n')
19d3ae85c4SBarry Smith  triads = {}
20d3ae85c4SBarry Smith  speedups = {}
214198fb66SBarry Smith  size = 0
224198fb66SBarry Smith  for i in s[0:-1]:
234198fb66SBarry Smith      i = i.split()
244198fb66SBarry Smith      triads[size] = float(i[1])
254198fb66SBarry Smith      size = size + 1
26d3ae85c4SBarry Smith
274198fb66SBarry Smith  if size < 2: return
28293a2e3aSBarry Smith
29080f2f32SBarry Smith  triads = list(triads.values())
304198fb66SBarry Smith  speedups = {}
314198fb66SBarry Smith  for i in range(0,size):
324198fb66SBarry Smith    speedups[i] = triads[i]/triads[0]
33d3ae85c4SBarry Smith
34d3ae85c4SBarry Smith  try:
35d3ae85c4SBarry Smith    import matplotlib
36d3ae85c4SBarry Smith  except:
375b6bfdb9SJed Brown    print("Unable to open matplotlib to plot speedup")
38d3ae85c4SBarry Smith    return
39d3ae85c4SBarry Smith
40d3ae85c4SBarry Smith  try:
41a6cca095SBarry Smith    if fileoutput: matplotlib.use('Agg')
42d3ae85c4SBarry Smith    import matplotlib.pyplot as plt
436a90b735SBarry Smith  except:
445b6bfdb9SJed Brown    print("Unable to open matplotlib to plot speedup")
456a90b735SBarry Smith    return
46d3ae85c4SBarry Smith
47182d2d36SBarry Smith  try:
487137e648SBarry Smith    fig, ax1 = plt.subplots()
494198fb66SBarry Smith    plt.title(streamstype+' Perfect and Streams Speedup')
507137e648SBarry Smith    ax2 = ax1.twinx()
517137e648SBarry Smith    ax1.set_autoscaley_on(False)
528473a99dSBarry Smith
534198fb66SBarry Smith    r = range(1,size+1)
544198fb66SBarry Smith    speedups = speedups.values()
554198fb66SBarry Smith
568473a99dSBarry Smith    # make sure that actual bandwidth values (as opposed to perfect speedup) takes
578473a99dSBarry Smith    # at least a third of the y axis
584198fb66SBarry Smith    ymax = min(size, 3*max(speedups))
594198fb66SBarry Smith    ymin = min(1, min(speedups))
604198fb66SBarry Smith    if ymin < 1: ymin = 0
618473a99dSBarry Smith
624198fb66SBarry Smith    ax1.set_xlim(1,size)
634198fb66SBarry Smith    ax1.set_ylim([ymin,ymax])
644198fb66SBarry Smith    ax1.set_xlabel('Number of processes/threads')
657137e648SBarry Smith    ax1.set_ylabel('Memory Bandwidth Speedup')
664198fb66SBarry Smith    ax1.plot(r,r,'b',r,speedups,'r-o')
677137e648SBarry Smith    ax2.set_autoscaley_on(False)
684198fb66SBarry Smith    ax2.set_xlim([1,size])
694198fb66SBarry Smith    ax2.set_ylim([min(triads),max(triads)])
704198fb66SBarry Smith    ax2.set_ylabel("Achieved Bandwidth. Megabytes per Second")
714198fb66SBarry Smith    ax2.plot(r,triads,'g-o')
727137e648SBarry Smith
73d3ae85c4SBarry Smith    plt.show()
744198fb66SBarry Smith    if fileoutput: plt.savefig(streamstype+'scaling.png')
754198fb66SBarry Smith    if fileoutput: print("See graph in the file src/benchmarks/streams/"+streamstype+"scaling.png")
765b6bfdb9SJed Brown  except Exception as e:
775b6bfdb9SJed Brown    if fileoutput: print("Unable to plot speedup to a file")
785b6bfdb9SJed Brown    else: print("Unable to display speedup plot")
79182d2d36SBarry Smith    return
80d3ae85c4SBarry Smith
811df1832dSBarry Smith  ff.close()
821df1832dSBarry Smith
83d3ae85c4SBarry Smith#
84d3ae85c4SBarry Smith#
85d3ae85c4SBarry Smithif __name__ ==  '__main__':
86d3ae85c4SBarry Smith  import sys
874198fb66SBarry Smith
884198fb66SBarry Smith  process(sys.argv[1],len(sys.argv)-2)
89d3ae85c4SBarry Smith
90d3ae85c4SBarry Smith
91