MFEM  v4.5.1
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-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
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
35 #ifdef MFEM_USE_SUPERLU5
37 #else
39 #endif
42  } ColPerm;
43 typedef enum {NOTRANS, TRANS, CONJ} Trans;
45 }
46 
48 {
49 public:
50  /** Creates a general parallel matrix from a local CSR matrix on each
51  processor described by the I, J and data arrays. The local matrix should
52  be of size (local) nrows by (global) glob_ncols. The new parallel matrix
53  contains copies of all input arrays (so they can be deleted). */
54  SuperLURowLocMatrix(MPI_Comm comm,
55  int num_loc_rows, int first_loc_row,
56  int glob_nrows, int glob_ncols,
57  int *I, int *J, double *data);
58 
59  /** Creates a copy of the parallel matrix hypParMat in SuperLU's RowLoc
60  format. All data is copied so the original matrix may be deleted. */
61  SuperLURowLocMatrix(const HypreParMatrix & hypParMat);
62 
64 
65  void Mult(const Vector &x, Vector &y) const
66  {
67  mfem_error("SuperLURowLocMatrix::Mult(...)\n"
68  " matrix vector products are not supported.");
69  }
70 
71  MPI_Comm GetComm() const { return comm_; }
72 
73  void * InternalData() const { return rowLocPtr_; }
74 
75  HYPRE_BigInt GetGlobalNumColumns() const { return num_global_cols; }
76 
77 private:
78  MPI_Comm comm_;
79  void * rowLocPtr_;
80  HYPRE_BigInt num_global_cols;
81 
82 }; // mfem::SuperLURowLocMatrix
83 
84 /** The MFEM SuperLU Direct Solver class.
85 
86  The mfem::SuperLUSolver class uses the SuperLU_DIST library to perform LU
87  factorization of a parallel sparse matrix. The solver is capable of handling
88  double precision types. It is currently maintained by Xiaoye Sherry Li at
89  NERSC, see http://crd-legacy.lbl.gov/~xiaoye/SuperLU/.
90 */
92 {
93 public:
94  // Constructor with MPI_Comm parameter.
95  SuperLUSolver( MPI_Comm comm );
96 
97  // Constructor with SuperLU Matrix Object.
99 
100  // Default destructor.
101  ~SuperLUSolver( void );
102 
103  // Allocate and deallocate the MPI communicators. This routine is called
104  // internally by SetOperator().
105  void SetupGrid();
106  // This routing must be called after the solve, but before destruction.
107  void DismantleGrid();
108 
109  // Factor and solve the linear system y = Op^{-1} x.
110  void Mult( const Vector & x, Vector & y ) const;
111 
112  // Set the operator.
113  void SetOperator( const Operator & op );
114 
115  // Set various solver options. Refer to SuperLU documentation for details.
116  void SetPrintStatistics ( bool print_stat );
117  void SetEquilibriate ( bool equil );
118  void SetColumnPermutation( superlu::ColPerm col_perm );
119  void SetRowPermutation ( superlu::RowPerm row_perm,
120  Array<int> * perm = NULL );
122  void SetIterativeRefine ( superlu::IterRefine iter_ref );
123  void SetReplaceTinyPivot ( bool rtp );
124  void SetNumLookAheads ( int num_lookaheads );
125  void SetLookAheadElimTree( bool etree );
126  void SetSymmetricPattern ( bool sym );
127  void SetParSymbFact ( bool par );
128 
129 private:
130  void Init();
131 
132 protected:
133 
134  MPI_Comm comm_;
136  int myid_;
137 
139 
140  // The actual types of the following pointers are hidden to avoid exposing
141  // the SuperLU header files to the entire library. Their types are given in
142  // the trailing comments. The reason that this is necessary is that SuperLU
143  // defines these structs differently for use with its real and complex
144  // solvers. If we want to add support for SuperLU's complex solvers one day
145  // we will need to hide these types to avoid name conflicts.
146  void* optionsPtr_; // superlu_options_t *
147  void* statPtr_; // SuperLUStat_t *
148  void* ScalePermstructPtr_; // ScalePermsruct_t *
149  void* LUstructPtr_; // LUstruct_t *
150  void* SOLVEstructPtr_; // SOLVEstruct_t *
151  void* gridPtr_; // gridinfo_t *
152 
153  double* berr_;
154  mutable int* perm_r_;
155  int nrhs_;
156  int nprow_;
157  int npcol_;
158  mutable bool firstSolveWithThisA_;
160  mutable bool LUStructInitialized_;
161 
162 }; // mfem::SuperLUSolver class
163 
164 } // mfem namespace
165 
166 #endif // MFEM_USE_MPI
167 #endif // MFEM_USE_SUPERLU
168 #endif // MFEM_SUPERLU
void * InternalData() const
Definition: superlu.hpp:73
void trans(const Vector &u, Vector &x)
Definition: ex27.cpp:412
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: superlu.cpp:485
void * ScalePermstructPtr_
Definition: superlu.hpp:148
void SetRowPermutation(superlu::RowPerm row_perm, Array< int > *perm=NULL)
Definition: superlu.cpp:354
void SetSymmetricPattern(bool sym)
Definition: superlu.cpp:425
void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: superlu.cpp:591
HYPRE_BigInt GetGlobalNumColumns() const
Definition: superlu.hpp:75
void SetIterativeRefine(superlu::IterRefine iter_ref)
Definition: superlu.cpp:391
void SetColumnPermutation(superlu::ColPerm col_perm)
Definition: superlu.cpp:345
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Definition: error.cpp:154
void SetNumLookAheads(int num_lookaheads)
Definition: superlu.cpp:409
void SetPrintStatistics(bool print_stat)
Definition: superlu.cpp:327
HYPRE_Int HYPRE_BigInt
A class to initialize the size of a Tensor.
Definition: dtensor.hpp:54
MPI_Comm GetComm() const
Definition: superlu.hpp:71
double a
Definition: lissajous.cpp:41
void * SOLVEstructPtr_
Definition: superlu.hpp:150
void SetLookAheadElimTree(bool etree)
Definition: superlu.cpp:416
unsigned int sqrti(const unsigned int &a)
Definition: superlu.cpp:48
void SetReplaceTinyPivot(bool rtp)
Definition: superlu.cpp:400
Vector data type.
Definition: vector.hpp:60
void SetTranspose(superlu::Trans trans)
Definition: superlu.cpp:382
const SuperLURowLocMatrix * APtr_
Definition: superlu.hpp:138
void SetParSymbFact(bool par)
Definition: superlu.cpp:434
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: superlu.hpp:65
Base class for solvers.
Definition: operator.hpp:655
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:75
Abstract operator.
Definition: operator.hpp:24
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:343
SuperLUSolver(MPI_Comm comm)
Definition: superlu.cpp:210
void SetEquilibriate(bool equil)
Definition: superlu.cpp:336