1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// Copyright (C) 2008 Dag Lindbo, Anders Logg, Ilmar Wilbers.
// Licensed under the GNU LGPL Version 2.1.
//
// First added: 2008-07-22
// Last changed: 2008-08-07
#include <iostream>
#include <dolfin.h>
#include "forms.h"
using namespace dolfin;
double assemble_form(Form& form, Mesh& mesh)
{
// Assemble once
const double t0 = time();
Matrix A;
assemble(A, form, mesh);
return time() - t0;
}
double reassemble_form(Form& form, Mesh& mesh)
{
// Assemble once
Matrix A;
assemble(A, form, mesh);
// Reassemble
const double t0 = time();
assemble(A, form, mesh, false);
return time() - t0;
}
int main()
{
dolfin_set("output destination", "silent");
// Backends
Array<std::string> backends;
backends.push_back("uBLAS");
backends.push_back("PETSc");
backends.push_back("Epetra");
backends.push_back("MTL4");
backends.push_back("STL");
// Forms
Array<std::string> forms;
forms.push_back("Poisson2DP1");
forms.push_back("Poisson2DP2");
forms.push_back("Poisson2DP3");
forms.push_back("THStokes2D");
forms.push_back("StabStokes2D");
forms.push_back("Elasticity3D");
forms.push_back("NSEMomentum3D");
// Tables for results
Table t0("Assemble total");
Table t1("Init dof map");
Table t2("Build sparsity");
Table t3("Init tensor");
Table t4("Delete sparsity");
Table t5("Assemble cells");
Table t6("Overhead");
Table t7("Reassemble total");
// Benchmark assembly
for (unsigned int i = 0; i < backends.size(); i++)
{
dolfin_set("linear algebra backend", backends[i]);
dolfin_set("timer prefix", backends[i]);
std::cout << "Backend: " << backends[i] << std::endl;
for (unsigned int j = 0; j < forms.size(); j++)
{
std::cout << " Form: " << forms[j] << std::endl;
t0(backends[i], forms[j]) = bench_form(forms[j], assemble_form);
t1(backends[i], forms[j]) = timing(backends[i] + t1.title(), true);
t2(backends[i], forms[j]) = timing(backends[i] + t2.title(), true);
t3(backends[i], forms[j]) = timing(backends[i] + t3.title(), true);
t4(backends[i], forms[j]) = timing(backends[i] + t4.title(), true);
t5(backends[i], forms[j]) = timing(backends[i] + t5.title(), true);
}
}
// Benchmark reassembly
for (unsigned int i = 0; i < backends.size(); i++)
{
dolfin_set("linear algebra backend", backends[i]);
dolfin_set("timer prefix", backends[i]);
std::cout << "Backend: " << backends[i] << std::endl;
for (unsigned int j = 0; j < forms.size(); j++)
{
std::cout << " Form: " << forms[j] << std::endl;
t7(backends[i], forms[j]) = bench_form(forms[j], reassemble_form);
}
}
// Compute overhead
t6 = t0 - t1 - t2 - t3 - t4 - t5;
// Display results
dolfin_set("output destination", "terminal");
cout << endl; t0.disp();
cout << endl; t1.disp();
cout << endl; t2.disp();
cout << endl; t3.disp();
cout << endl; t4.disp();
cout << endl; t5.disp();
cout << endl; t6.disp();
cout << endl; t7.disp();
return 0;
}
|