2 // Copyright (c) 2000-2002
3 // Joerg Walter, Mathias Koch
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // The authors gratefully acknowledge the support of
10 // GeNeSys mbH & Co. KG in producing this work.
20 #include <boost/numeric/ublas/vector.hpp>
21 #include <boost/numeric/ublas/vector_sparse.hpp>
22 #include <boost/numeric/ublas/matrix.hpp>
23 #include <boost/numeric/ublas/matrix_sparse.hpp>
25 #include <boost/timer.hpp>
28 #define BOOST_UBLAS_NOT_USED(x) (void)(x)
31 namespace ublas = boost::numeric::ublas;
33 void header (std::string text);
37 void operator () (int multiplies, int plus, int runs, double elapsed) {
38 std::cout << "elapsed: " << elapsed << " s, "
39 << (multiplies * ublas::type_traits<T>::multiplies_complexity +
40 plus * ublas::type_traits<T>::plus_complexity) * runs /
41 (1024 * 1024 * elapsed) << " Mflops" << std::endl;
45 template<class T, int N>
46 struct c_vector_traits {
49 template<class T, int N, int M>
50 struct c_matrix_traits {
51 typedef T type [N] [M];
54 template<class T, int N>
55 struct initialize_c_vector {
56 void operator () (typename c_vector_traits<T, N>::type &v) {
57 for (int i = 0; i < N; ++ i)
58 v [i] = std::rand () * 1.f;
64 void initialize_vector (V &v) {
66 for (int i = 0; i < size; ++ i)
67 v [i] = std::rand () * 1.f;
71 template<class T, int N, int M>
72 struct initialize_c_matrix {
73 void operator () (typename c_matrix_traits<T, N, M>::type &m) {
74 for (int i = 0; i < N; ++ i)
75 for (int j = 0; j < M; ++ j)
76 m [i] [j] = std::rand () * 1.f;
82 void initialize_matrix (M &m, ublas::row_major_tag) {
83 int size1 = m.size1 ();
84 int size2 = m.size2 ();
85 for (int i = 0; i < size1; ++ i)
86 for (int j = 0; j < size2; ++ j)
87 m (i, j) = std::rand () * 1.f;
92 void initialize_matrix (M &m, ublas::column_major_tag) {
93 int size1 = m.size1 ();
94 int size2 = m.size2 ();
95 for (int j = 0; j < size2; ++ j)
96 for (int i = 0; i < size1; ++ i)
97 m (i, j) = std::rand () * 1.f;
102 void initialize_matrix (M &m) {
103 typedef typename M::orientation_category orientation_category;
104 initialize_matrix (m, orientation_category ());
109 void sink_scalar (const T &s) {
113 template<class T, int N>
114 struct sink_c_vector {
115 void operator () (const typename c_vector_traits<T, N>::type &v) {
116 static typename c_vector_traits<T, N>::type g_v;
117 for (int i = 0; i < N; ++ i)
123 void sink_vector (const V &v) {
127 template<class T, int N, int M>
128 struct sink_c_matrix {
129 void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
130 static typename c_matrix_traits<T, N, M>::type g_m;
131 for (int i = 0; i < N; ++ i)
132 for (int j = 0; j < M; ++ j)
133 g_m [i] [j] = m [i] [j];
138 void sink_matrix (const M &m) {
144 void operator () (int runs);
147 template<class T, int N>
149 void operator () (int runs);
152 template<class T, int N>
154 void operator () (int runs);
157 template<class T, int N>
159 void operator () (int runs);
167 // #define USE_STD_COMPLEX
169 #define USE_MAP_ARRAY
170 // #define USE_STD_MAP
171 // #define USE_STD_VALARRAY
173 #define USE_MAPPED_VECTOR
174 #define USE_COMPRESSED_VECTOR
175 #define USE_COORDINATE_VECTOR
177 #define USE_MAPPED_MATRIX
178 // #define USE_SPARSE_VECTOR_OF_SPARSE_VECTOR
179 #define USE_COMPRESSED_MATRIX
180 #define USE_COORDINATE_MATRIX