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/matrix.hpp>
23 #include <boost/timer.hpp>
26 #define BOOST_UBLAS_NOT_USED(x) (void)(x)
29 namespace ublas = boost::numeric::ublas;
31 void header (std::string text);
35 void operator () (int multiplies, int plus, int runs, double elapsed) {
36 std::cout << "elapsed: " << elapsed << " s, "
37 << (multiplies * ublas::type_traits<T>::multiplies_complexity +
38 plus * ublas::type_traits<T>::plus_complexity) * runs /
39 (1024 * 1024 * elapsed) << " Mflops" << std::endl;
43 template<class T, int N>
44 struct c_vector_traits {
47 template<class T, int N, int M>
48 struct c_matrix_traits {
49 typedef T type [N] [M];
52 template<class T, int N>
53 struct initialize_c_vector {
54 void operator () (typename c_vector_traits<T, N>::type &v) {
55 for (int i = 0; i < N; ++ i)
56 v [i] = std::rand () * 1.f;
62 void initialize_vector (V &v) {
64 for (int i = 0; i < size; ++ i)
65 v [i] = std::rand () * 1.f;
69 template<class T, int N, int M>
70 struct initialize_c_matrix {
71 void operator () (typename c_matrix_traits<T, N, M>::type &m) {
72 for (int i = 0; i < N; ++ i)
73 for (int j = 0; j < M; ++ j)
74 m [i] [j] = std::rand () * 1.f;
80 void initialize_matrix (M &m) {
81 int size1 = m.size1 ();
82 int size2 = m.size2 ();
83 for (int i = 0; i < size1; ++ i)
84 for (int j = 0; j < size2; ++ j)
85 m (i, j) = std::rand () * 1.f;
91 void sink_scalar (const T &s) {
95 template<class T, int N>
96 struct sink_c_vector {
97 void operator () (const typename c_vector_traits<T, N>::type &v) {
98 static typename c_vector_traits<T, N>::type g_v;
99 for (int i = 0; i < N; ++ i)
105 void sink_vector (const V &v) {
109 template<class T, int N, int M>
110 struct sink_c_matrix {
111 void operator () (const typename c_matrix_traits<T, N, M>::type &m) {
112 static typename c_matrix_traits<T, N, M>::type g_m;
113 for (int i = 0; i < N; ++ i)
114 for (int j = 0; j < M; ++ j)
115 g_m [i] [j] = m [i] [j];
120 void sink_matrix (const M &m) {
126 void operator () (int runs);
129 template<class T, int N>
131 void operator () (int runs);
134 template<class T, int N>
136 void operator () (int runs);
139 template<class T, int N>
141 void operator () (int runs);
149 // #define USE_STD_COMPLEX
152 // #define USE_BOUNDED_ARRAY
153 #define USE_UNBOUNDED_ARRAY
154 // #define USE_STD_VALARRAY
155 //#define USE_STD_VECTOR