xref: /petsc/src/benchmarks/streams/process.py (revision 1df1832d73d056fc8e354d2e487472d3e74063b3)
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    plt.title('Perfect and Streams Speedup')
74    plt.plot(hosts.keys(),hosts.keys(),'b-o',hosts.keys(),speedups.values(),'r-o')
75    plt.show()
76    if fileoutput: plt.savefig('scaling.png')
77    if fileoutput: print "See graph in the file src/benchmarks/streams/scaling.png"
78    if fileoutput: ff.write("See graph in the file src/benchmarks/streams/scaling.png\n")
79  except:
80    if fileoutput: print "Unable to plot speedup to a file"
81    else: print "Unable to display speedup plot"
82    return
83
84  ff.close()
85
86#
87#
88if __name__ ==  '__main__':
89  import sys
90  process(len(sys.argv)-1)
91
92
93