Debian Codegraph @

bench/fem/speedup/cpp/analyse-bench

raw
1 #!/usr/bin/env python
2
3 # Copyright (C) 2009 Anders Logg
4 #
5 # This file is part of DOLFIN.
6 #
7 # DOLFIN is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # DOLFIN is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
19 #
20 # Modified by Johan Hake, 2009.
21 #
22 # First added: 2009-09-15
23 # Last changed: 2011-01-04
24
25 # FIXME: Not checked if working!
26
27 from dolfin import *
28 from glob import glob
29 from numpy import arange
30
31 # Size of mesh
32 size = 128
33
34 # Number of processes to use
35 # NOTE: Largest number of processors to run is 2^EXP
36 EXP = 6
37 num_processes = list(2**arange(EXP+1))
38
39 # Function for extracting log file
40 def get_filename(pattern):
41 filenames = glob(pattern)
42 if len(filenames) == 0:
43 raise IOError, "Unable to open file: %s" % pattern
44 elif len(filenames) > 1:
45 raise RuntimeError, "More than one data file, don't know which one to pick: " + ", ".join(filenames)
46 filename = filenames[0]
47 print "Reading data from %s..." % filename
48 return filename
49
50 # Iterate over process range
51 assemble_time = []
52 assemble_second_time = []
53 solve_time = []
54
55 # Remove run with one processor
56 if 1 in num_processes:
57 num_processes.remove(1)
58
59 for np in num_processes:
60
61 # Read timings for assemble benchmark
62 lines = open(get_filename(\
63 "assemble-poisson_np_%d_size_%d.log*" % (np, size))).readlines()
64 assemble_time.append(float([line for line in lines \
65 if "TIME (first assembly):" in \
66 line][0].split("TIME (first assembly): ")[-1]))
67
68 assemble_second_time.append(float([line for line in lines \
69 if "TIME (second assembly):" in \
70 line][0].split("TIME (second assembly): ")[-1]))
71
72 # Read timings for solve benchmark
73 filename = get_filename("solve-poisson_np_%d_size_%d.log*" % (np, size))
74 solve_time.append(float([line for line in open(filename).readlines()\
75 if "TIME:" in line][0].split("TIME: ")[-1]))
76
77 # Compute speedups
78 scale_assemble = [assemble_time[0] / t for t in assemble_time]
79 scale_second_assemble = [assemble_second_time[0] / t for t in assemble_second_time]
80 scale_solve = [solve_time[0] / t for t in solve_time]
81
82 # Print results
83 table = Table("Speedup")
84 for i, np in enumerate(num_processes):
85 table.set(str(np), "Assemble (first)", scale_assemble[i])
86 table.set(str(np), "Assemble (second)", scale_second_assemble[i])
87 table.set(str(np), "Solve", scale_solve[i])
88
89 print ""
90 info(table, True)