]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // Copyright (c) 2000-2002 | |
3 | // Joerg Walter, Mathias Koch | |
4 | // | |
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) | |
8 | // | |
9 | // The authors gratefully acknowledge the support of | |
10 | // GeNeSys mbH & Co. KG in producing this work. | |
11 | // | |
12 | ||
13 | #ifndef BENCH1_H | |
14 | #define BENCH1_H | |
15 | ||
16 | #include <iostream> | |
17 | #include <string> | |
18 | #include <valarray> | |
19 | ||
20 | #include <boost/numeric/ublas/vector.hpp> | |
21 | #include <boost/numeric/ublas/matrix.hpp> | |
22 | ||
23 | #include <boost/timer.hpp> | |
24 | ||
25 | ||
26 | #define BOOST_UBLAS_NOT_USED(x) (void)(x) | |
27 | ||
28 | ||
29 | namespace ublas = boost::numeric::ublas; | |
30 | ||
31 | void header (std::string text); | |
32 | ||
33 | template<class T> | |
34 | struct footer { | |
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; | |
40 | } | |
41 | }; | |
42 | ||
43 | template<class T, int N> | |
44 | struct c_vector_traits { | |
45 | typedef T type [N]; | |
46 | }; | |
47 | template<class T, int N, int M> | |
48 | struct c_matrix_traits { | |
49 | typedef T type [N] [M]; | |
50 | }; | |
51 | ||
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; | |
57 | // v [i] = 0.f; | |
58 | } | |
59 | }; | |
60 | template<class V> | |
61 | BOOST_UBLAS_INLINE | |
62 | void initialize_vector (V &v) { | |
63 | int size = v.size (); | |
64 | for (int i = 0; i < size; ++ i) | |
65 | v [i] = std::rand () * 1.f; | |
66 | // v [i] = 0.f; | |
67 | } | |
68 | ||
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; | |
75 | // m [i] [j] = 0.f; | |
76 | } | |
77 | }; | |
78 | template<class M> | |
79 | BOOST_UBLAS_INLINE | |
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; | |
86 | // m (i, j) = 0.f; | |
87 | } | |
88 | ||
89 | template<class T> | |
90 | BOOST_UBLAS_INLINE | |
91 | void sink_scalar (const T &s) { | |
92 | static T g_s = s; | |
93 | } | |
94 | ||
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) | |
100 | g_v [i] = v [i]; | |
101 | } | |
102 | }; | |
103 | template<class V> | |
104 | BOOST_UBLAS_INLINE | |
105 | void sink_vector (const V &v) { | |
106 | static V g_v (v); | |
107 | } | |
108 | ||
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]; | |
116 | } | |
117 | }; | |
118 | template<class M> | |
119 | BOOST_UBLAS_INLINE | |
120 | void sink_matrix (const M &m) { | |
121 | static M g_m (m); | |
122 | } | |
123 | ||
124 | template<class T> | |
125 | struct peak { | |
126 | void operator () (int runs); | |
127 | }; | |
128 | ||
129 | template<class T, int N> | |
130 | struct bench_1 { | |
131 | void operator () (int runs); | |
132 | }; | |
133 | ||
134 | template<class T, int N> | |
135 | struct bench_2 { | |
136 | void operator () (int runs); | |
137 | }; | |
138 | ||
139 | template<class T, int N> | |
140 | struct bench_3 { | |
141 | void operator () (int runs); | |
142 | }; | |
143 | ||
144 | struct safe_tag {}; | |
145 | struct fast_tag {}; | |
146 | ||
147 | //#define USE_FLOAT | |
148 | #define USE_DOUBLE | |
149 | // #define USE_STD_COMPLEX | |
150 | ||
151 | #define USE_C_ARRAY | |
152 | // #define USE_BOUNDED_ARRAY | |
153 | #define USE_UNBOUNDED_ARRAY | |
154 | // #define USE_STD_VALARRAY | |
155 | //#define USE_STD_VECTOR | |
156 | ||
157 | #endif | |
158 | ||
159 |