Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Superludist_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_SUPERLUDIST_FUNCTIONMAP_HPP
54 #define AMESOS2_SUPERLUDIST_FUNCTIONMAP_HPP
55 
56 #ifdef HAVE_TEUCHOS_COMPLEX
57 #include <complex>
58 #endif
59 
60 #include "Amesos2_FunctionMap.hpp"
61 #include "Amesos2_MatrixAdapter.hpp"
63 
64 
65 // Declarations of SuperLU_DIST types and namespace are found in
66 // Superludist_TypeMap.hpp
67 
68 #define AMESOS2_SLUD_GET_DIAG_SCALE(eq) (((eq)=='N') ? SLUD::NOEQUIL : ((eq)=='R') ? SLUD::ROW : ((eq)=='C') ? SLUD::COL : SLUD::BOTH)
69 
70 #define AMESOS2_SLUD_GET_EQUED(ds) (((ds)==SLUD::NOEQUIL) ? 'N' : ((ds)==SLUD::ROW) ? 'R' : ((ds)=='C') ? SLUD::COL : SLUD::BOTH)
71 
72 namespace Amesos2 {
73 
74  template <class Matrix, class Vector> class Superludist;
75 
76  SLUD::DiagScale_t get_diag_scale(char eq);
77  char get_equed(SLUD::DiagScale_t ds);
78 
79 
80  /* ==================== Specializations ====================
81  *
82  * \cond SuperLU_DIST_function_specializations
83  */
84 
107  template <>
108  struct FunctionMap<Superludist,double>
109  {
110  typedef TypeMap<Superludist,double> type_map;
111 
125  static void gstrf(SLUD::superlu_options_t* options, int m, int n, double anorm,
126  type_map::LUstruct_t* LU, SLUD::gridinfo_t* grid, SLUD::SuperLUStat_t* stat,
127  int* info)
128  {
129  SLUD::D::pdgstrf(options, m, n, anorm, LU, grid, stat, info);
130  }
131 
136  static void gstrs(SLUD::int_t n, type_map::LUstruct_t* lu_struct,
137  SLUD::ScalePermstruct_t* scale_perm_struct, SLUD::gridinfo_t* grid,
138  type_map::type* B, SLUD::int_t l_numrows, SLUD::int_t fst_global_row,
139  SLUD::int_t ldb, int nrhs, type_map::SOLVEstruct_t* solve_struct,
140  SLUD::SuperLUStat_t* stat, int* info)
141  {
142  SLUD::D::pdgstrs(n, lu_struct, scale_perm_struct, grid, B, l_numrows,
143  fst_global_row, ldb, nrhs, solve_struct, stat, info);
144  }
145 
153  static void gstrs_Bglobal(SLUD::int_t n, type_map::LUstruct_t* lu_struct,
154  SLUD::gridinfo_t* grid, type_map::type* B,
155  SLUD::int_t ldb, int nrhs,
156  SLUD::SuperLUStat_t* stat, int* info)
157  {
158  SLUD::D::pdgstrs_Bglobal(n, lu_struct, grid, B, ldb, nrhs, stat, info);
159  }
160 
164  static void gsrfs(SLUD::int_t n, SLUD::SuperMatrix* A, double anorm,
165  type_map::LUstruct_t* lu_struct,
166  SLUD::ScalePermstruct_t* scale_perm,
167  SLUD::gridinfo_t* grid, type_map::type* B, SLUD::int_t ldb,
168  type_map::type* X, SLUD::int_t ldx, int nrhs,
169  type_map::SOLVEstruct_t* solve_struct, double* berr,
170  SLUD::SuperLUStat_t* stat, int* info)
171  {
172  SLUD::D::pdgsrfs(n, A, anorm, lu_struct, scale_perm, grid, B, ldb,
173  X, ldx, nrhs, solve_struct, berr, stat, info);
174  }
175 
183  static void gsrfs_ABXglobal(SLUD::int_t n, SLUD::SuperMatrix* A, double anorm,
184  type_map::LUstruct_t* lu_struct, SLUD::gridinfo_t* grid,
185  type_map::type* B, SLUD::int_t ldb, type_map::type* X,
186  SLUD::int_t ldx, int nrhs, double* berr,
187  SLUD::SuperLUStat_t* stat, int* info)
188  {
189  SLUD::D::pdgsrfs_ABXglobal(n, A, anorm, lu_struct, grid, B, ldb,
190  X, ldx, nrhs, berr, stat, info);
191  }
192 
197  static void create_CompRowLoc_Matrix(SLUD::SuperMatrix* A, SLUD::int_t g_numrows,
198  SLUD::int_t g_numcols, SLUD::int_t l_nnz,
199  SLUD::int_t l_numrows, SLUD::int_t fst_global_row,
200  type_map::type* nzval, SLUD::int_t* colind,
201  SLUD::int_t* rowptr, SLUD::Stype_t storage_t,
202  SLUD::Dtype_t data_t, SLUD::Mtype_t mat_t)
203  {
204  SLUD::D::dCreate_CompRowLoc_Matrix_dist(A, g_numrows, g_numcols, l_nnz,
205  l_numrows, fst_global_row,
206  nzval, colind, rowptr,
207  storage_t, data_t, mat_t);
208  }
209 
217  static void create_CompCol_Matrix(SLUD::SuperMatrix* A, SLUD::int_t numrows,
218  SLUD::int_t numcols, SLUD::int_t nnz,
219  type_map::type* nzval, SLUD::int_t* rowind,
220  SLUD::int_t* colptr, SLUD::Stype_t storage_t,
221  SLUD::Dtype_t data_t, SLUD::Mtype_t mat_t)
222  {
223  SLUD::D::dCreate_CompCol_Matrix_dist(A, numrows, numcols, nnz,
224  nzval, rowind, colptr,
225  storage_t, data_t, mat_t);
226  }
227 
236  static void create_Dense_Matrix(SLUD::SuperMatrix* X, int m, int n,
237  type_map::type* x, int ldx, SLUD::Stype_t stype,
238  SLUD::Dtype_t dtype, SLUD::Mtype_t mtype)
239  {
240  SLUD::D::dCreate_Dense_Matrix_dist(X, m, n, x, ldx, stype, dtype, mtype);
241  }
242 
243  static void permute_Dense_Matrix(SLUD::int_t fst_row, SLUD::int_t m_loc,
244  SLUD::int_t* row_to_proc, SLUD::int_t* perm,
245  type_map::type* X, int ldx, type_map::type* B,
246  int ldb, int nrhs, SLUD::gridinfo_t* grid)
247  {
248  SLUD::D::pdPermute_Dense_Matrix(fst_row, m_loc, row_to_proc, perm,
249  X, ldx, B, ldb, nrhs, grid);
250  }
251 
260  static void gsequ_loc(SLUD::SuperMatrix* A, double* r, double* c,
261  double* rowcnd, double* colcnd, double* amax, int* info,
262  SLUD::gridinfo_t* grid)
263  {
264  SLUD::D::pdgsequ(A, r, c, rowcnd, colcnd, amax, info, grid);
265  }
266 
271  static void gsequ(SLUD::SuperMatrix* A, double* r, double* c,
272  double* rowcnd, double* colcnd, double* amax, int* info)
273  {
274  SLUD::D::dgsequ_dist(A, r, c, rowcnd, colcnd, amax, info);
275  }
276 
280  static void laqgs_loc(SLUD::SuperMatrix* A, double* r, double* c,
281  double rowcnd, double colcnd, double amax,
282  SLUD::DiagScale_t* equed)
283  {
284  char eq = AMESOS2_SLUD_GET_EQUED(*equed);
285  SLUD::D::pdlaqgs(A, r, c, rowcnd, colcnd, amax, &eq);
286  *equed = AMESOS2_SLUD_GET_DIAG_SCALE(eq);
287  }
288 
302  static void laqgs(SLUD::SuperMatrix* A, double* r, double* c,
303  double rowcnd, double colcnd, double amax, SLUD::DiagScale_t* equed)
304  {
305  char eq = AMESOS2_SLUD_GET_EQUED(*equed);
306  SLUD::D::dlaqgs_dist(A, r, c, rowcnd, colcnd, amax, &eq);
307  *equed = AMESOS2_SLUD_GET_DIAG_SCALE(eq);
308  }
309 
310  /*
311  * This version suitable for A in NCPformat
312  */
313  static void distribute(SLUD::fact_t fact, SLUD::int_t n,
314  SLUD::SuperMatrix* A, SLUD::Glu_freeable_t* glu_freeable,
315  type_map::LUstruct_t* lu, SLUD::gridinfo_t* grid)
316  {
317  SLUD::D::ddistribute(fact, n, A, glu_freeable, lu, grid);
318  }
319 
320  /*
321  * This version suitable for A in NR_loc format.
322  *
323  * This routine should be used in the case where fact ==
324  * SamePattern_SameRowPerm, otherwise dist_psymbtonum should be
325  * called.o
326  */
327  static void pdistribute(SLUD::fact_t fact, SLUD::int_t n,
328  SLUD::SuperMatrix* A, SLUD::ScalePermstruct_t* scale_perm,
329  SLUD::Glu_freeable_t* glu_freeable, type_map::LUstruct_t* lu,
330  SLUD::gridinfo_t* grid)
331  {
332  SLUD::D::pddistribute(fact, n, A, scale_perm, glu_freeable, lu, grid);
333  }
334 
335  /*
336  * Distributes the input matrix A onto the 2D process grid based on
337  * the L/U graph data in pslu_freeable. On exit the struct lu
338  * contains the information necessary to perform a numeric
339  * factorization using gstrf.
340  *
341  * This routine should always be called with fact == DOFACT
342  */
343  static void dist_psymbtonum(SLUD::fact_t fact, SLUD::int_t n, SLUD::SuperMatrix* A,
344  SLUD::ScalePermstruct_t* scale_perm,
345  SLUD::Pslu_freeable_t* pslu_freeable,
346  type_map::LUstruct_t* lu, SLUD::gridinfo_t* grid)
347  {
348  SLUD::D::ddist_psymbtonum(fact, n, A, scale_perm, pslu_freeable, lu, grid);
349  }
350 
351  /*
352  * The parameter norm may be one of:
353  * - 'M' for the max absolute matrix entry value
354  * - '1' for the norm1(A)
355  * - 'I' for the normI(A)
356  * - 'F' for the Frobenius norm of A
357  */
358  static double plangs(char* norm, SLUD::SuperMatrix* A, SLUD::gridinfo_t* grid)
359  {
360  return SLUD::D::pdlangs(norm, A, grid);
361  }
362 
363  static void SolveInit(SLUD::superlu_options_t* options, SLUD::SuperMatrix* A,
364  SLUD::int_t* perm_r, SLUD::int_t* perm_c, SLUD::int_t nrhs,
365  type_map::LUstruct_t* lu, SLUD::gridinfo_t* grid,
366  type_map::SOLVEstruct_t* solve_struct)
367  {
368  SLUD::D::dSolveInit(options, A, perm_r, perm_c, nrhs, lu, grid, solve_struct);
369  }
370 
371  static void LUstructInit(SLUD::int_t m, SLUD::int_t n,
372  type_map::LUstruct_t* lu)
373  {
374  SLUD::D::LUstructInit(m, n, lu);
375  }
376 
377  static void Destroy_LU(SLUD::int_t m, SLUD::gridinfo_t* grid,
378  type_map::LUstruct_t* lu)
379  {
380  SLUD::D::Destroy_LU(m, grid, lu);
381  }
382 
383  static void LUstructFree(type_map::LUstruct_t* lu)
384  {
385  SLUD::D::LUstructFree(lu);
386  }
387 
388  static void SolveFinalize(SLUD::superlu_options_t* options,
389  type_map::SOLVEstruct_t* solve_struct)
390  {
391  SLUD::D::dSolveFinalize(options, solve_struct);
392  }
393  };
394 
395 
396 #ifdef HAVE_TEUCHOS_COMPLEX
397  /* The specializations for Teuchos::as<> for SLUD::complex and
398  * SLUD::doublecomplex are provided in Amesos2_Superlu_Type.hpp
399  */
400  template <>
401  struct FunctionMap<Superludist,SLUD::Z::doublecomplex>
402  {
403  typedef TypeMap<Superludist,std::complex<double> > type_map;
404 
405  static void gstrf(SLUD::superlu_options_t* options, int m, int n, double anorm,
406  type_map::LUstruct_t* LU, SLUD::gridinfo_t* grid,
407  SLUD::SuperLUStat_t* stat, int* info)
408  {
409  SLUD::Z::pzgstrf(options, m, n, anorm, LU, grid, stat, info);
410  }
411 
412  static void gstrs(SLUD::int_t n, type_map::LUstruct_t* lu_struct,
413  SLUD::ScalePermstruct_t* scale_perm_struct,
414  SLUD::gridinfo_t* grid, type_map::type* B,
415  SLUD::int_t l_numrows, SLUD::int_t fst_global_row,
416  SLUD::int_t ldb, int nrhs,
417  type_map::SOLVEstruct_t* solve_struct,
418  SLUD::SuperLUStat_t* stat, int* info)
419  {
420  SLUD::Z::pzgstrs(n, lu_struct, scale_perm_struct, grid, B, l_numrows,
421  fst_global_row, ldb, nrhs, solve_struct, stat, info);
422  }
423 
424  static void gstrs_Bglobal(SLUD::int_t n, type_map::LUstruct_t* lu_struct,
425  SLUD::gridinfo_t* grid, type_map::type* B,
426  SLUD::int_t ldb, int nrhs, SLUD::SuperLUStat_t* stat, int* info)
427  {
428  SLUD::Z::pzgstrs_Bglobal(n, lu_struct, grid, B, ldb, nrhs, stat, info);
429  }
430 
431  static void create_CompRowLoc_Matrix(SLUD::SuperMatrix* A, SLUD::int_t g_numrows,
432  SLUD::int_t g_numcols, SLUD::int_t l_nnz,
433  SLUD::int_t l_numrows, SLUD::int_t fst_global_row,
434  type_map::type* nzval, SLUD::int_t* colind,
435  SLUD::int_t* rowptr, SLUD::Stype_t storage_t,
436  SLUD::Dtype_t data_t, SLUD::Mtype_t mat_t)
437  {
438  SLUD::Z::zCreate_CompRowLoc_Matrix_dist(A, g_numrows, g_numcols, l_nnz,
439  l_numrows, fst_global_row,
440  nzval, colind, rowptr,
441  storage_t, data_t, mat_t);
442  }
443 
444  static void create_CompCol_Matrix(SLUD::SuperMatrix* A, SLUD::int_t numrows,
445  SLUD::int_t numcols, SLUD::int_t nnz,
446  type_map::type* nzval, SLUD::int_t* rowind,
447  SLUD::int_t* colptr, SLUD::Stype_t storage_t,
448  SLUD::Dtype_t data_t, SLUD::Mtype_t mat_t)
449  {
450  SLUD::Z::zCreate_CompCol_Matrix_dist(A, numrows, numcols, nnz,
451  nzval, rowind, colptr,
452  storage_t, data_t, mat_t);
453  }
454 
455  static void create_Dense_Matrix(SLUD::SuperMatrix* X, int m, int n,
456  TypeMap<Superludist,std::complex<double> >::type* x, int ldx,
457  SLUD::Stype_t stype, SLUD::Dtype_t dtype, SLUD::Mtype_t mtype)
458  {
459  SLUD::Z::zCreate_Dense_Matrix_dist(X, m, n, x, ldx, stype, dtype, mtype);
460  }
461 
462  static void permute_Dense_Matrix(SLUD::int_t fst_row, SLUD::int_t m_loc,
463  SLUD::int_t* row_to_proc, SLUD::int_t* perm,
464  type_map::type* X, int ldx,
465  type_map::type* B, int ldb,
466  int nrhs, SLUD::gridinfo_t* grid)
467  {
468  SLUD::Z::pzPermute_Dense_Matrix(fst_row, m_loc, row_to_proc, perm,
469  X, ldx, B, ldb, nrhs, grid);
470  }
471 
472  static void gsequ_loc(SLUD::SuperMatrix* A, double* r, double* c,
473  double* rowcnd, double* colcnd, double* amax, int* info,
474  SLUD::gridinfo_t* grid)
475  {
476  SLUD::Z::pzgsequ(A, r, c, rowcnd, colcnd, amax, info, grid);
477  }
478 
479  static void gsequ(SLUD::SuperMatrix* A, double* r, double* c,
480  double* rowcnd, double* colcnd, double* amax, int* info)
481  {
482  SLUD::Z::zgsequ_dist(A, r, c, rowcnd, colcnd, amax, info);
483  }
484 
485  static void laqgs_loc(SLUD::SuperMatrix* A, double* r, double* c,
486  double rowcnd, double colcnd, double amax, SLUD::DiagScale_t* equed)
487  {
488  char eq = AMESOS2_SLUD_GET_EQUED(*equed);
489  SLUD::Z::pzlaqgs(A, r, c, rowcnd, colcnd, amax, &eq);
490  *equed = AMESOS2_SLUD_GET_DIAG_SCALE(eq);
491  }
492 
493  static void laqgs(SLUD::SuperMatrix* A, double* r, double* c,
494  double rowcnd, double colcnd, double amax, SLUD::DiagScale_t* equed)
495  {
496  char eq = AMESOS2_SLUD_GET_EQUED(*equed);
497  SLUD::Z::zlaqgs_dist(A, r, c, rowcnd, colcnd, amax, &eq);
498  *equed = AMESOS2_SLUD_GET_DIAG_SCALE(eq);
499  }
500 
501  static void distribute(SLUD::fact_t fact, SLUD::int_t n,
502  SLUD::SuperMatrix* A, SLUD::Glu_freeable_t* glu_freeable,
503  type_map::LUstruct_t* lu, SLUD::gridinfo_t* grid)
504  {
505  SLUD::Z::zdistribute(fact, n, A, glu_freeable, lu, grid);
506  }
507 
508  static void pdistribute(SLUD::fact_t fact, SLUD::int_t n,
509  SLUD::SuperMatrix* A, SLUD::ScalePermstruct_t* scale_perm,
510  SLUD::Glu_freeable_t* glu_freeable, type_map::LUstruct_t* lu,
511  SLUD::gridinfo_t* grid)
512  {
513  SLUD::Z::pzdistribute(fact, n, A, scale_perm, glu_freeable, lu, grid);
514  }
515 
516  static void dist_psymbtonum(SLUD::fact_t fact, SLUD::int_t n,
517  SLUD::SuperMatrix* A, SLUD::ScalePermstruct_t* scale_perm,
518  SLUD::Pslu_freeable_t* pslu_freeable, type_map::LUstruct_t* lu,
519  SLUD::gridinfo_t* grid)
520  {
521  SLUD::Z::zdist_psymbtonum(fact, n, A, scale_perm, pslu_freeable, lu, grid);
522  }
523 
524  static double plangs(char* norm, SLUD::SuperMatrix* A, SLUD::gridinfo_t* grid)
525  {
526  return SLUD::Z::pzlangs(norm, A, grid);
527  }
528 
529  static void SolveInit(SLUD::superlu_options_t* options, SLUD::SuperMatrix* A,
530  SLUD::int_t* perm_r, SLUD::int_t* perm_c, SLUD::int_t nrhs,
531  type_map::LUstruct_t* lu, SLUD::gridinfo_t* grid,
532  type_map::SOLVEstruct_t* solve_struct)
533  {
534  SLUD::Z::zSolveInit(options, A, perm_r, perm_c, nrhs, lu, grid, solve_struct);
535  }
536 
537  static void LUstructInit(SLUD::int_t m, SLUD::int_t n, type_map::LUstruct_t* lu)
538  {
539  SLUD::Z::LUstructInit(m, n, lu);
540  }
541 
542  static void Destroy_LU(SLUD::int_t m, SLUD::gridinfo_t* grid, type_map::LUstruct_t* lu)
543  {
544  SLUD::Z::Destroy_LU(m, grid, lu);
545  }
546 
547  static void LUstructFree(type_map::LUstruct_t* lu)
548  {
549  SLUD::Z::LUstructFree(lu);
550  }
551 
552  static void SolveFinalize(SLUD::superlu_options_t* options,
553  type_map::SOLVEstruct_t* solve_struct)
554  {
555  SLUD::Z::zSolveFinalize(options, solve_struct);
556  }
557  };
558 #endif // HAVE_TEUCHOS_COMPLEX
559 
560 } // end namespace Amesos2
561 
562 
563 #endif // AMESOS2_SUPERLUDIST_FUNCTIONMAP_HPP
Declaration of Function mapping class for Amesos2.
Provides definition of SuperLU_DIST types as well as conversions and type traits. ...