1 |
commit: 637d5057499669550edd1a3e14bf49664808198f |
2 |
Author: Andrea Arteaga <andyspiros <AT> gmail <DOT> com> |
3 |
AuthorDate: Sun Jul 29 16:53:26 2012 +0000 |
4 |
Commit: Andrea Arteaga <andyspiros <AT> gmail <DOT> com> |
5 |
CommitDate: Sun Jul 29 16:53:26 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=637d5057 |
7 |
|
8 |
New BTL module lapacke. |
9 |
|
10 |
--- |
11 |
btl/libs/LAPACK/lapack_.hh | 2 + |
12 |
btl/libs/LAPACK/lapack_interface.hh | 33 +++------ |
13 |
btl/libs/LAPACK/lapack_interface_impl.hh | 4 +- |
14 |
btl/libs/LAPACK/lapacke_interface_impl.hh | 101 +++++++++++++++++++++++++++++ |
15 |
btl/libs/LAPACK/main.cpp | 86 ++++++++++++------------ |
16 |
5 files changed, 160 insertions(+), 66 deletions(-) |
17 |
|
18 |
diff --git a/btl/libs/LAPACK/lapack_.hh b/btl/libs/LAPACK/lapack_.hh |
19 |
index e7c8c3f..bc56dda 100644 |
20 |
--- a/btl/libs/LAPACK/lapack_.hh |
21 |
+++ b/btl/libs/LAPACK/lapack_.hh |
22 |
@@ -32,6 +32,8 @@ void LAPACKFUNC(gesvd)(const char*, const char*, const int*, const int*, SCALAR* |
23 |
void LAPACKFUNC(syev)(const char*, const char*, const int*, SCALAR*, const int*, SCALAR*, SCALAR*, const int*, int*); |
24 |
void LAPACKFUNC(stev)(const char*, const int*, SCALAR*, SCALAR*, SCALAR*, const int*, SCALAR*, int*); |
25 |
|
26 |
+void LAPACKFUNC(gels)(char*, int*, int*, int*, SCALAR*, int*, SCALAR*, int*, SCALAR*, int*, int*); |
27 |
+ |
28 |
#ifdef __cplusplus |
29 |
} |
30 |
#endif |
31 |
|
32 |
diff --git a/btl/libs/LAPACK/lapack_interface.hh b/btl/libs/LAPACK/lapack_interface.hh |
33 |
index a0ec52b..87b3cbb 100644 |
34 |
--- a/btl/libs/LAPACK/lapack_interface.hh |
35 |
+++ b/btl/libs/LAPACK/lapack_interface.hh |
36 |
@@ -20,26 +20,7 @@ |
37 |
|
38 |
#include <../BLAS/c_interface_base.h> |
39 |
#include <complex> |
40 |
-#include "lapack.hh" |
41 |
- |
42 |
-extern "C" { |
43 |
-#include "../BLAS/blas.h" |
44 |
- |
45 |
-//void sgesv_(int*, int*, float *, int*, int*, float *, int*, int*); |
46 |
-//void dgesv_(int*, int*, double*, int*, int*, double*, int*, int*); |
47 |
- |
48 |
-void sgels_(char*, int*, int*, int*, float *, int*, float *, int*, float *, int*, int*); |
49 |
-void dgels_(char*, int*, int*, int*, double*, int*, double*, int*, double*, int*, int*); |
50 |
- |
51 |
-//void sgetrf_(int*, int*, float *, int*, int*, int*); |
52 |
-//void dgetrf_(int*, int*, double*, int*, int*, int*); |
53 |
- |
54 |
-//void spotrf_(char*, int*, float *, int*, int*); |
55 |
-//void dpotrf_(char*, int*, double*, int*, int*); |
56 |
- |
57 |
-//void ssyev_(char*, char*, int*, float *, int*, float *, float *, int*, int*); |
58 |
-//void dsyev_(char*, char*, int*, double*, int*, double*, double*, int*, int*); |
59 |
-} |
60 |
+//#include "lapack.hh" |
61 |
|
62 |
|
63 |
#define MAKE_STRING2(S) #S |
64 |
@@ -65,13 +46,21 @@ static int zeroint = 0; |
65 |
|
66 |
#define SCALAR float |
67 |
#define SCALAR_PREFIX s |
68 |
-#include "lapack_interface_impl.hh" |
69 |
+#ifdef LAPACKE_INTERFACE |
70 |
+# include "lapacke_interface_impl.hh" |
71 |
+#else |
72 |
+# include "lapack_interface_impl.hh" |
73 |
+#endif |
74 |
#undef SCALAR |
75 |
#undef SCALAR_PREFIX |
76 |
|
77 |
#define SCALAR double |
78 |
#define SCALAR_PREFIX d |
79 |
-#include "lapack_interface_impl.hh" |
80 |
+#ifdef LAPACKE_INTERFACE |
81 |
+# include "lapacke_interface_impl.hh" |
82 |
+#else |
83 |
+# include "lapack_interface_impl.hh" |
84 |
+#endif |
85 |
#undef SCALAR |
86 |
#undef SCALAR_PREFIX |
87 |
|
88 |
|
89 |
diff --git a/btl/libs/LAPACK/lapack_interface_impl.hh b/btl/libs/LAPACK/lapack_interface_impl.hh |
90 |
index a95bc5b..523e53a 100644 |
91 |
--- a/btl/libs/LAPACK/lapack_interface_impl.hh |
92 |
+++ b/btl/libs/LAPACK/lapack_interface_impl.hh |
93 |
@@ -17,6 +17,9 @@ |
94 |
// |
95 |
#define LAPACKFUNC(NAME) CAT(CAT(SCALAR_PREFIX,NAME),_) |
96 |
|
97 |
+#include "lapack_.hh" |
98 |
+#include "blas.h" |
99 |
+ |
100 |
template<> class lapack_interface<SCALAR> : public c_interface_base<SCALAR> |
101 |
{ |
102 |
public: |
103 |
@@ -114,7 +117,6 @@ public: |
104 |
static inline void stev(const gene_vector& D, const gene_vector& E, gene_vector& W, gene_matrix& V, const int& N) |
105 |
{ |
106 |
int N0 = N; |
107 |
- int N1 = N-1; |
108 |
LAPACKFUNC(copy)(&N0, D, &intone, W, &intone); |
109 |
stl_vector E_(E, E+N-1), work(max(1, 2*N-2)); |
110 |
|
111 |
|
112 |
diff --git a/btl/libs/LAPACK/lapacke_interface_impl.hh b/btl/libs/LAPACK/lapacke_interface_impl.hh |
113 |
new file mode 100644 |
114 |
index 0000000..eef3638 |
115 |
--- /dev/null |
116 |
+++ b/btl/libs/LAPACK/lapacke_interface_impl.hh |
117 |
@@ -0,0 +1,101 @@ |
118 |
+//===================================================== |
119 |
+// Copyright (C) 2012 Andrea Arteaga <andyspiros@×××××.com> |
120 |
+//===================================================== |
121 |
+// |
122 |
+// This program is free software; you can redistribute it and/or |
123 |
+// modify it under the terms of the GNU General Public License |
124 |
+// as published by the Free Software Foundation; either version 2 |
125 |
+// of the License, or (at your option) any later version. |
126 |
+// |
127 |
+// This program is distributed in the hope that it will be useful, |
128 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of |
129 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
130 |
+// GNU General Public License for more details. |
131 |
+// You should have received a copy of the GNU General Public License |
132 |
+// along with this program; if not, write to the Free Software |
133 |
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
134 |
+// |
135 |
+#define LAPACKEFUNC(NAME) CAT(LAPACKE_,CAT(SCALAR_PREFIX,NAME)) |
136 |
+#define BLASFUNC(NAME) CAT(CAT(SCALAR_PREFIX,NAME),_) |
137 |
+ |
138 |
+#include "lapacke.h" |
139 |
+ |
140 |
+ |
141 |
+// Define BLAS functions used by LAPACKE interface |
142 |
+extern "C" { |
143 |
+ int BLASFUNC(copy) (int *, SCALAR*, int *, SCALAR*, int *); |
144 |
+} |
145 |
+ |
146 |
+template<> class lapack_interface<SCALAR> : public c_interface_base<SCALAR> |
147 |
+{ |
148 |
+public: |
149 |
+ |
150 |
+ static inline std::string name() |
151 |
+ { |
152 |
+ return MAKE_STRING(LAPACKNAME); |
153 |
+ } |
154 |
+ |
155 |
+ static inline void general_solve(gene_matrix& A, gene_vector& b, gene_vector& x, int N) |
156 |
+ { |
157 |
+ std::vector<int> ipiv(N); |
158 |
+ BLASFUNC(copy)(&N, b, &intone, x, &intone); |
159 |
+ LAPACKEFUNC(gesv)(LAPACK_COL_MAJOR, N, 1, A, N, &ipiv[0], x, N); |
160 |
+ } |
161 |
+ |
162 |
+ static inline void least_squares(gene_matrix& A, gene_vector& b, gene_vector& x, int N) |
163 |
+ { |
164 |
+ BLASFUNC(copy)(&N, b, &intone, x, &intone); |
165 |
+ LAPACKEFUNC(gels)(LAPACK_COL_MAJOR, 'N', N, N, 1, A, N, x, N); |
166 |
+ } |
167 |
+ |
168 |
+ static inline void lu_decomp(const gene_matrix& X, gene_matrix& C, int N) |
169 |
+ { |
170 |
+ int N2 = N*N; |
171 |
+ std::vector<int> ipiv(N); |
172 |
+ BLASFUNC(copy)(&N2, X, &intone, C, &intone); |
173 |
+ LAPACKEFUNC(getrf)(LAPACK_COL_MAJOR, N, N, C, N, &ipiv[0]); |
174 |
+ } |
175 |
+ |
176 |
+ static inline void cholesky(const gene_matrix& X, gene_matrix& C, int N) |
177 |
+ { |
178 |
+ int N2 = N*N; |
179 |
+ BLASFUNC(copy)(&N2, X, &intone, C, &intone); |
180 |
+ LAPACKEFUNC(potrf)(LAPACK_COL_MAJOR, 'L', N, C, N); |
181 |
+ } |
182 |
+ |
183 |
+ static inline void qr_decomp(const gene_matrix& X, gene_matrix& QR, gene_vector& tau, const int& N) |
184 |
+ { |
185 |
+ int N2 = N*N; |
186 |
+ BLASFUNC(copy)(&N2, X, &intone, QR, &intone); |
187 |
+ LAPACKEFUNC(geqrf)(LAPACK_COL_MAJOR, N, N, QR, N, tau); |
188 |
+ } |
189 |
+ |
190 |
+ static inline void svd_decomp(const gene_matrix& X, gene_matrix& U, gene_vector& S, gene_matrix& VT, const int& N) |
191 |
+ { |
192 |
+ int N2 = N*N; |
193 |
+ stl_vector Xcopy(N2), superb(N-1); |
194 |
+ BLASFUNC(copy)(&N2, X, &intone, &Xcopy[0], &intone); |
195 |
+ LAPACKEFUNC(gesvd)(LAPACK_COL_MAJOR, 'A', 'A', N, N, &Xcopy[0], N, S, U, N, VT, N, &superb[0]); |
196 |
+ } |
197 |
+ |
198 |
+ static inline void syev(const gene_matrix& X, gene_matrix& V, gene_vector& W, const int& N) |
199 |
+ { |
200 |
+ int N2 = N*N; |
201 |
+ BLASFUNC(copy)(&N2, X, &intone, V, &intone); |
202 |
+ LAPACKEFUNC(syev)(LAPACK_COL_MAJOR, 'V', 'U', N, V, N, W); |
203 |
+ } |
204 |
+ |
205 |
+ /* Size of D, W: N; size of E: N-1, size of V: NxN */ |
206 |
+ static inline void stev(const gene_vector& D, const gene_vector& E, gene_vector& W, gene_matrix& V, int N) |
207 |
+ { |
208 |
+ stl_vector E_(E, E+N-1); |
209 |
+ BLASFUNC(copy)(&N, D, &intone, W, &intone); |
210 |
+ LAPACKEFUNC(stev)(LAPACK_COL_MAJOR, 'V', N, W, &E_[0], V, N); |
211 |
+ } |
212 |
+ |
213 |
+ static inline void symm_ev(const gene_matrix& X, gene_vector& W, int N) |
214 |
+ { |
215 |
+ LAPACKEFUNC(syev)(LAPACK_COL_MAJOR, 'N', 'L', N, X, N, W); |
216 |
+ } |
217 |
+ |
218 |
+}; |
219 |
|
220 |
diff --git a/btl/libs/LAPACK/main.cpp b/btl/libs/LAPACK/main.cpp |
221 |
index e70c161..78f314a 100644 |
222 |
--- a/btl/libs/LAPACK/main.cpp |
223 |
+++ b/btl/libs/LAPACK/main.cpp |
224 |
@@ -35,61 +35,61 @@ BTL_MAIN; |
225 |
|
226 |
int main(int argc, char **argv) |
227 |
{ |
228 |
- bool |
229 |
- general_solve=false, least_squares=false, lu_decomp=false, cholesky=false, qr_decomp=false, svd_decomp=false, |
230 |
- syev=false, stev=false, symm_ev=false |
231 |
- ; |
232 |
- int N = 100; |
233 |
+ bool |
234 |
+ general_solve=false, least_squares=false, lu_decomp=false, cholesky=false, |
235 |
+ qr_decomp=false, svd_decomp=false, syev=false, stev=false, |
236 |
+ symm_ev=false; |
237 |
+ int N = 100; |
238 |
|
239 |
|
240 |
- for (int i = 1; i < argc; ++i) { |
241 |
- std::string arg = argv[i]; |
242 |
- if (arg == "general_solve") general_solve = true; |
243 |
- else if (arg == "least_squares") least_squares = true; |
244 |
- else if (arg == "lu_decomp") lu_decomp = true; |
245 |
- else if (arg == "cholesky") cholesky = true; |
246 |
- else if (arg == "qr_decomp") qr_decomp = true; |
247 |
- else if (arg == "svd_decomp") svd_decomp = true; |
248 |
- else if (arg == "syev") syev = true; |
249 |
- else if (arg == "stev") stev = true; |
250 |
- else if (arg == "symm_ev") symm_ev = true; |
251 |
+ for (int i = 1; i < argc; ++i) { |
252 |
+ std::string arg = argv[i]; |
253 |
+ if (arg == "general_solve") general_solve = true; |
254 |
+ else if (arg == "least_squares") least_squares = true; |
255 |
+ else if (arg == "lu_decomp") lu_decomp = true; |
256 |
+ else if (arg == "cholesky") cholesky = true; |
257 |
+ else if (arg == "qr_decomp") qr_decomp = true; |
258 |
+ else if (arg == "svd_decomp") svd_decomp = true; |
259 |
+ else if (arg == "syev") syev = true; |
260 |
+ else if (arg == "stev") stev = true; |
261 |
+ else if (arg == "symm_ev") symm_ev = true; |
262 |
|
263 |
- // Check switch -N |
264 |
- else if (arg[0] == '-' && arg[1] == 'N') { |
265 |
- if (arg[2] != '\0') |
266 |
- N = atoi(arg.c_str()+2); |
267 |
- else |
268 |
- N = atoi(argv[++i]); |
269 |
- } |
270 |
- } |
271 |
+ // Check switch -N |
272 |
+ else if (arg[0] == '-' && arg[1] == 'N') { |
273 |
+ if (arg[2] != '\0') |
274 |
+ N = atoi(arg.c_str()+2); |
275 |
+ else |
276 |
+ N = atoi(argv[++i]); |
277 |
+ } |
278 |
+ } |
279 |
|
280 |
|
281 |
- if (general_solve) |
282 |
- bench<Action_general_solve<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
283 |
+ if (general_solve) |
284 |
+ bench<Action_general_solve<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
285 |
|
286 |
- if (least_squares) |
287 |
- bench<Action_least_squares<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
288 |
+ if (least_squares) |
289 |
+ bench<Action_least_squares<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
290 |
|
291 |
- if (lu_decomp) |
292 |
- bench<Action_lu_decomp<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
293 |
+ if (lu_decomp) |
294 |
+ bench<Action_lu_decomp<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
295 |
|
296 |
- if (cholesky) |
297 |
- bench<Action_cholesky<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
298 |
+ if (cholesky) |
299 |
+ bench<Action_cholesky<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
300 |
|
301 |
- if (qr_decomp) |
302 |
- bench<Action_qr_decomp<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
303 |
+ if (qr_decomp) |
304 |
+ bench<Action_qr_decomp<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
305 |
|
306 |
- if (svd_decomp) |
307 |
- bench<Action_svd_decomp<lapack_interface<REAL_TYPE> > >(MIN_MM,750,N); |
308 |
+ if (svd_decomp) |
309 |
+ bench<Action_svd_decomp<lapack_interface<REAL_TYPE> > >(MIN_MM,750,N); |
310 |
|
311 |
- if (syev) |
312 |
- bench<Action_syev<lapack_interface<REAL_TYPE> > >(MIN_MM,750,N); |
313 |
+ if (syev) |
314 |
+ bench<Action_syev<lapack_interface<REAL_TYPE> > >(MIN_MM,750,N); |
315 |
|
316 |
- if (stev) |
317 |
- bench<Action_stev<lapack_interface<REAL_TYPE> > >(MIN_MM,1000,N); |
318 |
+ if (stev) |
319 |
+ bench<Action_stev<lapack_interface<REAL_TYPE> > >(MIN_MM,1000,N); |
320 |
|
321 |
- if (symm_ev) |
322 |
- bench<Action_symm_ev<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
323 |
+ if (symm_ev) |
324 |
+ bench<Action_symm_ev<lapack_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,N); |
325 |
|
326 |
- return 0; |
327 |
+ return 0; |
328 |
} |