1
// Copyright (C) 2006 Garth N. Wells.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2006-08-18
7
// Benchmarks for assigning values to vector
10
#include <boost/tuple/tuple.hpp>
12
using namespace dolfin;
13
using namespace boost::tuples;
15
//-----------------------------------------------------------------------------
19
static tuple<real, real> benchVectorAssign(const dolfin::uint N, const dolfin::uint n)
21
set("output destination", "silent");
23
tuple<real, real> timing;
27
for(dolfin::uint i=0; i < n; ++i)
28
for(dolfin::uint j=0; j < N; ++j)
30
get<0>(timing) = toc();
34
for(dolfin::uint i=0; i < n; ++i)
35
for(dolfin::uint j=0; j < N; ++j)
37
get<1>(timing) = toc();
42
//-----------------------------------------------------------------------------
45
// Bechmark elementwise assignment and access
46
const dolfin::uint N[3] = {6, 6, 100};
47
const dolfin::uint n[3] = {100000, 100000000, 1000000};
49
tuple<real, real> ublas_timing[3];
51
tuple<real, real> petsc_timing[2];
54
begin("Vector benchmark timings");
56
// Perform uBlas benchmarks
57
ublas_timing[0] = VectorAssign<uBlasVector>::benchVectorAssign(N[0], n[0]);
58
ublas_timing[1] = VectorAssign<uBlasVector>::benchVectorAssign(N[1], n[1]);
59
ublas_timing[2] = VectorAssign<uBlasVector>::benchVectorAssign(N[2], n[2]);
62
// Perform PETSc benchmarks
63
petsc_timing[0] = VectorAssign<PETScVector>::benchVectorAssign(N[0], n[0]);
66
// Output assignment timings
67
set("output destination", "terminal");
68
begin("Assign values to a vector of length N elementwise n times");
70
cout << "PETScVector (N="<< N[0] << ", n=" << n[0] << "): " << get<0>(petsc_timing[0]) << endl;
72
for(dolfin::uint i=0; i< 3; ++i)
73
cout << "uBlasVector (N="<< N[i] << ", n=" << n[i] << "): " << get<0>(ublas_timing[i]) << endl;
77
// Output access timings
78
begin("Access values of a vector of length n elementwise N times");
80
cout << "PETScVector (N="<< N[0] << ", n=" << n[0] << "): " << get<0>(petsc_timing[0]) << endl;
82
for(dolfin::uint i=0; i< 3; ++i)
83
cout << "uBlasVector (N="<< N[i] << ", n=" << n[i] << "): " << get<1>(ublas_timing[i]) << endl;