~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/bench/la/vector/main.cpp

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2006 Garth N. Wells.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
//
4
 
// First added:  2006-08-18
5
 
// Last changed:
6
 
//
7
 
// Benchmarks for assigning values to vector
8
 
 
9
 
#include <dolfin.h>
10
 
#include <boost/tuple/tuple.hpp>
11
 
 
12
 
using namespace dolfin;
13
 
using namespace boost::tuples;
14
 
 
15
 
//-----------------------------------------------------------------------------
16
 
template<class Vec>
17
 
struct VectorAssign
18
 
{
19
 
  static tuple<real, real> benchVectorAssign(const dolfin::uint N, const dolfin::uint n)
20
 
  {
21
 
    set("output destination", "silent");
22
 
 
23
 
    tuple<real, real> timing;
24
 
    Vec x(N);
25
 
 
26
 
    tic();
27
 
    for(dolfin::uint i=0; i < n; ++i)
28
 
      for(dolfin::uint j=0; j < N; ++j)
29
 
        x(j) = 1.0;      
30
 
    get<0>(timing) = toc();
31
 
 
32
 
    tic();
33
 
    real xtemp = 0.0;
34
 
    for(dolfin::uint i=0; i < n; ++i)
35
 
      for(dolfin::uint j=0; j < N; ++j)
36
 
        xtemp = x(j);      
37
 
    get<1>(timing) = toc();
38
 
 
39
 
    return timing;
40
 
  }
41
 
};
42
 
//-----------------------------------------------------------------------------
43
 
int main()
44
 
{
45
 
  // Bechmark elementwise assignment and access
46
 
  const dolfin::uint N[3] = {6, 6, 100};
47
 
  const dolfin::uint n[3] = {100000, 100000000, 1000000};
48
 
 
49
 
  tuple<real, real> ublas_timing[3];
50
 
#ifdef HAVE_PETSC_H  
51
 
  tuple<real, real> petsc_timing[2];
52
 
#endif
53
 
 
54
 
  begin("Vector benchmark timings");
55
 
 
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]);
60
 
 
61
 
#ifdef HAVE_PETSC_H  
62
 
  // Perform PETSc benchmarks
63
 
  petsc_timing[0] = VectorAssign<PETScVector>::benchVectorAssign(N[0], n[0]);
64
 
#endif
65
 
 
66
 
  // Output assignment timings
67
 
  set("output destination", "terminal");
68
 
  begin("Assign values to a vector of length N elementwise n times");
69
 
#ifdef HAVE_PETSC_H  
70
 
  cout << "PETScVector (N="<< N[0] << ", n=" << n[0] << "): " << get<0>(petsc_timing[0]) << endl;
71
 
#endif
72
 
  for(dolfin::uint i=0; i< 3; ++i)
73
 
    cout << "uBlasVector (N="<< N[i] << ", n=" << n[i] << "): " << get<0>(ublas_timing[i]) << endl;
74
 
 
75
 
  end();
76
 
 
77
 
  // Output access timings
78
 
  begin("Access values of a vector of length n elementwise N times");
79
 
#ifdef HAVE_PETSC_H  
80
 
  cout << "PETScVector (N="<< N[0] << ", n=" << n[0] << "): " << get<0>(petsc_timing[0]) << endl;
81
 
#endif
82
 
  for(dolfin::uint i=0; i< 3; ++i)
83
 
    cout << "uBlasVector (N="<< N[i] << ", n=" << n[i] << "): " << get<1>(ublas_timing[i]) << endl;
84
 
 
85
 
  end();
86
 
  end();
87
 
 
88
 
  return 0;
89
 
}