MFEM  v4.3.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-2021, 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 
128 private:
129  void Init();
130 
131 protected:
132 
133  MPI_Comm comm_;
135  int myid_;
136 
138 
139  // The actual types of the following pointers are hidden to avoid exposing
140  // the SuperLU header files to the entire library. Their types are given in
141  // the trailing comments. The reason that this is necessary is that SuperLU
142  // defines these structs differently for use with its real and complex
143  // solvers. If we want to add support for SuperLU's complex solvers one day
144  // we will need to hide these types to avoid name conflicts.
145  void* optionsPtr_; // superlu_options_t *
146  void* statPtr_; // SuperLUStat_t *
147  void* ScalePermstructPtr_; // ScalePermsruct_t *
148  void* LUstructPtr_; // LUstruct_t *
149  void* SOLVEstructPtr_; // SOLVEstruct_t *
150  void* gridPtr_; // gridinfo_t *
151 
152  double* berr_;
153  mutable int* perm_r_;
154  int nrhs_;
155  int nprow_;
156  int npcol_;
157  mutable bool firstSolveWithThisA_;
159  mutable bool LUStructInitialized_;
160 
161 }; // mfem::SuperLUSolver class
162 
163 } // mfem namespace
164 
165 #endif // MFEM_USE_MPI
166 #endif // MFEM_USE_SUPERLU
167 #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:474
void * ScalePermstructPtr_
Definition: superlu.hpp:147
void SetRowPermutation(superlu::RowPerm row_perm, Array< int > *perm=NULL)
Definition: superlu.cpp:352
void SetSymmetricPattern(bool sym)
Definition: superlu.cpp:423
void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: superlu.cpp:580
HYPRE_BigInt GetGlobalNumColumns() const
Definition: superlu.hpp:75
void SetIterativeRefine(superlu::IterRefine iter_ref)
Definition: superlu.cpp:389
void SetColumnPermutation(superlu::ColPerm col_perm)
Definition: superlu.cpp:343
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:407
void SetPrintStatistics(bool print_stat)
Definition: superlu.cpp:325
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:149
void SetLookAheadElimTree(bool etree)
Definition: superlu.cpp:414
unsigned int sqrti(const unsigned int &a)
Definition: superlu.cpp:48
void SetReplaceTinyPivot(bool rtp)
Definition: superlu.cpp:398
Vector data type.
Definition: vector.hpp:60
void SetTranspose(superlu::Trans trans)
Definition: superlu.cpp:380
const SuperLURowLocMatrix * APtr_
Definition: superlu.hpp:137
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: superlu.hpp:65
Base class for solvers.
Definition: operator.hpp:648
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:277
SuperLUSolver(MPI_Comm comm)
Definition: superlu.cpp:208
void SetEquilibriate(bool equil)
Definition: superlu.cpp:334