1 | // |
---|
2 | // Copyright (c) 2000-2002 |
---|
3 | // Joerg Walter, Mathias Koch |
---|
4 | // |
---|
5 | // Permission to use, copy, modify, distribute and sell this software |
---|
6 | // and its documentation for any purpose is hereby granted without fee, |
---|
7 | // provided that the above copyright notice appear in all copies and |
---|
8 | // that both that copyright notice and this permission notice appear |
---|
9 | // in supporting documentation. The authors make no representations |
---|
10 | // about the suitability of this software for any purpose. |
---|
11 | // It is provided "as is" without express or implied warranty. |
---|
12 | // |
---|
13 | // The authors gratefully acknowledge the support of |
---|
14 | // GeNeSys mbH & Co. KG in producing this work. |
---|
15 | // |
---|
16 | |
---|
17 | #ifndef BENCH3_H |
---|
18 | #define BENCH3_H |
---|
19 | |
---|
20 | #include <iostream> |
---|
21 | #include <string> |
---|
22 | #include <valarray> |
---|
23 | |
---|
24 | #include <boost/numeric/ublas/vector.hpp> |
---|
25 | #include <boost/numeric/ublas/vector_proxy.hpp> |
---|
26 | #include <boost/numeric/ublas/matrix.hpp> |
---|
27 | #include <boost/numeric/ublas/matrix_proxy.hpp> |
---|
28 | |
---|
29 | #include <boost/timer.hpp> |
---|
30 | |
---|
31 | namespace ublas = boost::numeric::ublas; |
---|
32 | |
---|
33 | void header (std::string text); |
---|
34 | |
---|
35 | template<class T> |
---|
36 | struct footer { |
---|
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; |
---|
42 | } |
---|
43 | }; |
---|
44 | |
---|
45 | template<class T, int N> |
---|
46 | struct c_vector_traits { |
---|
47 | typedef T type [N]; |
---|
48 | }; |
---|
49 | template<class T, int N, int M> |
---|
50 | struct c_matrix_traits { |
---|
51 | typedef T type [N] [M]; |
---|
52 | }; |
---|
53 | |
---|
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; |
---|
59 | // v [i] = 0.f; |
---|
60 | } |
---|
61 | }; |
---|
62 | template<class V> |
---|
63 | BOOST_UBLAS_INLINE |
---|
64 | void initialize_vector (V &v) { |
---|
65 | int size = v.size (); |
---|
66 | for (int i = 0; i < size; ++ i) |
---|
67 | v [i] = std::rand () * 1.f; |
---|
68 | // v [i] = 0.f; |
---|
69 | } |
---|
70 | |
---|
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; |
---|
77 | // m [i] [j] = 0.f; |
---|
78 | } |
---|
79 | }; |
---|
80 | template<class M> |
---|
81 | BOOST_UBLAS_INLINE |
---|
82 | void initialize_matrix (M &m) { |
---|
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; |
---|
88 | // m (i, j) = 0.f; |
---|
89 | } |
---|
90 | |
---|
91 | template<class T> |
---|
92 | BOOST_UBLAS_INLINE |
---|
93 | void sink_scalar (const T &s) { |
---|
94 | static T g_s = s; |
---|
95 | } |
---|
96 | |
---|
97 | template<class T, int N> |
---|
98 | struct sink_c_vector { |
---|
99 | void operator () (const typename c_vector_traits<T, N>::type &v) { |
---|
100 | static typename c_vector_traits<T, N>::type g_v; |
---|
101 | for (int i = 0; i < N; ++ i) |
---|
102 | g_v [i] = v [i]; |
---|
103 | } |
---|
104 | }; |
---|
105 | template<class V> |
---|
106 | BOOST_UBLAS_INLINE |
---|
107 | void sink_vector (const V &v) { |
---|
108 | static V g_v (v); |
---|
109 | } |
---|
110 | |
---|
111 | template<class T, int N, int M> |
---|
112 | struct sink_c_matrix { |
---|
113 | void operator () (const typename c_matrix_traits<T, N, M>::type &m) { |
---|
114 | static typename c_matrix_traits<T, N, M>::type g_m; |
---|
115 | for (int i = 0; i < N; ++ i) |
---|
116 | for (int j = 0; j < M; ++ j) |
---|
117 | g_m [i] [j] = m [i] [j]; |
---|
118 | } |
---|
119 | }; |
---|
120 | template<class M> |
---|
121 | BOOST_UBLAS_INLINE |
---|
122 | void sink_matrix (const M &m) { |
---|
123 | static M g_m (m); |
---|
124 | } |
---|
125 | |
---|
126 | template<class T> |
---|
127 | struct peak { |
---|
128 | void operator () (int runs); |
---|
129 | }; |
---|
130 | |
---|
131 | template<class T, int N> |
---|
132 | struct bench_1 { |
---|
133 | void operator () (int runs); |
---|
134 | }; |
---|
135 | |
---|
136 | template<class T, int N> |
---|
137 | struct bench_2 { |
---|
138 | void operator () (int runs); |
---|
139 | }; |
---|
140 | |
---|
141 | template<class T, int N> |
---|
142 | struct bench_3 { |
---|
143 | void operator () (int runs); |
---|
144 | }; |
---|
145 | |
---|
146 | struct safe_tag {}; |
---|
147 | struct fast_tag {}; |
---|
148 | |
---|
149 | // #define USE_FLOAT |
---|
150 | #define USE_DOUBLE |
---|
151 | // #define USE_STD_COMPLEX |
---|
152 | |
---|
153 | #define USE_C_ARRAY |
---|
154 | // #define USE_BOUNDED_ARRAY |
---|
155 | #define USE_UNBOUNDED_ARRAY |
---|
156 | // #define USE_STD_VALARRAY |
---|
157 | #define USE_STD_VECTOR |
---|
158 | |
---|
159 | #endif |
---|