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