xref: /petsc/src/benchmarks/streams/process.py (revision 182d2d361c68a88cb43f88c6bbcabae3893e4af9)
1#!/usr/bin/env python
2#!/bin/env python
3#
4#    Computers speed up of Streams benchmark results generated by make streams and plots
5#
6#    matplotlib can switch between different backends hence this needs to be run
7#    twice to first generate a file and then display a window
8#
9import os
10#
11def process(fileoutput = 1):
12  import re
13  ff = open('scaling.log')
14  data = ff.read()
15  ff.close()
16
17  hosts  = {}
18  triads = {}
19  speedups = {}
20  match = data.split('Number of MPI processes ')
21  for i in match:
22    if i:
23      fields = i.split('\n')
24      size = int(fields[0])
25      hosts[size] = fields[1:size+1]
26      triads[size] = float(fields[size+5].split()[1])
27
28  ff = open('scaling.log','a')
29  if fileoutput: print 'np  speedup'
30  if fileoutput: ff.write('np  speedup\n')
31  for sizes in hosts:
32    speedups[sizes] = triads[sizes]/triads[1]
33    if fileoutput: print sizes,round(triads[sizes]/triads[1],2)
34    if fileoutput: ff.write(str(sizes)+' '+str(round(triads[sizes]/triads[1],2))+'\n')
35
36  if fileoutput: print "Estimation of possible speedup of MPI programs based on Streams benchmark."
37  if fileoutput: ff.write("Estimation of possible speedup of MPI programs based on Streams benchmark.\n")
38
39  if fileoutput:
40    import re
41    last = max(hosts.keys())
42    lasthosts = hosts[last]
43    for i in range(0,len(lasthosts)):
44      lasthosts[i] = re.sub(r"Process [0-9]*", "", lasthosts[i])
45    ulasthosts = list(set(lasthosts))
46    print "It appears you have "+str(len(ulasthosts))+" nodes"
47    ff.write("It appears you have "+str(len(ulasthosts))+" nodes\n")
48
49    testhosts = []
50    for i in range(0,len(lasthosts)):
51      testhosts.append(ulasthosts[i % len(ulasthosts)])
52    if testhosts == lasthosts:
53      print "   distributed in a round robin order"
54      ff.write("   distributed in a round robin order\n")
55    else:
56      print "   NOT distributed in a round robin order"
57      ff.write("   NOT distributed in a round robin order\n")
58
59  try:
60    import matplotlib
61  except:
62    print "Unable to open matplotlib to plot speedup"
63    return
64
65  try:
66    if fileoutput: matplotlib.use('Agg')
67    import matplotlib.pyplot as plt
68  except:
69    print "Unable to open matplotlib to plot speedup"
70    return
71
72  try:
73    fig, ax1 = plt.subplots()
74    plt.title('MPI Perfect and Streams Speedup')
75    ax2 = ax1.twinx()
76    ax1.set_autoscaley_on(False)
77    ax1.set_xlim([min(hosts.keys()),max(hosts.keys())])
78    ax1.set_ylim([min(hosts.keys()),max(hosts.keys())])
79    ax1.set_xlabel('Number of MPI processes')
80    ax1.set_ylabel('Memory Bandwidth Speedup')
81    ax1.plot(hosts.keys(),hosts.keys(),'b-o',hosts.keys(),speedups.values(),'r-o')
82    ax2.set_autoscaley_on(False)
83    ax2.set_xlim([min(hosts.keys()),max(hosts.keys())])
84    ax2.set_ylim([min(triads.values())/1000.,min(triads.values())*max(hosts.keys())/1000.])
85    ax2.set_ylabel("Achieved Bandwidth. Gigabytes per Second")
86
87    plt.show()
88    if fileoutput: plt.savefig('scaling.png')
89    if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png"
90    if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n")
91  except:
92    if fileoutput: print "Unable to plot speedup to a file"
93    else: print "Unable to display speedup plot"
94    return
95
96  ff.close()
97
98#
99#
100if __name__ ==  '__main__':
101  import sys
102  process(len(sys.argv)-1)
103
104
105