xref: /petsc/src/benchmarks/streams/process.py (revision a6cca095d015c166a23607f39f253a09d60b8466)
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  ff.close()
36
37  try:
38    import matplotlib
39  except:
40    print "Unable to open matplotlib to plot speedup"
41    return
42
43  try:
44    if fileoutput: matplotlib.use('Agg')
45    import matplotlib.pyplot as plt
46  except:
47    print "Unable to open matplotlib to plot speedup"
48    return
49
50  try:
51    plt.title('Perfect and Streams Speedup')
52    plt.plot(hosts.keys(),hosts.keys(),'b-o',hosts.keys(),speedups.values(),'r-o')
53    plt.show()
54    if fileoutput: plt.savefig('scaling.png')
55  except:
56    if fileoutput: print "Unable to plot speedup to a file"
57    else: print "Unable to display speedup plot"
58    return
59
60#
61#
62if __name__ ==  '__main__':
63  import sys
64  process(len(sys.argv)-1)
65
66
67