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 #include "superlu_enum_consts.h"
81 
82 void
83 at_plus_a(
84  const int n, /* number of columns in matrix A. */
85  const int nz, /* number of nonzeros in matrix A */
86  int *colptr, /* column pointer of size n+1 for matrix A. */
87  int *rowind, /* row indices of size nz for matrix A. */
88  int *bnz, /* out - on exit, returns the actual number of
89  nonzeros in matrix A'*A. */
90  int **b_colptr, /* out - size n+1 */
91  int **b_rowind /* out - size *bnz */
92  );
93 
94 
95  namespace S { // single-precision real definitions
96 
97 #ifdef HAVE_AMESOS2_SUPERLU5_API
98  typedef struct {
99  int *xsup; /* supernode and column mapping */
100  int *supno;
101  int *lsub; /* compressed L subscripts */
102  int *xlsub;
103  float *lusup; /* L supernodes */
104  int *xlusup;
105  float *ucol; /* U columns */
106  int *usub;
107  int *xusub;
108  int nzlmax; /* current max size of lsub */
109  int nzumax; /* " " " ucol */
110  int nzlumax; /* " " " lusup */
111  int n; /* number of columns in the matrix */
112  LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */
113  int num_expansions;
114  ExpHeader *expanders; /* Array of pointers to 4 types of memory */
115  LU_stack_t stack; /* use user supplied memory */
116  } GlobalLU_t;
117 #endif
118 
119  extern void
120  sCompRow_to_CompCol(int, int, int, float*, int*, int*,
121  float **, int **, int **);
122  extern void
123  sgssvx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
124  char *, float *, float *, SLU::SuperMatrix *, SLU::SuperMatrix *,
125  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
126  float *, float *, float *, float *,
127 #ifdef HAVE_AMESOS2_SUPERLU5_API
128  GlobalLU_t*,
129 #endif
130  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
131  extern void
132  sgstrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
133  int, int, int*, void *, int, int *, int *,
134  SLU::SuperMatrix *, SLU::SuperMatrix *,
135 #ifdef HAVE_AMESOS2_SUPERLU5_API
136  GlobalLU_t*,
137 #endif
138  SLU::SuperLUStat_t*, int *);
139  extern void
140  sgsisx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
141  char *, float *, float *, SLU::SuperMatrix *, SLU::SuperMatrix *,
142  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
143  float *, float *,
144 #ifdef HAVE_AMESOS2_SUPERLU5_API
145  GlobalLU_t*,
146 #endif
147  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
148  extern void
149  sgsitrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
150  int, int, int*, void *, int, int *, int *,
151  SLU::SuperMatrix *, SLU::SuperMatrix *,
152 #ifdef HAVE_AMESOS2_SUPERLU5_API
153  GlobalLU_t*,
154 #endif
155  SLU::SuperLUStat_t*, int *);
156  extern void
157  sCreate_CompCol_Matrix(SLU::SuperMatrix *, int, int, int, float *,
158  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
159  extern void
160  sCreate_CompRow_Matrix(SLU::SuperMatrix *, int, int, int, float *,
161  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
162  extern void
163  sCreate_Dense_Matrix(SLU::SuperMatrix *, int, int, float *, int,
164  SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
165 
166  extern void
167  sgsequ (SLU::SuperMatrix *, float *, float *, float *,
168  float *, float *, int *);
169 
170  extern void
171  slaqgs (SLU::SuperMatrix *, float *, float *, float,
172  float, float, char *);
173 
174 //#include "slu_sdefs.h"
175  }
176 
177  namespace D { // double-precision real definitions
178 
179 #ifdef HAVE_AMESOS2_SUPERLU5_API
180  typedef struct {
181  int *xsup; /* supernode and column mapping */
182  int *supno;
183  int *lsub; /* compressed L subscripts */
184  int *xlsub;
185  double *lusup; /* L supernodes */
186  int *xlusup;
187  double *ucol; /* U columns */
188  int *usub;
189  int *xusub;
190  int nzlmax; /* current max size of lsub */
191  int nzumax; /* " " " ucol */
192  int nzlumax; /* " " " lusup */
193  int n; /* number of columns in the matrix */
194  LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */
195  int num_expansions;
196  ExpHeader *expanders; /* Array of pointers to 4 types of memory */
197  LU_stack_t stack; /* use user supplied memory */
198  } GlobalLU_t;
199 #endif
200 
201  extern void
202  dCompRow_to_CompCol(int, int, int, double*, int*, int*,
203  double **, int **, int **);
204  extern void
205  dgssvx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
206  char *, double *, double *, SLU::SuperMatrix *, SLU::SuperMatrix *,
207  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
208  double *, double *, double *, double *,
209 #ifdef HAVE_AMESOS2_SUPERLU5_API
210  GlobalLU_t*,
211 #endif
212  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
213  extern void
214  dgstrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
215  int, int, int*, void *, int, int *, int *,
216  SLU::SuperMatrix *, SLU::SuperMatrix *,
217 #ifdef HAVE_AMESOS2_SUPERLU5_API
218  GlobalLU_t*,
219 #endif
220  SLU::SuperLUStat_t*, int *);
221  extern void
222  dgsisx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
223  char *, double *, double *, SLU::SuperMatrix *, SLU::SuperMatrix *,
224  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
225  double *, double *,
226 #ifdef HAVE_AMESOS2_SUPERLU5_API
227  GlobalLU_t*,
228 #endif
229  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
230  extern void
231  dgsitrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
232  int, int, int*, void *, int, int *, int *,
233  SLU::SuperMatrix *, SLU::SuperMatrix *,
234 #ifdef HAVE_AMESOS2_SUPERLU5_API
235  GlobalLU_t*,
236 #endif
237  SLU::SuperLUStat_t*, int *);
238  extern void
239  dCreate_CompCol_Matrix(SLU::SuperMatrix *, int, int, int, double *,
240  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
241  extern void
242  dCreate_CompRow_Matrix(SLU::SuperMatrix *, int, int, int, double *,
243  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
244  extern void
245  dCreate_Dense_Matrix(SLU::SuperMatrix *, int, int, double *, int,
246  SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
247 
248  extern void
249  dlaqgs (SLU::SuperMatrix *, double *, double *, double,
250  double, double, char *);
251 
252  extern void
253  dgsequ (SLU::SuperMatrix *, double *, double *, double *,
254  double *, double *, int *);
255 
256 //#include "slu_ddefs.h"
257  }
258 
259 #ifdef HAVE_TEUCHOS_COMPLEX
260  namespace C { // single-precision complex definitions
261 
262 #ifdef HAVE_AMESOS2_SUPERLU5_API
263  typedef struct {
264  int *xsup; /* supernode and column mapping */
265  int *supno;
266  int *lsub; /* compressed L subscripts */
267  int *xlsub;
268  complex *lusup; /* L supernodes */
269  int *xlusup;
270  complex *ucol; /* U columns */
271  int *usub;
272  int *xusub;
273  int nzlmax; /* current max size of lsub */
274  int nzumax; /* " " " ucol */
275  int nzlumax; /* " " " lusup */
276  int n; /* number of columns in the matrix */
277  LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */
278  int num_expansions;
279  ExpHeader *expanders; /* Array of pointers to 4 types of memory */
280  LU_stack_t stack; /* use user supplied memory */
281  } GlobalLU_t;
282 #endif
283 
284  extern void
285  cCompRow_to_CompCol(int, int, int, complex*, int*, int*,
286  complex **, int **, int **);
287  extern void
288  cgssvx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
289  char *, float *, float *, SLU::SuperMatrix *, SLU::SuperMatrix *,
290  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
291  float *, float *, float *, float *,
292 #ifdef HAVE_AMESOS2_SUPERLU5_API
293  GlobalLU_t*,
294 #endif
295  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
296  extern void
297  cgstrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
298  int, int, int*, void *, int, int *, int *,
299  SLU::SuperMatrix *, SLU::SuperMatrix *,
300 #ifdef HAVE_AMESOS2_SUPERLU5_API
301  GlobalLU_t*,
302 #endif
303  SLU::SuperLUStat_t*, int *);
304  extern void
305  cgsisx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
306  char *, float *, float *, SLU::SuperMatrix *, SLU::SuperMatrix *,
307  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
308  float *, float *,
309 #ifdef HAVE_AMESOS2_SUPERLU5_API
310  GlobalLU_t*,
311 #endif
312  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
313  extern void
314  cgsitrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
315  int, int, int*, void *, int, int *, int *,
316  SLU::SuperMatrix *, SLU::SuperMatrix *,
317 #ifdef HAVE_AMESOS2_SUPERLU5_API
318  GlobalLU_t*,
319 #endif
320  SLU::SuperLUStat_t*, int *);
321  extern void
322  cCreate_CompCol_Matrix(SLU::SuperMatrix *, int, int, int, complex *,
323  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
324  extern void
325  cCreate_CompRow_Matrix(SLU::SuperMatrix *, int, int, int, complex *,
326  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
327  extern void
328  cCreate_Dense_Matrix(SLU::SuperMatrix *, int, int, complex *, int,
329  SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
330 
331  extern void
332  cgsequ (SLU::SuperMatrix *, float *, float *, float *,
333  float *, float *, int *);
334 
335  extern void
336  claqgs (SLU::SuperMatrix *, float *, float *, float,
337  float, float, char *);
338 
339 //#include "slu_cdefs.h"
340  }
341 
342  namespace Z { // double-precision complex definitions
343 
344 #ifdef HAVE_AMESOS2_SUPERLU5_API
345  typedef struct {
346  int *xsup; /* supernode and column mapping */
347  int *supno;
348  int *lsub; /* compressed L subscripts */
349  int *xlsub;
350  doublecomplex *lusup; /* L supernodes */
351  int *xlusup;
352  doublecomplex *ucol; /* U columns */
353  int *usub;
354  int *xusub;
355  int nzlmax; /* current max size of lsub */
356  int nzumax; /* " " " ucol */
357  int nzlumax; /* " " " lusup */
358  int n; /* number of columns in the matrix */
359  LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */
360  int num_expansions;
361  ExpHeader *expanders; /* Array of pointers to 4 types of memory */
362  LU_stack_t stack; /* use user supplied memory */
363  } GlobalLU_t;
364 #endif
365 
366  extern void
367  zCompRow_to_CompCol(int, int, int, doublecomplex*, int*, int*,
368  doublecomplex **, int **, int **);
369  extern void
370  zgssvx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
371  char *, double *, double *, SLU::SuperMatrix *, SLU::SuperMatrix *,
372  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
373  double *, double *, double *, double *,
374 #ifdef HAVE_AMESOS2_SUPERLU5_API
375  GlobalLU_t*,
376 #endif
377  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
378  extern void
379  zgstrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
380  int, int, int*, void *, int, int *, int *,
381  SLU::SuperMatrix *, SLU::SuperMatrix *,
382 #ifdef HAVE_AMESOS2_SUPERLU5_API
383  GlobalLU_t*,
384 #endif
385  SLU::SuperLUStat_t*, int *);
386  extern void
387  zgsisx(SLU::superlu_options_t *, SLU::SuperMatrix *, int *, int *, int *,
388  char *, double *, double *, SLU::SuperMatrix *, SLU::SuperMatrix *,
389  void *, int, SLU::SuperMatrix *, SLU::SuperMatrix *,
390  double *, double *,
391 #ifdef HAVE_AMESOS2_SUPERLU5_API
392  GlobalLU_t*,
393 #endif
394  SLU::mem_usage_t *, SLU::SuperLUStat_t *, int *);
395  extern void
396  zgsitrf (SLU::superlu_options_t*, SLU::SuperMatrix*,
397  int, int, int*, void *, int, int *, int *,
398  SLU::SuperMatrix *, SLU::SuperMatrix *,
399 #ifdef HAVE_AMESOS2_SUPERLU5_API
400  GlobalLU_t*,
401 #endif
402  SLU::SuperLUStat_t*, int *);
403  extern void
404  zCreate_CompCol_Matrix(SLU::SuperMatrix *, int, int, int, doublecomplex *,
405  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
406  extern void
407  zCreate_CompRow_Matrix(SLU::SuperMatrix *, int, int, int, doublecomplex *,
408  int *, int *, SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
409  extern void
410  zCreate_Dense_Matrix(SLU::SuperMatrix *, int, int, doublecomplex *, int,
411  SLU::Stype_t, SLU::Dtype_t, SLU::Mtype_t);
412 
413  extern void
414  zgsequ (SLU::SuperMatrix *, double *, double *, double *,
415  double *, double *, int *);
416 
417  extern void
418  zlaqgs (SLU::SuperMatrix *, double *, double *, double,
419  double, double, char *);
420 
421 //#include "slu_zdefs.h"
422  }
423 #endif // HAVE_TEUCHOS_COMPLEX
424 
425  } // end extern "C"
426 
427 } // end namespace SLU
428 
429 
430 namespace Amesos2 {
431 
432  /* ==================== Specializations ====================
433  *
434  * \cond Superlu_function_specializations
435  */
436 
460  template <>
461  struct FunctionMap<Superlu,float>
462  {
463  typedef TypeMap<Superlu,float> type_map;
464 
465 #ifdef HAVE_AMESOS2_SUPERLU5_API
466  typedef typename SLU::S::GlobalLU_t GlobalLU_type;
467 #endif
468 
472  static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
473  int* perm_c, int* perm_r, int* etree, char* equed, float* R, float* C,
474  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
475  SLU::SuperMatrix* B, SLU::SuperMatrix* X, float* recip_pivot_growth,
476  float* rcond, float* ferr, float* berr,
477 #ifdef HAVE_AMESOS2_SUPERLU5_API
478  GlobalLU_type* lu,
479 #endif
480  SLU::mem_usage_t* mem_usage,
481  SLU::SuperLUStat_t* stat, int* info)
482  {
483  SLU::S::sgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
484  lwork, B, X, recip_pivot_growth, rcond, ferr, berr,
485 #ifdef HAVE_AMESOS2_SUPERLU5_API
486  lu,
487 #endif
488  mem_usage, stat, info);
489  }
490 
491  static void gsisx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
492  int* perm_c, int* perm_r, int* etree, char* equed, float* R, float* C,
493  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
494  SLU::SuperMatrix* B, SLU::SuperMatrix* X, float* recip_pivot_growth,
495  float* rcond,
496 #ifdef HAVE_AMESOS2_SUPERLU5_API
497  GlobalLU_type* lu,
498 #endif
499  SLU::mem_usage_t* mem_usage,
500  SLU::SuperLUStat_t* stat, int* info)
501  {
502  SLU::S::sgsisx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
503  lwork, B, X, recip_pivot_growth, rcond,
504 #ifdef HAVE_AMESOS2_SUPERLU5_API
505  lu,
506 #endif
507  mem_usage, stat, info);
508  }
509 
529  static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
530  int relax, int panel_size, int* etree, void* work,
531  int lwork, int* perm_c, int* perm_r, SLU::SuperMatrix* L,
532  SLU::SuperMatrix* U,
533 #ifdef HAVE_AMESOS2_SUPERLU5_API
534  GlobalLU_type* lu,
535 #endif
536  SLU::SuperLUStat_t* stat, int* info)
537  {
538  SLU::S::sgstrf(options, AC, relax, panel_size, etree,
539  work, lwork, perm_c, perm_r, L, U,
540 #ifdef HAVE_AMESOS2_SUPERLU5_API
541  lu,
542 #endif
543  stat, info);
544  }
545 
546  static void gsitrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
547  int relax, int panel_size, int* etree, void* work,
548  int lwork, int* perm_c, int* perm_r, SLU::SuperMatrix* L,
549  SLU::SuperMatrix* U,
550 #ifdef HAVE_AMESOS2_SUPERLU5_API
551  GlobalLU_type* lu,
552 #endif
553  SLU::SuperLUStat_t* stat, int* info)
554  {
555  SLU::S::sgsitrf(options, AC, relax, panel_size, etree,
556  work, lwork, perm_c, perm_r, L, U,
557 #ifdef HAVE_AMESOS2_SUPERLU5_API
558  lu,
559 #endif
560  stat, info);
561  }
562 
566  template<class view_t>
567  static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
568  Teuchos::Array<float> & convert_nzval, view_t & nzval,
569  int* rowind, int* colptr,
570  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
571  {
572  // conversion not necessay - pass view data directly
573  SLU::S::sCreate_CompCol_Matrix(A, m, n, nnz, nzval.data(), rowind, colptr,
574  stype, dtype, mtype);
575  }
576 
580  static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n,
581  int nnz, float* nzval, int* rowind, int* colptr,
582  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
583  {
584  SLU::S::sCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
585  stype, dtype, mtype);
586  }
587 
588 
597  template<class view_t>
598  static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
599  Teuchos::Array<float> & convert_x, view_t & x,
600  int ldx, SLU::Stype_t stype,
601  SLU::Dtype_t dtype, SLU::Mtype_t mtype)
602  {
603  // conversion not necessay - pass view data directly
604  SLU::S::sCreate_Dense_Matrix(X, m, n, x.data(), ldx, stype, dtype, mtype);
605  }
606 
607  template<class view_t>
608  static void convert_back_Dense_Matrix(
609  Teuchos::Array<float> & convert_x, view_t & x)
610  {
611  // conversion not necessay - pass view data directly
612  }
613 
617  static void gsequ(SLU::SuperMatrix* A, float* R, float* C,
618  float* rowcnd, float* colcnd, float* amax, int* info)
619  {
620  SLU::S::sgsequ(A, R, C, rowcnd, colcnd, amax, info);
621  }
622 
637  static void laqgs(SLU::SuperMatrix* A, float* R, float* C,
638  float rowcnd, float colcnd, float amax, char* equed)
639  {
640  SLU::S::slaqgs(A, R, C, rowcnd, colcnd, amax, equed);
641  }
642  };
643 
644 
645  template <>
646  struct FunctionMap<Superlu,double>
647  {
648  typedef TypeMap<Superlu,double> type_map;
649 
650 #ifdef HAVE_AMESOS2_SUPERLU5_API
651  typedef typename SLU::D::GlobalLU_t GlobalLU_type;
652 #endif
653 
654  static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
655  int* perm_c, int* perm_r, int* etree, char* equed, double* R, double* C,
656  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
657  SLU::SuperMatrix* B, SLU::SuperMatrix* X, double* recip_pivot_growth,
658  double* rcond, double* ferr, double* berr,
659 #ifdef HAVE_AMESOS2_SUPERLU5_API
660  GlobalLU_type* lu,
661 #endif
662  SLU::mem_usage_t* mem_usage,
663  SLU::SuperLUStat_t* stat, int* info)
664  {
665  SLU::D::dgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
666  lwork, B, X, recip_pivot_growth, rcond, ferr, berr,
667 #ifdef HAVE_AMESOS2_SUPERLU5_API
668  lu,
669 #endif
670  mem_usage, stat, info);
671  }
672 
673  static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
674  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
675  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
676 #ifdef HAVE_AMESOS2_SUPERLU5_API
677  GlobalLU_type* lu,
678 #endif
679  SLU::SuperLUStat_t* stat, int* info)
680  {
681  SLU::D::dgstrf(options, AC, relax, panel_size, etree,
682  work, lwork, perm_c, perm_r, L, U,
683 #ifdef HAVE_AMESOS2_SUPERLU5_API
684  lu,
685 #endif
686  stat, info);
687  }
688 
689  static void gsisx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
690  int* perm_c, int* perm_r, int* etree, char* equed, double* R, double* C,
691  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
692  SLU::SuperMatrix* B, SLU::SuperMatrix* X, double* recip_pivot_growth,
693  double* rcond,
694 #ifdef HAVE_AMESOS2_SUPERLU5_API
695  GlobalLU_type* lu,
696 #endif
697  SLU::mem_usage_t* mem_usage,
698  SLU::SuperLUStat_t* stat, int* info)
699  {
700  SLU::D::dgsisx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
701  lwork, B, X, recip_pivot_growth, rcond,
702 #ifdef HAVE_AMESOS2_SUPERLU5_API
703  lu,
704 #endif
705  mem_usage, stat, info);
706  }
707 
708  static void gsitrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
709  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
710  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
711 #ifdef HAVE_AMESOS2_SUPERLU5_API
712  GlobalLU_type* lu,
713 #endif
714  SLU::SuperLUStat_t* stat, int* info)
715  {
716  SLU::D::dgsitrf(options, AC, relax, panel_size, etree,
717  work, lwork, perm_c, perm_r, L, U,
718 #ifdef HAVE_AMESOS2_SUPERLU5_API
719  lu,
720 #endif
721  stat, info);
722  }
723 
724  template<class view_t>
725  static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
726  Teuchos::Array<double> & convert_nzval, view_t & nzval,
727  int* rowind, int* colptr,
728  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
729  {
730  // conversion not necessay - pass view data directly
731  SLU::D::dCreate_CompCol_Matrix(A, m, n, nnz, nzval.data(), rowind, colptr,
732  stype, dtype, mtype);
733  }
734 
735  static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n,
736  int nnz, double* nzval, int* rowind, int* colptr,
737  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
738  {
739  SLU::D::dCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
740  stype, dtype, mtype);
741  }
742 
743  template<class view_t>
744  static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
745  Teuchos::Array<double> & convert_x, view_t & x,
746  int ldx, SLU::Stype_t stype,
747  SLU::Dtype_t dtype, SLU::Mtype_t mtype)
748  {
749  // conversion not necessay - pass view data directly
750  SLU::D::dCreate_Dense_Matrix(X, m, n, x.data(), ldx, stype, dtype, mtype);
751  }
752 
753  template<class view_t>
754  static void convert_back_Dense_Matrix(
755  Teuchos::Array<double> & convert_x, view_t & x)
756  {
757  // conversion not necessay - pass view data directly
758  }
759 
760  static void gsequ(SLU::SuperMatrix* A, double* R, double* C,
761  double* rowcnd, double* colcnd, double* amax, int* info)
762  {
763  SLU::D::dgsequ(A, R, C, rowcnd, colcnd, amax, info);
764  }
765 
766  static void laqgs(SLU::SuperMatrix* A, double* R, double* C,
767  double rowcnd, double colcnd, double amax, char* equed)
768  {
769  SLU::D::dlaqgs(A, R, C, rowcnd, colcnd, amax, equed);
770  }
771 
772  };
773 
774 
775 #ifdef HAVE_TEUCHOS_COMPLEX
776 
777  template <>
778  struct FunctionMap<Superlu, Kokkos::complex<float>>
779  {
780 #ifdef HAVE_AMESOS2_SUPERLU5_API
781  typedef typename SLU::C::GlobalLU_t GlobalLU_type;
782 #endif
783 
784  static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
785  int* perm_c, int* perm_r, int* etree, char* equed, float* R, float* C,
786  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
787  SLU::SuperMatrix* B, SLU::SuperMatrix* X, float* recip_pivot_growth,
788  float* rcond, float* ferr, float* berr,
789 #ifdef HAVE_AMESOS2_SUPERLU5_API
790  GlobalLU_type* lu,
791 #endif
792  SLU::mem_usage_t* mem_usage,
793  SLU::SuperLUStat_t* stat, int* info)
794  {
795  SLU::C::cgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
796  lwork, B, X, recip_pivot_growth, rcond, ferr, berr,
797 #ifdef HAVE_AMESOS2_SUPERLU5_API
798  lu,
799 #endif
800  mem_usage, stat, info);
801  }
802 
803  static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
804  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
805  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
806 #ifdef HAVE_AMESOS2_SUPERLU5_API
807  GlobalLU_type* lu,
808 #endif
809  SLU::SuperLUStat_t* stat, int* info)
810  {
811  SLU::C::cgstrf(options, AC, relax, panel_size, etree,
812  work, lwork, perm_c, perm_r, L, U,
813 #ifdef HAVE_AMESOS2_SUPERLU5_API
814  lu,
815 #endif
816  stat, info);
817  }
818 
819  static void gsisx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
820  int* perm_c, int* perm_r, int* etree, char* equed, float* R, float* C,
821  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
822  SLU::SuperMatrix* B, SLU::SuperMatrix* X, float* recip_pivot_growth,
823  float* rcond,
824 #ifdef HAVE_AMESOS2_SUPERLU5_API
825  GlobalLU_type* lu,
826 #endif
827  SLU::mem_usage_t* mem_usage,
828  SLU::SuperLUStat_t* stat, int* info)
829  {
830  SLU::C::cgsisx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
831  lwork, B, X, recip_pivot_growth, rcond,
832 #ifdef HAVE_AMESOS2_SUPERLU5_API
833  lu,
834 #endif
835  mem_usage, stat, info);
836  }
837 
838  static void gsitrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
839  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
840  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
841 #ifdef HAVE_AMESOS2_SUPERLU5_API
842  GlobalLU_type* lu,
843 #endif
844  SLU::SuperLUStat_t* stat, int* info)
845  {
846  SLU::C::cgsitrf(options, AC, relax, panel_size, etree,
847  work, lwork, perm_c, perm_r, L, U,
848 #ifdef HAVE_AMESOS2_SUPERLU5_API
849  lu,
850 #endif
851  stat, info);
852  }
853 
854  template<class view_t>
855  static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
856  Teuchos::Array<SLU::C::complex> & convert_nzval, view_t & nzval,
857  int* rowind, int* colptr,
858  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
859  {
860  convert_nzval.resize(nnz);
861  for(int i = 0; i < nnz; ++i) {
862  convert_nzval[i] = Teuchos::as<SLU::C::complex>(nzval(i));
863  }
864  SLU::C::cCreate_CompCol_Matrix(A, m, n, nnz, convert_nzval.data(), rowind, colptr,
865  stype, dtype, mtype);
866  }
867 
868  static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
869  SLU::C::complex* nzval, int* rowind, int* colptr,
870  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
871  {
872  SLU::C::cCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
873  stype, dtype, mtype);
874  }
875 
876  template<class view_t>
877  static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
878  Teuchos::Array<SLU::C::complex> & convert_x, view_t & x,
879  int ldx, SLU::Stype_t stype,
880  SLU::Dtype_t dtype, SLU::Mtype_t mtype)
881  {
882  convert_x.resize(m * n);
883  int write_index = 0;
884  for(int j = 0; j < n; ++j) {
885  for(int i = 0; i < m; ++i) { // layout left
886  convert_x[write_index++] = Teuchos::as<SLU::C::complex>(x(i,j));
887  }
888  }
889  SLU::C::cCreate_Dense_Matrix(X, m, n, convert_x.data(), ldx, stype, dtype, mtype);
890  }
891 
892  template<class view_t>
893  static void convert_back_Dense_Matrix(
894  Teuchos::Array<SLU::C::complex> & convert_x, view_t & x)
895  {
896  int read_index = 0;
897  for(int j = 0; j < static_cast<int>(x.extent(1)); ++j) {
898  for(int i = 0; i < static_cast<int>(x.extent(0)); ++i) { // layout left
899  x(i,j) = Teuchos::as<Kokkos::complex<float>>(convert_x[read_index++]);
900  }
901  }
902  }
903 
904  static void gsequ(SLU::SuperMatrix* A, float* R, float* C,
905  float* rowcnd, float* colcnd, float* amax, int* info)
906  {
907  SLU::C::cgsequ(A, R, C, rowcnd, colcnd, amax, info);
908  }
909 
910  static void laqgs(SLU::SuperMatrix* A, float* R, float* C,
911  float rowcnd, float colcnd, float amax, char* equed)
912  {
913  SLU::C::claqgs(A, R, C, rowcnd, colcnd, amax, equed);
914  }
915  };
916 
917 
918  template <>
919  struct FunctionMap<Superlu,Kokkos::complex<double>>
920  {
921 #ifdef HAVE_AMESOS2_SUPERLU5_API
922  typedef typename SLU::Z::GlobalLU_t GlobalLU_type;
923 #endif
924 
925  static void gssvx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
926  int* perm_c, int* perm_r, int* etree, char* equed, double* R, double* C,
927  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
928  SLU::SuperMatrix* B, SLU::SuperMatrix* X, double* recip_pivot_growth,
929  double* rcond, double* ferr, double* berr,
930 #ifdef HAVE_AMESOS2_SUPERLU5_API
931  GlobalLU_type* lu,
932 #endif
933  SLU::mem_usage_t* mem_usage,
934  SLU::SuperLUStat_t* stat, int* info)
935  {
936  SLU::Z::zgssvx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
937  lwork, B, X, recip_pivot_growth, rcond, ferr, berr,
938 #ifdef HAVE_AMESOS2_SUPERLU5_API
939  lu,
940 #endif
941  mem_usage, stat, info);
942  }
943 
944  static void gstrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
945  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
946  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
947 #ifdef HAVE_AMESOS2_SUPERLU5_API
948  GlobalLU_type* lu,
949 #endif
950  SLU::SuperLUStat_t* stat, int* info)
951  {
952  SLU::Z::zgstrf(options, AC, relax, panel_size, etree,
953  work, lwork, perm_c, perm_r, L, U,
954 #ifdef HAVE_AMESOS2_SUPERLU5_API
955  lu,
956 #endif
957  stat, info);
958  }
959 
960  static void gsisx(SLU::superlu_options_t* options, SLU::SuperMatrix* A,
961  int* perm_c, int* perm_r, int* etree, char* equed, double* R, double* C,
962  SLU::SuperMatrix* L, SLU::SuperMatrix* U, void* work, int lwork,
963  SLU::SuperMatrix* B, SLU::SuperMatrix* X, double* recip_pivot_growth,
964  double* rcond,
965 #ifdef HAVE_AMESOS2_SUPERLU5_API
966  GlobalLU_type* lu,
967 #endif
968  SLU::mem_usage_t* mem_usage,
969  SLU::SuperLUStat_t* stat, int* info)
970  {
971  SLU::Z::zgsisx(options, A, perm_c, perm_r, etree, equed, R, C, L, U, work,
972  lwork, B, X, recip_pivot_growth, rcond,
973 #ifdef HAVE_AMESOS2_SUPERLU5_API
974  lu,
975 #endif
976  mem_usage, stat, info);
977  }
978 
979  static void gsitrf(SLU::superlu_options_t* options, SLU::SuperMatrix* AC,
980  int relax, int panel_size, int* etree, void* work, int lwork, int* perm_c,
981  int* perm_r, SLU::SuperMatrix* L, SLU::SuperMatrix* U,
982 #ifdef HAVE_AMESOS2_SUPERLU5_API
983  GlobalLU_type* lu,
984 #endif
985  SLU::SuperLUStat_t* stat, int* info)
986  {
987  SLU::Z::zgsitrf(options, AC, relax, panel_size, etree,
988  work, lwork, perm_c, perm_r, L, U,
989 #ifdef HAVE_AMESOS2_SUPERLU5_API
990  lu,
991 #endif
992  stat, info);
993  }
994 
995  template<class view_t>
996  static void create_CompCol_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
997  Teuchos::Array<SLU::Z::doublecomplex> & convert_nzval, view_t & nzval,
998  int* rowind, int* colptr,
999  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
1000  {
1001  convert_nzval.resize(nnz);
1002  for(int i = 0; i < nnz; ++i) {
1003  convert_nzval[i] = Teuchos::as<SLU::Z::doublecomplex>(nzval(i));
1004  }
1005  SLU::Z::zCreate_CompCol_Matrix(A, m, n, nnz, convert_nzval.data(), rowind, colptr,
1006  stype, dtype, mtype);
1007 
1008  TEUCHOS_TEST_FOR_EXCEPTION( A == NULL,
1009  std::runtime_error,
1010  "Supermatrix A not initialized properly!");
1011  }
1012 
1013 
1014  static void create_CompRow_Matrix(SLU::SuperMatrix* A, int m, int n, int nnz,
1015  SLU::Z::doublecomplex* nzval, int* rowind, int* colptr,
1016  SLU::Stype_t stype, SLU::Dtype_t dtype, SLU::Mtype_t mtype)
1017  {
1018  SLU::Z::zCreate_CompRow_Matrix(A, m, n, nnz, nzval, rowind, colptr,
1019  stype, dtype, mtype);
1020 
1021  TEUCHOS_TEST_FOR_EXCEPTION( A == NULL,
1022  std::runtime_error,
1023  "Supermatrix A not initialized properly!");
1024  }
1025 
1026  template<class view_t>
1027  static void create_Dense_Matrix(SLU::SuperMatrix* X, int m, int n,
1028  Teuchos::Array<SLU::Z::doublecomplex> & convert_x, view_t & x,
1029  int ldx, SLU::Stype_t stype,
1030  SLU::Dtype_t dtype, SLU::Mtype_t mtype)
1031  {
1032  convert_x.resize(m * n);
1033  int write_index = 0;
1034  for(int j = 0; j < n; ++j) {
1035  for(int i = 0; i < m; ++i) { // layout left
1036  convert_x[write_index++] = Teuchos::as<SLU::Z::doublecomplex>(x(i,j));
1037  }
1038  }
1039  SLU::Z::zCreate_Dense_Matrix(X, m, n, convert_x.data(), ldx, stype, dtype, mtype);
1040  }
1041 
1042  template<class view_t>
1043  static void convert_back_Dense_Matrix(
1044  Teuchos::Array<SLU::Z::doublecomplex> & convert_x, view_t & x)
1045  {
1046  int read_index = 0;
1047  for(int j = 0; j < static_cast<int>(x.extent(1)); ++j) {
1048  for(int i = 0; i < static_cast<int>(x.extent(0)); ++i) { // layout left
1049  x(i,j) = Teuchos::as<Kokkos::complex<double>>(convert_x[read_index++]);
1050  }
1051  }
1052  }
1053 
1054  static void gsequ(SLU::SuperMatrix* A, double* R, double* C,
1055  double* rowcnd, double* colcnd, double* amax, int* info)
1056  {
1057  SLU::Z::zgsequ(A, R, C, rowcnd, colcnd, amax, info);
1058  }
1059 
1060  static void laqgs(SLU::SuperMatrix* A, double* R, double* C,
1061  double rowcnd, double colcnd, double amax, char* equed)
1062  {
1063  SLU::Z::zlaqgs(A, R, C, rowcnd, colcnd, amax, equed);
1064  }
1065  };
1066 #endif // HAVE_TEUCHOS_COMPLEX
1067 
1068  /* \endcond Superlu_function_specializations */
1069 
1070 
1071 } // end namespace Amesos2
1072 
1073 #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