| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
"""This script provides a benchmark for the JIT compiler, in |
| 4 |
particular the speed of the in-memory cache.""" |
| 5 |
|
| 6 |
# Copyright (C) 2008-2010 Anders Logg |
| 7 |
# |
| 8 |
# This file is part of DOLFIN. |
| 9 |
# |
| 10 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 11 |
# it under the terms of the GNU Lesser General Public License as published by |
| 12 |
# the Free Software Foundation, either version 3 of the License, or |
| 13 |
# (at your option) any later version. |
| 14 |
# |
| 15 |
# DOLFIN is distributed in the hope that it will be useful, |
| 16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
# GNU Lesser General Public License for more details. |
| 19 |
# |
| 20 |
# You should have received a copy of the GNU Lesser General Public License |
| 21 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 22 |
# |
| 23 |
# First added: 2008-09-04 |
| 24 |
# Last changed: 2010-05-03 |
| 25 |
|
| 26 |
from dolfin import * |
| 27 |
from time import time |
| 28 |
|
| 29 |
print "JIT compilation (in memory cache)" |
| 30 |
|
| 31 |
# Benchmark parameters |
| 32 |
NUM_REPS = 10 |
| 33 |
SIZE = 3 |
| 34 |
|
| 35 |
# Create mesh |
| 36 |
mesh = UnitCubeMesh(SIZE, SIZE, SIZE) |
| 37 |
|
| 38 |
# Create form (velocity equation for "G2") |
| 39 |
V = VectorFunctionSpace(mesh, "Lagrange", 1) |
| 40 |
Q = FunctionSpace(mesh, "Lagrange", 1) |
| 41 |
DG = FunctionSpace(mesh, "DG", 0) |
| 42 |
DGv = VectorFunctionSpace(mesh, "DG", 0) |
| 43 |
|
| 44 |
v = TestFunction(V) |
| 45 |
q = TestFunction(Q) |
| 46 |
u = TrialFunction(V) |
| 47 |
p = TrialFunction(Q) |
| 48 |
u0 = Function(V) |
| 49 |
p1 = Function(Q) |
| 50 |
W = Function(DGv) |
| 51 |
nu = Constant(0.1) |
| 52 |
k = Constant(0.1) |
| 53 |
h = 2*Circumradius(mesh) |
| 54 |
d1 = h |
| 55 |
d2 = 2.0*h |
| 56 |
|
| 57 |
U = 0.5*(u0 + u) |
| 58 |
|
| 59 |
F = (1.0/k)*inner(v, u - u0) + inner(v, grad(U)*W) + nu*inner(grad(v), grad(U)) - div(v)*p1 + \ |
| 60 |
d1*inner(grad(v)*W, grad(U)*W) + d2*div(v)*div(U) |
| 61 |
a = lhs(F*dx) |
| 62 |
|
| 63 |
# JIT compile once |
| 64 |
t0 = time() |
| 65 |
jit(a) |
| 66 |
t1 = time() - t0 |
| 67 |
|
| 68 |
# Then JIT compile some more |
| 69 |
t0 = time() |
| 70 |
for i in range(NUM_REPS): |
| 71 |
jit(a) |
| 72 |
t2 = (time() - t0) / float(NUM_REPS) |
| 73 |
|
| 74 |
print "Disk cache: ", t1 |
| 75 |
print "In-memory cache:", t2 |
| 76 |
print "BENCH", t2 |