xref: /petsc/src/benchmarks/streams/process.py (revision 19623ac0929ec554b92a56cbe2f821b1384a9cdc)
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#
9d3ae85c4SBarry Smithimport os
10d3ae85c4SBarry Smith#
11a6cca095SBarry Smithdef process(fileoutput = 1):
12d3ae85c4SBarry Smith  import re
13a6cca095SBarry Smith  ff = open('scaling.log')
14d3ae85c4SBarry Smith  data = ff.read()
15d3ae85c4SBarry Smith  ff.close()
16d3ae85c4SBarry Smith
17d3ae85c4SBarry Smith  hosts  = {}
18d3ae85c4SBarry Smith  triads = {}
19d3ae85c4SBarry Smith  speedups = {}
20d3ae85c4SBarry Smith  match = data.split('Number of MPI processes ')
21d3ae85c4SBarry Smith  for i in match:
22d3ae85c4SBarry Smith    if i:
23d3ae85c4SBarry Smith      fields = i.split('\n')
24d3ae85c4SBarry Smith      size = int(fields[0])
25d3ae85c4SBarry Smith      hosts[size] = fields[1:size+1]
26d3ae85c4SBarry Smith      triads[size] = float(fields[size+5].split()[1])
27d3ae85c4SBarry Smith
28293a2e3aSBarry Smith  if len(hosts) < 2: return
29293a2e3aSBarry Smith
30a6cca095SBarry Smith  ff = open('scaling.log','a')
31a6cca095SBarry Smith  if fileoutput: print 'np  speedup'
32a6cca095SBarry Smith  if fileoutput: ff.write('np  speedup\n')
33d3ae85c4SBarry Smith  for sizes in hosts:
34d3ae85c4SBarry Smith    speedups[sizes] = triads[sizes]/triads[1]
35a6cca095SBarry Smith    if fileoutput: print sizes,round(triads[sizes]/triads[1],2)
36a6cca095SBarry Smith    if fileoutput: ff.write(str(sizes)+' '+str(round(triads[sizes]/triads[1],2))+'\n')
371df1832dSBarry Smith
381df1832dSBarry Smith  if fileoutput: print "Estimation of possible speedup of MPI programs based on Streams benchmark."
391df1832dSBarry Smith  if fileoutput: ff.write("Estimation of possible speedup of MPI programs based on Streams benchmark.\n")
401df1832dSBarry Smith
411df1832dSBarry Smith  if fileoutput:
421df1832dSBarry Smith    import re
431df1832dSBarry Smith    last = max(hosts.keys())
441df1832dSBarry Smith    lasthosts = hosts[last]
451df1832dSBarry Smith    for i in range(0,len(lasthosts)):
461df1832dSBarry Smith      lasthosts[i] = re.sub(r"Process [0-9]*", "", lasthosts[i])
471df1832dSBarry Smith    ulasthosts = list(set(lasthosts))
48*19623ac0SBarry Smith    print "It appears you have "+str(len(ulasthosts))+" node(s)"
49*19623ac0SBarry Smith    ff.write("It appears you have "+str(len(ulasthosts))+" node(s)\n")
501df1832dSBarry Smith
51*19623ac0SBarry Smith    if len(ulasthosts) < 1:
521df1832dSBarry Smith      testhosts = []
531df1832dSBarry Smith      for i in range(0,len(lasthosts)):
541df1832dSBarry Smith        testhosts.append(ulasthosts[i % len(ulasthosts)])
551df1832dSBarry Smith      if testhosts == lasthosts:
561df1832dSBarry Smith        print "   distributed in a round robin order"
571df1832dSBarry Smith        ff.write("   distributed in a round robin order\n")
581df1832dSBarry Smith      else:
591df1832dSBarry Smith        print "   NOT distributed in a round robin order"
601df1832dSBarry Smith        ff.write("   NOT distributed in a round robin order\n")
61d3ae85c4SBarry Smith
62d3ae85c4SBarry Smith  try:
63d3ae85c4SBarry Smith    import matplotlib
64d3ae85c4SBarry Smith  except:
656a90b735SBarry Smith    print "Unable to open matplotlib to plot speedup"
66d3ae85c4SBarry Smith    return
67d3ae85c4SBarry Smith
68d3ae85c4SBarry Smith  try:
69a6cca095SBarry Smith    if fileoutput: matplotlib.use('Agg')
70d3ae85c4SBarry Smith    import matplotlib.pyplot as plt
716a90b735SBarry Smith  except:
726a90b735SBarry Smith    print "Unable to open matplotlib to plot speedup"
736a90b735SBarry Smith    return
74d3ae85c4SBarry Smith
75182d2d36SBarry Smith  try:
767137e648SBarry Smith    fig, ax1 = plt.subplots()
777137e648SBarry Smith    plt.title('MPI Perfect and Streams Speedup')
787137e648SBarry Smith    ax2 = ax1.twinx()
797137e648SBarry Smith    ax1.set_autoscaley_on(False)
808473a99dSBarry Smith
818473a99dSBarry Smith    # make sure that actual bandwidth values (as opposed to perfect speedup) takes
828473a99dSBarry Smith    # at least a third of the y axis
838473a99dSBarry Smith    ymax = min(max(hosts.keys()), 3*max(triads.values())/min(triads.values()) - 2)
848473a99dSBarry Smith
857137e648SBarry Smith    ax1.set_xlim([min(hosts.keys()),max(hosts.keys())])
868473a99dSBarry Smith    ax1.set_ylim([min(hosts.keys()),ymax])
877137e648SBarry Smith    ax1.set_xlabel('Number of MPI processes')
887137e648SBarry Smith    ax1.set_ylabel('Memory Bandwidth Speedup')
89576f62e6SBarry Smith    ax1.plot(hosts.keys(),hosts.keys(),'b',hosts.keys(),speedups.values(),'r-o')
907137e648SBarry Smith    ax2.set_autoscaley_on(False)
917137e648SBarry Smith    ax2.set_xlim([min(hosts.keys()),max(hosts.keys())])
928473a99dSBarry Smith    ax2.set_ylim([min(triads.values())/1000.,min(triads.values())*ymax/1000.])
937137e648SBarry Smith    ax2.set_ylabel("Achieved Bandwidth. Gigabytes per Second")
947137e648SBarry Smith
95d3ae85c4SBarry Smith    plt.show()
96a6cca095SBarry Smith    if fileoutput: plt.savefig('scaling.png')
971df1832dSBarry Smith    if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png"
981df1832dSBarry Smith    if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n")
998473a99dSBarry Smith  except Exception, e:
100182d2d36SBarry Smith    if fileoutput: print "Unable to plot speedup to a file"
101182d2d36SBarry Smith    else: print "Unable to display speedup plot"
102182d2d36SBarry Smith    return
103d3ae85c4SBarry Smith
1041df1832dSBarry Smith  ff.close()
1051df1832dSBarry Smith
106d3ae85c4SBarry Smith#
107d3ae85c4SBarry Smith#
108d3ae85c4SBarry Smithif __name__ ==  '__main__':
109d3ae85c4SBarry Smith  import sys
110a6cca095SBarry Smith  process(len(sys.argv)-1)
111d3ae85c4SBarry Smith
112d3ae85c4SBarry Smith
113