Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Superlu_FunctionMap.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
53 #ifndef AMESOS2_SUPERLU_FUNCTIONMAP_HPP
54 #define AMESOS2_SUPERLU_FUNCTIONMAP_HPP
55 
56 #ifdef HAVE_TEUCHOS_COMPLEX
57 #include <complex>
58 #endif
59 
60 #include "Amesos2_FunctionMap.hpp"
62 
63 
64 /* External definitions of the Superlu functions
65  *
66  * Note that we do include the "slu_*defs.h" files provided for each
67  * data-type. This produces linker warnings, but keeps us from
68  * including SuperLU code in our own code (even if only extern
69  * declarations, which would eliminate linker warnings). This is
70  * because there are several declarations (as of SuperLU 4.1) across
71  * these headers which conflict with each other in C linkage. All of
72  * the conflicting functions, on the other hand, we do not care about.
73  */
74 namespace SLU {
75 
76  extern "C" {
77  typedef int int_t;
78 #include "supermatrix.h"
79 #include "slu_util.h"
80 
81  namespace S { // single-precision real definitions
82  extern void
83  sgssvx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
84  char *, float *, float *, SLU::SuperMatrix *, SLU::SuperMatrix *,
85  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
86  float *, float *, float *, float *,
87  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
88  extern void
89  sgstrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
90  int, int, int*, void *, int, int *, int *,
91  SLU::SuperMatrix *, SLU::SuperMatrix *, SLU::SuperLUStat_t*, int *);
92  extern void
93  sCreate_CompCol_Matrix(SLU::SuperMatrix *, int, int, int, float *,
94  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
95  extern void
96  sCreate_CompRow_Matrix(SLU::SuperMatrix *, int, int, int, float *,
97  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
98  extern void
99  sCreate_Dense_Matrix(SLU::SuperMatrix *, int, int, float *, int,
100  SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
101 
102  extern void
103  sgsequ (SLU::SuperMatrix *, float *, float *, float *,
104  float *, float *, int *);
105 
106  extern void
107  slaqgs (SLU::SuperMatrix *, float *, float *, float,
108  float, float, char *);
109 
110 //#include "slu_sdefs.h"
111  }
112 
113  namespace D { // double-precision real definitions
114  extern void
115  dgssvx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
116  char *, double *, double *, SLU::SuperMatrix *, SLU::SuperMatrix *,
117  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
118  double *, double *, double *, double *,
119  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
120  extern void
121  dgstrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
122  int, int, int*, void *, int, int *, int *,
123  SLU::SuperMatrix *, SLU::SuperMatrix *, SLU::SuperLUStat_t*, int *);
124  extern void
125  dCreate_CompCol_Matrix(SLU::SuperMatrix *, int, int, int, double *,
126  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
127  extern void
128  dCreate_CompRow_Matrix(SLU::SuperMatrix *, int, int, int, double *,
129  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
130  extern void
131  dCreate_Dense_Matrix(SLU::SuperMatrix *, int, int, double *, int,
132  SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
133 
134  extern void
135  dlaqgs (SLU::SuperMatrix *, double *, double *, double,
136  double, double, char *);
137 
138  extern void
139  dgsequ (SLU::SuperMatrix *, double *, double *, double *,
140  double *, double *, int *);
141 
142 //#include "slu_ddefs.h"
143  }
144 
145 #ifdef HAVE_TEUCHOS_COMPLEX
146  namespace C { // single-precision complex definitions
147  extern void
148  cgssvx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
149  char *, float *, float *, SLU::SuperMatrix *, SLU::SuperMatrix *,
150  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
151  float *, float *, float *, float *,
152  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
153  extern void
154  cgstrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
155  int, int, int*, void *, int, int *, int *,
156  SLU::SuperMatrix *, SLU::SuperMatrix *, SLU::SuperLUStat_t*, int *);
157  extern void
158  cCreate_CompCol_Matrix(SLU::SuperMatrix *, int, int, int, complex *,
159  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
160  extern void
161  cCreate_CompRow_Matrix(SLU::SuperMatrix *, int, int, int, complex *,
162  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
163  extern void
164  cCreate_Dense_Matrix(SLU::SuperMatrix *, int, int, complex *, int,
165  SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
166 
167  extern void
168  cgsequ (SLU::SuperMatrix *, float *, float *, float *,
169  float *, float *, int *);
170 
171  extern void
172  claqgs (SLU::SuperMatrix *, float *, float *, float,
173  float, float, char *);
174 
175 //#include "slu_cdefs.h"
176  }
177 
178  namespace Z { // double-precision complex definitions
179  extern void
180  zgssvx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
181  char *, double *, double *, SLU::SuperMatrix *, SLU::SuperMatrix *,
182  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
183  double *, double *, double *, double *,
184  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
185  extern void
186  zgstrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
187  int, int, int*, void *, int, int *, int *,
188  SLU::SuperMatrix *, SLU::SuperMatrix *, SLU::SuperLUStat_t*, int *);
189  extern void
190  zCreate_CompCol_Matrix(SLU::SuperMatrix *, int, int, int, doublecomplex *,
191  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
192  extern void
193  zCreate_CompRow_Matrix(SLU::SuperMatrix *, int, int, int, doublecomplex *,
194  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
195  extern void
196  zCreate_Dense_Matrix(SLU::SuperMatrix *, int, int, doublecomplex *, int,
197  SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
198 
199  extern void
200  zgsequ (SLU::SuperMatrix *, double *, double *, double *,
201  double *, double *, int *);
202 
203  extern void
204  zlaqgs (SLU::SuperMatrix *, double *, double *, double,
205  double, double, char *);
206 
207 //#include "slu_zdefs.h"
208  }
209 #endif // HAVE_TEUCHOS_COMPLEX
210 
211  } // end extern "C"
212 
213 } // end namespace SLU
214 
215 
216 namespace Amesos2 {
217 
218  /* ==================== Specializations ====================
219  *
220  * \cond Superlu_function_specializations
221  */
222 
246  template <>
247  struct FunctionMap<Superlu,float>
248  {
249  typedef TypeMap<Superlu,float> type_map;
250 
254  static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
255  int* perm_c, int* perm_r, int* etree, char* equed, float* R, float* C,
256  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
257  SLU::SuperMatrix* B, SLU::SuperMatrix* X, float* recip_pivot_growth,
258  float* rcond, float* ferr, float* berr, SLU::mem_usage_t* mem_usage,
259  SLU::SuperLUStat_t* stat, int* info)
260  {
261  SLU::S::sgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
262  lwork, B, X, recip_pivot_growth, rcond, ferr, berr, mem_usage, stat, info);
263  }
264 
284  static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
285  int relax, int panel_size, int* etree, void* work,
286  int lwork, int* perm_c, int* perm_r, SLU::SuperMatrix* L,
287  SLU::SuperMatrix* U, SLU::SuperLUStat_t* stat, int* info)
288  {
289  SLU::S::sgstrf(options, AC, relax, panel_size, etree,
290  work, lwork, perm_c, perm_r, L, U, stat, info);
291  }
292 
296  static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n,
297  int nnz, type_map::type* nzval, int* rowind, int* colptr,
298  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
299  {
300  SLU::S::sCreate_CompCol_Matrix(A, m, n, nnz, nzval, rowind, colptr,
301  stype, dtype, mtype);
302  }
303 
307  static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n,
308  int nnz, type_map::type* nzval, int* rowind, int* colptr,
309  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
310  {
311  SLU::S::sCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
312  stype, dtype, mtype);
313  }
314 
315 
324  static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
325  type_map::type* x, int ldx, SLU::Stype_t stype,
326  SLU::Dtype_t dtype, SLU::Mtype_t mtype)
327  {
328  SLU::S::sCreate_Dense_Matrix(X, m, n, x, ldx, stype, dtype, mtype);
329  }
330 
334  static void gsequ(SLU::SuperMatrix* A, float* R, float* C,
335  float* rowcnd, float* colcnd, float* amax, int* info)
336  {
337  SLU::S::sgsequ(A, R, C, rowcnd, colcnd, amax, info);
338  }
339 
354  static void laqgs(SLU::SuperMatrix* A, float* R, float* C,
355  float rowcnd, float colcnd, float amax, char* equed)
356  {
357  SLU::S::slaqgs(A, R, C, rowcnd, colcnd, amax, equed);
358  }
359  };
360 
361 
362  template <>
363  struct FunctionMap<Superlu,double>
364  {
365  typedef TypeMap<Superlu,double> type_map;
366 
367  static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
368  int* perm_c, int* perm_r, int* etree, char* equed, double* R, double* C,
369  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
370  SLU::SuperMatrix* B, SLU::SuperMatrix* X, double* recip_pivot_growth,
371  double* rcond, double* ferr, double* berr, SLU::mem_usage_t* mem_usage,
372  SLU::SuperLUStat_t* stat, int* info)
373  {
374  SLU::D::dgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
375  lwork, B, X, recip_pivot_growth, rcond, ferr, berr, mem_usage, stat, info);
376  }
377 
378  static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
379  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
380  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
381  SLU::SuperLUStat_t* stat, int* info)
382  {
383  SLU::D::dgstrf(options, AC, relax, panel_size, etree,
384  work, lwork, perm_c, perm_r, L, U, stat, info);
385  }
386 
387  static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n,
388  int nnz, type_map::type* nzval, int* rowind, int* colptr,
389  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
390  {
391  SLU::D::dCreate_CompCol_Matrix(A, m, n, nnz, nzval, rowind, colptr,
392  stype, dtype, mtype);
393  }
394 
395  static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n,
396  int nnz, type_map::type* nzval, int* rowind, int* colptr,
397  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
398  {
399  SLU::D::dCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
400  stype, dtype, mtype);
401  }
402 
403  static void create_Dense_Matrix(SLU::SuperMatrix* X, int m,
404  int n, type_map::type* x, int ldx, SLU::Stype_t stype,
405  SLU::Dtype_t dtype, SLU::Mtype_t mtype)
406  {
407  SLU::D::dCreate_Dense_Matrix(X, m, n, x, ldx, stype, dtype, mtype);
408  }
409 
410  static void gsequ(SLU::SuperMatrix* A, double* R, double* C,
411  double* rowcnd, double* colcnd, double* amax, int* info)
412  {
413  SLU::D::dgsequ(A, R, C, rowcnd, colcnd, amax, info);
414  }
415 
416  static void laqgs(SLU::SuperMatrix* A, double* R, double* C,
417  double rowcnd, double colcnd, double amax, char* equed)
418  {
419  SLU::D::dlaqgs(A, R, C, rowcnd, colcnd, amax, equed);
420  }
421 
422  };
423 
424 
425 #ifdef HAVE_TEUCHOS_COMPLEX
426 
427  /* The specializations for Teuchos::as<> for SLU::complex and
428  * SLU::doublecomplex are provided in Amesos2_Superlu_Type.hpp
429  */
430  template <>
431  struct FunctionMap<Superlu,SLU::C::complex>
432  {
433  static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
434  int* perm_c, int* perm_r, int* etree, char* equed, float* R, float* C,
435  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
436  SLU::SuperMatrix* B, SLU::SuperMatrix* X, float* recip_pivot_growth,
437  float* rcond, float* ferr, float* berr, SLU::mem_usage_t* mem_usage,
438  SLU::SuperLUStat_t* stat, int* info)
439  {
440  SLU::C::cgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
441  lwork, B, X, recip_pivot_growth, rcond, ferr, berr, mem_usage, stat, info);
442  }
443 
444  static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
445  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
446  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
447  SLU::SuperLUStat_t* stat, int* info)
448  {
449  SLU::C::cgstrf(options, AC, relax, panel_size, etree,
450  work, lwork, perm_c, perm_r, L, U, stat, info);
451  }
452 
453  static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
454  SLU::C::complex* nzval, int* rowind, int* colptr,
455  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
456  {
457  SLU::C::cCreate_CompCol_Matrix(A, m, n, nnz, nzval, rowind, colptr,
458  stype, dtype, mtype);
459  }
460 
461  static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
462  SLU::C::complex* nzval, int* rowind, int* colptr,
463  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
464  {
465  SLU::C::cCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
466  stype, dtype, mtype);
467  }
468 
469  static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
470  SLU::C::complex* x, int ldx, SLU::Stype_t stype,
471  SLU::Dtype_t dtype, SLU::Mtype_t mtype)
472  {
473  SLU::C::cCreate_Dense_Matrix(X, m, n, x, ldx, stype, dtype, mtype);
474  }
475 
476  static void gsequ(SLU::SuperMatrix* A, float* R, float* C,
477  float* rowcnd, float* colcnd, float* amax, int* info)
478  {
479  SLU::C::cgsequ(A, R, C, rowcnd, colcnd, amax, info);
480  }
481 
482  static void laqgs(SLU::SuperMatrix* A, float* R, float* C,
483  float rowcnd, float colcnd, float amax, char* equed)
484  {
485  SLU::C::claqgs(A, R, C, rowcnd, colcnd, amax, equed);
486  }
487  };
488 
489 
490  template <>
491  struct FunctionMap<Superlu,SLU::Z::doublecomplex>
492  {
493  static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
494  int* perm_c, int* perm_r, int* etree, char* equed, double* R, double* C,
495  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
496  SLU::SuperMatrix* B, SLU::SuperMatrix* X, double* recip_pivot_growth,
497  double* rcond, double* ferr, double* berr, SLU::mem_usage_t* mem_usage,
498  SLU::SuperLUStat_t* stat, int* info)
499  {
500  SLU::Z::zgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
501  lwork, B, X, recip_pivot_growth, rcond, ferr, berr, mem_usage, stat, info);
502  }
503 
504  static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
505  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
506  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
507  SLU::SuperLUStat_t* stat, int* info)
508  {
509  SLU::Z::zgstrf(options, AC, relax, panel_size, etree,
510  work, lwork, perm_c, perm_r, L, U, stat, info);
511  }
512 
513  static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
514  SLU::Z::doublecomplex* nzval, int* rowind, int* colptr,
515  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
516  {
517  SLU::Z::zCreate_CompCol_Matrix(A, m, n, nnz, nzval, rowind, colptr,
518  stype, dtype, mtype);
519 
520  TEUCHOS_TEST_FOR_EXCEPTION( A == NULL,
521  std::runtime_error,
522  "Supermatrix A not initialized properly!");
523  }
524 
525 
526  static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
527  SLU::Z::doublecomplex* nzval, int* rowind, int* colptr,
528  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
529  {
530  SLU::Z::zCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
531  stype, dtype, mtype);
532 
533  TEUCHOS_TEST_FOR_EXCEPTION( A == NULL,
534  std::runtime_error,
535  "Supermatrix A not initialized properly!");
536  }
537 
538  static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
539  SLU::Z::doublecomplex* x, int ldx, SLU::Stype_t stype,
540  SLU::Dtype_t dtype, SLU::Mtype_t mtype)
541  {
542  SLU::Z::zCreate_Dense_Matrix(X, m, n, x, ldx, stype, dtype, mtype);
543  }
544 
545  static void gsequ(SLU::SuperMatrix* A, double* R, double* C,
546  double* rowcnd, double* colcnd, double* amax, int* info)
547  {
548  SLU::Z::zgsequ(A, R, C, rowcnd, colcnd, amax, info);
549  }
550 
551  static void laqgs(SLU::SuperMatrix* A, double* R, double* C,
552  double rowcnd, double colcnd, double amax, char* equed)
553  {
554  SLU::Z::zlaqgs(A, R, C, rowcnd, colcnd, amax, equed);
555  }
556  };
557 #endif // HAVE_TEUCHOS_COMPLEX
558 
559  /* \endcond Superlu_function_specializations */
560 
561 
562 } // end namespace Amesos2
563 
564 #endif // AMESOS2_SUPERLU_FUNCTIONMAP_HPP
Declaration of Function mapping class for Amesos2.
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
Provides definition of SuperLU types as well as conversions and type traits.
Definition: Amesos2_Superlu_FunctionMap.hpp:74