Debian Codegraph @

bench/fem/assembly/python/broken

raw
1 # Copyright (C) 2008 Ilmar Wilbers
2 #
3 # This file is part of DOLFIN.
4 #
5 # DOLFIN is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # DOLFIN is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Modified by Anders Logg, 2008.
19 #
20 # First added: 2008-06-04
21 # Last changed: 2008-07-21
22
23 # Be careful to first run the benchmark once in order for
24 # the Python extensions to be created, or else the timings
25 # will not be correct.
26
27 from dolfin import *
28 from time import time
29 import sys
30
31 def make_form(name, mesh):
32 globals()['mesh'] = mesh
33 execfile("../forms/" + name + '.form', globals())
34 try:
35 return a
36 except:
37 print "No object 'a' to return in file %s.form" %name
38 return None
39
40 def bench_form(form, mesh, reps=1):
41 totaltime = 0.0
42 t0 = time()
43 A = assemble(form, mesh)
44 totaltime += time() - t0
45 for i in range(reps - 1):
46 t0 = time()
47 assemble(form, mesh, tensor=A, reset_sparsity=False)
48 totaltime += time() - t0
49 return totaltime / float(reps)
50
51 def make_mesh(name, dim):
52 if dim == 3:
53 N = 32
54 mesh = UnitCube(N, N, N)
55 return mesh
56 else:
57 N = 256
58 mesh = UnitSquare(N, N)
59 return mesh
60
61 if __name__ == "__main__":
62 try:
63 reps = int(sys.argv[1])
64 except:
65 print 'Usage: %s number_of_repetitions [1]' %sys.argv[0]
66 reps = 1
67
68 # Backends
69 backends = ["uBLAS", "PETSc", "Tpetra", "Eigen"]
70
71 # Forms
72 forms = ["Elasticity3D",
73 "PoissonP1",
74 "PoissonP2",
75 "PoissonP3",
76 "THStokes2D",
77 "NSEMomentum3D",
78 "StabStokes2D"]
79
80 dolfin_set("output destination", "silent")
81 results = Table("Assembly benchmark")
82
83 for backend in backends:
84 dolfin_set("linear algebra backend", backend)
85 for form in forms:
86 dim = 2 if not form.find("3D") > -1 else 3
87 m = make_mesh(form, dim)
88 a = make_form(form, m)
89 print "Assembling %s with %s" % (form, backend)
90 t = bench_form(a, m, reps=reps)
91 results.set(backend, form, t)
92
93 dolfin_set("output destination", "terminal")
94 print ""
95
96 results.disp()
97 list_timings(TimingClear_keep,
98 [TimingType_wall, TimingType_user, TimingType_system])