MFEM  v3.3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
superlu.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_SUPERLU
13 #define MFEM_SUPERLU
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_SUPERLU
18 #ifdef MFEM_USE_MPI
19 #include "operator.hpp"
20 #include "hypre.hpp"
21 
22 #include <mpi.h>
23 
24 namespace mfem
25 {
26 
27 namespace superlu_internal
28 {
29 unsigned int sqrti(const unsigned int & a);
30 }
31 
32 namespace superlu
33 {
34 // Copy selected enumerations from SuperLU
38  } ColPerm;
39 typedef enum {NOTRANS, TRANS, CONJ} Trans;
41 }
42 
44 {
45 public:
46  /** Creates a general parallel matrix from a local CSR matrix on each
47  processor described by the I, J and data arrays. The local matrix should
48  be of size (local) nrows by (global) glob_ncols. The new parallel matrix
49  contains copies of all input arrays (so they can be deleted). */
50  SuperLURowLocMatrix(MPI_Comm comm,
51  int num_loc_rows, int first_loc_row,
52  int glob_nrows, int glob_ncols,
53  int *I, int *J, double *data);
54 
55  /** Creates a copy of the parallel matrix hypParMat in SuperLU's RowLoc
56  format. All data is copied so the original matrix may be deleted. */
57  SuperLURowLocMatrix(const HypreParMatrix & hypParMat);
58 
60 
61  void Mult(const Vector &x, Vector &y) const
62  {
63  mfem_error("SuperLURowLocMatrix::Mult(...)\n"
64  " matrix vector products are not supported.");
65  }
66 
67  MPI_Comm GetComm() const { return comm_; }
68 
69  void * InternalData() const { return rowLocPtr_; }
70 
71 private:
72  MPI_Comm comm_;
73  void * rowLocPtr_;
74 
75 }; // mfem::SuperLURowLocMatrix
76 
77 /** The MFEM SuperLU Direct Solver class.
78 
79  The mfem::SuperLUSolver class uses the SuperLU_DIST library to perform LU
80  factorization of a parallel sparse matrix. The solver is capable of handling
81  double precision types. It is currently maintained by Xiaoye Sherry Li at
82  NERSC, see http://crd-legacy.lbl.gov/~xiaoye/SuperLU/.
83 */
85 {
86 public:
87  // Constructor with MPI_Comm parameter.
88  SuperLUSolver( MPI_Comm comm );
89 
90  // Constructor with SuperLU Matrix Object.
92 
93  // Default destructor.
94  ~SuperLUSolver( void );
95 
96  // Allocate and deallocate the MPI communicators. This routine is called
97  // internally by SetOperator().
98  void SetupGrid();
99  // This routing must be called after the solve, but before destruction.
100  void DismantleGrid();
101 
102  // Factor and solve the linear system y = Op^{-1} x.
103  void Mult( const Vector & x, Vector & y ) const;
104 
105  // Set the operator.
106  void SetOperator( const Operator & op );
107 
108  // Set various solver options. Refer to SuperLU documentation for details.
109  void SetPrintStatistics ( bool print_stat );
110  void SetEquilibriate ( bool equil );
111  void SetColumnPermutation( superlu::ColPerm col_perm );
112  void SetRowPermutation ( superlu::RowPerm row_perm,
113  Array<int> * perm = NULL );
114  void SetTranspose ( superlu::Trans trans );
115  void SetIterativeRefine ( superlu::IterRefine iter_ref );
116  void SetReplaceTinyPivot ( bool rtp );
117  void SetNumLookAheads ( int num_lookaheads );
118  void SetLookAheadElimTree( bool etree );
119  void SetSymmetricPattern ( bool sym );
120 
121 private:
122  void Init();
123 
124 protected:
125 
126  MPI_Comm comm_;
128  int myid_;
129 
131 
132  // The actual types of the following pointers are hidden to avoid exposing
133  // the SuperLU header files to the entire library. Their types are given in
134  // the trailing comments. The reason that this is necessary is that SuperLU
135  // defines these structs differently for use with its real and complex
136  // solvers. If we want to add support for SuperLU's complex solvers one day
137  // we will need to hide these types to avoid name conflicts.
138  void* optionsPtr_; // superlu_options_t *
139  void* statPtr_; // SuperLUStat_t *
140  void* ScalePermstructPtr_; // ScalePermsruct_t *
141  void* LUstructPtr_; // LUstruct_t *
142  void* SOLVEstructPtr_; // SOLVEstruct_t *
143  void* gridPtr_; // gridinfo_t *
144 
145  double* berr_;
146  mutable int* perm_r_;
147  int nrhs_;
148  int nprow_;
149  int npcol_;
150  mutable bool firstSolveWithThisA_;
152  mutable bool LUStructInitialized_;
153 
154 }; // mfem::SuperLUSolver class
155 
156 } // mfem namespace
157 
158 #endif // MFEM_USE_MPI
159 #endif // MFEM_USE_SUPERLU
160 #endif // MFEM_SUPERLU
void * InternalData() const
Definition: superlu.hpp:69
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: superlu.cpp:445
void * ScalePermstructPtr_
Definition: superlu.hpp:140
void SetRowPermutation(superlu::RowPerm row_perm, Array< int > *perm=NULL)
Definition: superlu.cpp:324
void SetSymmetricPattern(bool sym)
Definition: superlu.cpp:395
void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: superlu.cpp:528
void SetIterativeRefine(superlu::IterRefine iter_ref)
Definition: superlu.cpp:361
void SetColumnPermutation(superlu::ColPerm col_perm)
Definition: superlu.cpp:315
void SetNumLookAheads(int num_lookaheads)
Definition: superlu.cpp:379
void SetPrintStatistics(bool print_stat)
Definition: superlu.cpp:297
void mfem_error(const char *msg)
Definition: error.cpp:107
MPI_Comm GetComm() const
Definition: superlu.hpp:67
void * SOLVEstructPtr_
Definition: superlu.hpp:142
void SetLookAheadElimTree(bool etree)
Definition: superlu.cpp:386
unsigned int sqrti(const unsigned int &a)
Definition: superlu.cpp:27
void SetReplaceTinyPivot(bool rtp)
Definition: superlu.cpp:370
Vector data type.
Definition: vector.hpp:41
void SetTranspose(superlu::Trans trans)
Definition: superlu.cpp:352
const SuperLURowLocMatrix * APtr_
Definition: superlu.hpp:130
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: superlu.hpp:61
Base class for solvers.
Definition: operator.hpp:259
SuperLURowLocMatrix(MPI_Comm comm, int num_loc_rows, int first_loc_row, int glob_nrows, int glob_ncols, int *I, int *J, double *data)
Definition: superlu.cpp:54
Abstract operator.
Definition: operator.hpp:21
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:175
SuperLUSolver(MPI_Comm comm)
Definition: superlu.cpp:177
void SetEquilibriate(bool equil)
Definition: superlu.cpp:306