MFEM  v4.2.0
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-2020, 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 private:
76  MPI_Comm comm_;
77  void * rowLocPtr_;
78 
79 }; // mfem::SuperLURowLocMatrix
80 
81 /** The MFEM SuperLU Direct Solver class.
82 
83  The mfem::SuperLUSolver class uses the SuperLU_DIST library to perform LU
84  factorization of a parallel sparse matrix. The solver is capable of handling
85  double precision types. It is currently maintained by Xiaoye Sherry Li at
86  NERSC, see http://crd-legacy.lbl.gov/~xiaoye/SuperLU/.
87 */
89 {
90 public:
91  // Constructor with MPI_Comm parameter.
92  SuperLUSolver( MPI_Comm comm );
93 
94  // Constructor with SuperLU Matrix Object.
96 
97  // Default destructor.
98  ~SuperLUSolver( void );
99 
100  // Allocate and deallocate the MPI communicators. This routine is called
101  // internally by SetOperator().
102  void SetupGrid();
103  // This routing must be called after the solve, but before destruction.
104  void DismantleGrid();
105 
106  // Factor and solve the linear system y = Op^{-1} x.
107  void Mult( const Vector & x, Vector & y ) const;
108 
109  // Set the operator.
110  void SetOperator( const Operator & op );
111 
112  // Set various solver options. Refer to SuperLU documentation for details.
113  void SetPrintStatistics ( bool print_stat );
114  void SetEquilibriate ( bool equil );
115  void SetColumnPermutation( superlu::ColPerm col_perm );
116  void SetRowPermutation ( superlu::RowPerm row_perm,
117  Array<int> * perm = NULL );
119  void SetIterativeRefine ( superlu::IterRefine iter_ref );
120  void SetReplaceTinyPivot ( bool rtp );
121  void SetNumLookAheads ( int num_lookaheads );
122  void SetLookAheadElimTree( bool etree );
123  void SetSymmetricPattern ( bool sym );
124 
125 private:
126  void Init();
127 
128 protected:
129 
130  MPI_Comm comm_;
132  int myid_;
133 
135 
136  // The actual types of the following pointers are hidden to avoid exposing
137  // the SuperLU header files to the entire library. Their types are given in
138  // the trailing comments. The reason that this is necessary is that SuperLU
139  // defines these structs differently for use with its real and complex
140  // solvers. If we want to add support for SuperLU's complex solvers one day
141  // we will need to hide these types to avoid name conflicts.
142  void* optionsPtr_; // superlu_options_t *
143  void* statPtr_; // SuperLUStat_t *
144  void* ScalePermstructPtr_; // ScalePermsruct_t *
145  void* LUstructPtr_; // LUstruct_t *
146  void* SOLVEstructPtr_; // SOLVEstruct_t *
147  void* gridPtr_; // gridinfo_t *
148 
149  double* berr_;
150  mutable int* perm_r_;
151  int nrhs_;
152  int nprow_;
153  int npcol_;
154  mutable bool firstSolveWithThisA_;
156  mutable bool LUStructInitialized_;
157 
158 }; // mfem::SuperLUSolver class
159 
160 } // mfem namespace
161 
162 #endif // MFEM_USE_MPI
163 #endif // MFEM_USE_SUPERLU
164 #endif // MFEM_SUPERLU
void * InternalData() const
Definition: superlu.hpp:73
void trans(const Vector &u, Vector &x)
Definition: ex27.cpp:421
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: superlu.cpp:471
void * ScalePermstructPtr_
Definition: superlu.hpp:144
void SetRowPermutation(superlu::RowPerm row_perm, Array< int > *perm=NULL)
Definition: superlu.cpp:349
void SetSymmetricPattern(bool sym)
Definition: superlu.cpp:420
void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: superlu.cpp:576
void SetIterativeRefine(superlu::IterRefine iter_ref)
Definition: superlu.cpp:386
void SetColumnPermutation(superlu::ColPerm col_perm)
Definition: superlu.cpp:340
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:153
void SetNumLookAheads(int num_lookaheads)
Definition: superlu.cpp:404
void SetPrintStatistics(bool print_stat)
Definition: superlu.cpp:322
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:146
void SetLookAheadElimTree(bool etree)
Definition: superlu.cpp:411
unsigned int sqrti(const unsigned int &a)
Definition: superlu.cpp:48
void SetReplaceTinyPivot(bool rtp)
Definition: superlu.cpp:395
Vector data type.
Definition: vector.hpp:51
void SetTranspose(superlu::Trans trans)
Definition: superlu.cpp:377
const SuperLURowLocMatrix * APtr_
Definition: superlu.hpp:134
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: superlu.hpp:65
Base class for solvers.
Definition: operator.hpp:634
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:181
SuperLUSolver(MPI_Comm comm)
Definition: superlu.cpp:205
void SetEquilibriate(bool equil)
Definition: superlu.cpp:331