xref: /petsc/src/benchmarks/streams/process.py (revision 7137e648527a5ef3cccb7eb9478de302cc414f12) !
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
28a6cca095SBarry Smith  ff = open('scaling.log','a')
29a6cca095SBarry Smith  if fileoutput: print 'np  speedup'
30a6cca095SBarry Smith  if fileoutput: ff.write('np  speedup\n')
31d3ae85c4SBarry Smith  for sizes in hosts:
32d3ae85c4SBarry Smith    speedups[sizes] = triads[sizes]/triads[1]
33a6cca095SBarry Smith    if fileoutput: print sizes,round(triads[sizes]/triads[1],2)
34a6cca095SBarry Smith    if fileoutput: ff.write(str(sizes)+' '+str(round(triads[sizes]/triads[1],2))+'\n')
351df1832dSBarry Smith
361df1832dSBarry Smith  if fileoutput: print "Estimation of possible speedup of MPI programs based on Streams benchmark."
371df1832dSBarry Smith  if fileoutput: ff.write("Estimation of possible speedup of MPI programs based on Streams benchmark.\n")
381df1832dSBarry Smith
391df1832dSBarry Smith  if fileoutput:
401df1832dSBarry Smith    import re
411df1832dSBarry Smith    last = max(hosts.keys())
421df1832dSBarry Smith    lasthosts = hosts[last]
431df1832dSBarry Smith    for i in range(0,len(lasthosts)):
441df1832dSBarry Smith      lasthosts[i] = re.sub(r"Process [0-9]*", "", lasthosts[i])
451df1832dSBarry Smith    ulasthosts = list(set(lasthosts))
461df1832dSBarry Smith    print "It appears you have "+str(len(ulasthosts))+" nodes"
471df1832dSBarry Smith    ff.write("It appears you have "+str(len(ulasthosts))+" nodes\n")
481df1832dSBarry Smith
491df1832dSBarry Smith    testhosts = []
501df1832dSBarry Smith    for i in range(0,len(lasthosts)):
511df1832dSBarry Smith      testhosts.append(ulasthosts[i % len(ulasthosts)])
521df1832dSBarry Smith    if testhosts == lasthosts:
531df1832dSBarry Smith      print "   distributed in a round robin order"
541df1832dSBarry Smith      ff.write("   distributed in a round robin order\n")
551df1832dSBarry Smith    else:
561df1832dSBarry Smith      print "   NOT distributed in a round robin order"
571df1832dSBarry Smith      ff.write("   NOT distributed in a round robin order\n")
58d3ae85c4SBarry Smith
59d3ae85c4SBarry Smith  try:
60d3ae85c4SBarry Smith    import matplotlib
61d3ae85c4SBarry Smith  except:
626a90b735SBarry Smith    print "Unable to open matplotlib to plot speedup"
63d3ae85c4SBarry Smith    return
64d3ae85c4SBarry Smith
65d3ae85c4SBarry Smith  try:
66a6cca095SBarry Smith    if fileoutput: matplotlib.use('Agg')
67d3ae85c4SBarry Smith    import matplotlib.pyplot as plt
686a90b735SBarry Smith  except:
696a90b735SBarry Smith    print "Unable to open matplotlib to plot speedup"
706a90b735SBarry Smith    return
71d3ae85c4SBarry Smith
72*7137e648SBarry Smith#  try:
73*7137e648SBarry Smith  fig, ax1 = plt.subplots()
74*7137e648SBarry Smith  plt.title('MPI Perfect and Streams Speedup')
75*7137e648SBarry Smith  ax2 = ax1.twinx()
76*7137e648SBarry Smith  ax1.set_autoscaley_on(False)
77*7137e648SBarry Smith  ax1.set_xlim([min(hosts.keys()),max(hosts.keys())])
78*7137e648SBarry Smith  ax1.set_ylim([min(hosts.keys()),max(hosts.keys())])
79*7137e648SBarry Smith  ax1.set_xlabel('Number of MPI processes')
80*7137e648SBarry Smith  ax1.set_ylabel('Memory Bandwidth Speedup')
81*7137e648SBarry Smith  ax1.plot(hosts.keys(),hosts.keys(),'b-o',hosts.keys(),speedups.values(),'r-o')
82*7137e648SBarry Smith  ax2.set_autoscaley_on(False)
83*7137e648SBarry Smith  ax2.set_xlim([min(hosts.keys()),max(hosts.keys())])
84*7137e648SBarry Smith  ax2.set_ylim([min(triads.values())/1000.,min(triads.values())*max(hosts.keys())/1000.])
85*7137e648SBarry Smith  ax2.set_ylabel("Achieved Bandwidth. Gigabytes per Second")
86*7137e648SBarry Smith
87d3ae85c4SBarry Smith  plt.show()
88a6cca095SBarry Smith  if fileoutput: plt.savefig('scaling.png')
891df1832dSBarry Smith  if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png"
901df1832dSBarry Smith  if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n")
91*7137e648SBarry Smith # except:
92*7137e648SBarry Smith #   if fileoutput: print "Unable to plot speedup to a file"
93*7137e648SBarry Smith #   else: print "Unable to display speedup plot"
94*7137e648SBarry Smith #   return
95d3ae85c4SBarry Smith
961df1832dSBarry Smith  ff.close()
971df1832dSBarry Smith
98d3ae85c4SBarry Smith#
99d3ae85c4SBarry Smith#
100d3ae85c4SBarry Smithif __name__ ==  '__main__':
101d3ae85c4SBarry Smith  import sys
102a6cca095SBarry Smith  process(len(sys.argv)-1)
103d3ae85c4SBarry Smith
104d3ae85c4SBarry Smith
105