Debian Codegraph @

bench/fem/speedup/cpp/assemble-poisson.cpp

raw
1 // Copyright (C) 2009 Anders Logg
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 // First added: 2009-09-15
19 // Last changed: 2012-12-12
20 //
21 // Simple Poisson assembler
22
23 #include <cstdlib>
24 #include <dolfin.h>
25 #include "Poisson.h"
26
27 using namespace dolfin;
28
29 int main(int argc, char* argv[])
30 {
31 // Parse command-line arguments
32 if (argc != 2)
33 {
34 info("Usage: solve-poisson n");
35 return 1;
36 }
37 int n = atoi(argv[1]);
38
39 // Create mesh and function space
40 auto mesh = std::make_shared<UnitCubeMesh>(n, n, n);
41 auto V = std::make_shared<Poisson::FunctionSpace>(mesh);
42
43 const MPI_Comm comm = mesh->mpi_comm();
44
45 // Assemble matrix
46 Poisson::BilinearForm a(V, V);
47 Matrix A;
48 dolfin::MPI::barrier(comm);
49 double t = time();
50 Assembler assembler;
51 assembler.assemble(A, a);
52 dolfin::MPI::barrier(comm);
53 t = time() - t;
54
55 // Report timing
56 if (dolfin::MPI::rank(comm) == 0)
57 info("TIME (first assembly): %.5g", t);
58
59 // Re-assemble matrix
60 dolfin::MPI::barrier(comm);
61 t = time();
62 assembler.assemble(A, a);
63 dolfin::MPI::barrier(comm);
64 t = time() - t;
65
66 // Report timing
67 if (dolfin::MPI::rank(comm) == 0)
68 info("TIME (second assembly): %.5g", t);
69
70 return 0;
71 }