MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
superlu.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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
20#include "operator.hpp"
21#include "hypre.hpp"
22#include <mpi.h>
23
24namespace mfem
25{
26
27namespace superlu
28{
29
30// Copy selected enumerations from SuperLU (from superlu_enum_consts.h)
31#ifdef MFEM_USE_SUPERLU5
38#else
39/// Define the type of row permutation
40typedef enum
41{
42 /// No row permutation
44 /** @brief Duff/Koster algorithm to make the diagonals large compared to the
45 off-diagonals. Use LargeDiag for SuperLU version 5 and below. */
47 /** @brief Parallel approximate weight perfect matching to make the diagonals
48 large compared to the off-diagonals. Option doesn't exist in SuperLU
49 version 5 and below. */
51 /// User defined row permutation
53} RowPerm;
54#endif
55
56/// Define the type of column permutation
57typedef enum
58{
59 /// Natural ordering
61 /// Minimum degree ordering on structure of $ A^T*A $
63 /// Minimum degree ordering on structure of $ A^T+A $
65 /// Approximate minimum degree column ordering
67 /// Sequential ordering on structure of $ A^T+A $ using the METIS package
69 /** @brief Sequential ordering on structure of $ A^T+A $ using the
70 PARMETIS package */
72 /// Use the Zoltan library from Sandia to define the column ordering
74 /// User defined column permutation
77
78/// Define how to do iterative refinement
79typedef enum
80{
81 /// No interative refinement
83 /// Iterative refinement accumulating residuals in a float.
85 /// Iterative refinement accumulating residuals in a double.
87 /// Iterative refinement accumulating residuals in a higher precision variable.
90
91/** @brief Define the information that is provided about the matrix
92 factorization ahead of time. */
93typedef enum
94{
95 /// No information is provided, do the full factorization.
97 /** @brief Matrix A will be factored assuming the sparsity is the same as a
98 previous factorization. Column permutations will be reused. */
100 /** @brief Matrix A will be factored assuming the sparsity is the same and
101 the matrix as a previous are similar as a previous factorization. Column
102 permutations and row permutations will be reused. */
104 /** @brief The matrix A was provided in fully factored form and no
105 factorization is needed. */
108
109} // namespace superlu
110
112{
113public:
114 /** @brief Creates a general parallel matrix from a local CSR matrix on each
115 processor described by the I, J and data arrays. The local matrix should
116 be of size (local) nrows by (global) glob_ncols. The new parallel matrix
117 contains copies of all input arrays (so they can be deleted). */
118 SuperLURowLocMatrix(MPI_Comm comm,
119 int num_loc_rows, HYPRE_BigInt first_loc_row,
120 HYPRE_BigInt glob_nrows, HYPRE_BigInt glob_ncols,
121 int *I, HYPRE_BigInt *J, double *data);
122
123 /** @brief Creates a copy of the parallel matrix hypParMat in SuperLU's
124 RowLoc format. All data is copied so the original matrix may be
125 deleted. */
126 SuperLURowLocMatrix(const Operator &op);
127
129
130 /// Matrix Vector products are not supported for this type of matrix
131 void Mult(const Vector &x, Vector &y) const
132 {
133 MFEM_ABORT("SuperLURowLocMatrix::Mult: Matrix vector products are not "
134 "supported!");
135 }
136
137 void *InternalData() const { return rowLocPtr_; }
138
139 /// Get the MPI communicator for this matrix
140 MPI_Comm GetComm() const { return comm_; }
141
142 /// Get the number of global rows in this matrix
143 HYPRE_BigInt GetGlobalNumRows() const { return num_global_rows_; }
144
145 /// Get the number of global columns in this matrix
146 HYPRE_BigInt GetGlobalNumColumns() const { return num_global_cols_; }
147
148private:
149 MPI_Comm comm_;
150 void *rowLocPtr_;
151 HYPRE_BigInt num_global_rows_, num_global_cols_;
152};
153
154/** The MFEM wrapper around the SuperLU Direct Solver class.
155
156 The mfem::SuperLUSolver class uses the SuperLU_DIST library to perform LU
157 factorization of a parallel sparse matrix. The solver is capable of handling
158 double precision types. It is currently maintained by Xiaoye Sherry Li at
159 NERSC, see http://crd-legacy.lbl.gov/~xiaoye/SuperLU/.
160*/
161class SuperLUSolver : public Solver
162{
163public:
164 /** @brief Constructor with MPI_Comm parameter.
165
166 @a npdep is the replication factor for the matrix
167 data and must be a power of 2 and divide evenly
168 into the number of processors. */
169 SuperLUSolver(MPI_Comm comm, int npdep = 1);
170
171 /** @brief Constructor with SuperLU matrix object.
172
173 @a npdep is the replication factor for the matrix
174 data and must be a power of 2 and divide evenly
175 into the number of processors. */
176 SuperLUSolver(SuperLURowLocMatrix &A, int npdep = 1);
177
178 /// Default destructor.
180
181 /** @brief Set the operator/matrix.
182 @note @a A must be a SuperLURowLocMatrix. */
183 void SetOperator(const Operator &op);
184
185 /** @brief Factor and solve the linear system $ y = Op^{-1} x $
186 @note Factorization modifies the operator matrix. */
187 void Mult(const Vector &x, Vector &y) const;
188
189 /** @brief Factor and solve the linear systems $ y_i = Op^{-1} x_i $
190 for all i in the @a X and @a Y arrays.
191 @note Factorization modifies the operator matrix. */
192 void ArrayMult(const Array<const Vector *> &X, Array<Vector *> &Y) const;
193
194 /** @brief Factor and solve the transposed linear system
195 $ y = Op^{-T} x $
196 @note Factorization modifies the operator matrix. */
197 void MultTranspose(const Vector &x, Vector &y) const;
198
199 /** @brief Factor and solve the transposed linear systems
200 $ y_i = Op^{-T} x_i $ for all i in the @a X and @a Y arrays.
201 @note Factorization modifies the operator matrix. */
203 Array<Vector *> &Y) const;
204
205 /// Specify whether to print the solver statistics (default true)
206 void SetPrintStatistics(bool print_stat);
207
208 /** @brief Specify whether to equibrate the system scaling to make
209 the rows and columns have unit norms. (default true) */
210 void SetEquilibriate(bool equil);
211
212 /** @brief Specify how to permute the columns of the matrix.
213
214 Supported options are:
215 superlu::NATURAL, superlu::MMD_ATA, superlu::MMD_AT_PLUS_A,
216 superlu::COLAMD, superlu::METIS_AT_PLUS_A (default),
217 superlu::PARMETIS, superlu::ZOLTAN, superlu::MY_PERMC */
219
220 /** @brief Specify how to permute the rows of the matrix.
221
222 Supported options are:
223 superlu::NOROWPERM, superlu::LargeDiag (default), superlu::MY_PERMR for
224 SuperLU version 5. For later versions the supported options are:
225 superlu::NOROWPERM, superlu::LargeDiag_MC64 (default),
226 superlu::LargeDiag_HWPM, superlu::MY_PERMR */
227 void SetRowPermutation(superlu::RowPerm row_perm);
228
229 /** @brief Specify how to handle iterative refinement
230
231 Supported options are:
232 superlu::NOREFINE, superlu::SLU_SINGLE,
233 superlu::SLU_DOUBLE (default), superlu::SLU_EXTRA */
235
236 /** @brief Specify whether to replace tiny diagonals encountered
237 during pivot with $ \sqrt{\epsilon} \lVert A \rVert $
238 (default false) */
239 void SetReplaceTinyPivot(bool rtp);
240
241 /// Specify the number of levels in the look-ahead factorization (default 10)
242 void SetNumLookAheads(int num_lookaheads);
243
244 /** @brief Specifies whether to use the elimination tree computed from the
245 serial symbolic factorization to perform static scheduling
246 (default false) */
247 void SetLookAheadElimTree(bool etree);
248
249 /** @brief Specify whether the matrix has a symmetric pattern to avoid extra
250 work (default false) */
251 void SetSymmetricPattern(bool sym);
252
253 /** @brief Specify whether to perform parallel symbolic factorization.
254 @note If true SuperLU will use superlu::PARMETIS for the Column
255 Permutation regardless of the setting */
256 void SetParSymbFact(bool par);
257
258 /** @brief Specify what information has been provided ahead of time about the
259 factorization of A.
260
261 Supported options are:
262 superlu::DOFACT, superlu::SamePattern, superlu::SamePattern_SameRowPerm,
263 superlu::FACTORED*/
264 void SetFact(superlu::Fact fact);
265
266 // Processor grid for SuperLU_DIST.
267 const int nprow_, npcol_, npdep_;
268
269private:
270 // Initialize the solver.
271 void Init(MPI_Comm comm);
272
273 // Handle error message from call to SuperLU solver.
274 void HandleError(int info) const;
275
276protected:
278 mutable Vector sol_;
279 mutable int nrhs_;
280
281 /** The actual types of the following pointers are hidden to avoid exposing
282 the SuperLU header files to the entire library. Their types are given in
283 the trailing comments. The reason that this is necessary is that SuperLU
284 defines these structs differently for use with its real and complex
285 solvers. If we want to add support for SuperLU's complex solvers one day
286 we will need to hide these types to avoid name conflicts. */
287 void *optionsPtr_; // superlu_options_t *
288 void *ScalePermstructPtr_; // ScalePermsruct_t *
289 void *LUstructPtr_; // LUstruct_t *
290 void *SOLVEstructPtr_; // SOLVEstruct_t *
291 void *gridPtr_; // gridinfo_t * or gridinfo3d_t *
292};
293
294} // namespace mfem
295
296#endif // MFEM_USE_MPI
297#endif // MFEM_USE_SUPERLU
298#endif // MFEM_SUPERLU
A class to initialize the size of a Tensor.
Definition dtensor.hpp:55
Abstract operator.
Definition operator.hpp:25
Base class for solvers.
Definition operator.hpp:683
SuperLURowLocMatrix(MPI_Comm comm, int num_loc_rows, HYPRE_BigInt first_loc_row, HYPRE_BigInt glob_nrows, HYPRE_BigInt glob_ncols, int *I, HYPRE_BigInt *J, double *data)
Creates a general parallel matrix from a local CSR matrix on each processor described by the I,...
Definition superlu.cpp:107
void Mult(const Vector &x, Vector &y) const
Matrix Vector products are not supported for this type of matrix.
Definition superlu.hpp:131
void * InternalData() const
Definition superlu.hpp:137
HYPRE_BigInt GetGlobalNumColumns() const
Get the number of global columns in this matrix.
Definition superlu.hpp:146
MPI_Comm GetComm() const
Get the MPI communicator for this matrix.
Definition superlu.hpp:140
HYPRE_BigInt GetGlobalNumRows() const
Get the number of global rows in this matrix.
Definition superlu.hpp:143
SuperLUSolver(MPI_Comm comm, int npdep=1)
Constructor with MPI_Comm parameter.
Definition superlu.cpp:262
void ArrayMultTranspose(const Array< const Vector * > &X, Array< Vector * > &Y) const
Factor and solve the transposed linear systems for all i in the X and Y arrays.
Definition superlu.cpp:712
void SetColumnPermutation(superlu::ColPerm col_perm)
Specify how to permute the columns of the matrix.
Definition superlu.cpp:399
void SetRowPermutation(superlu::RowPerm row_perm)
Specify how to permute the rows of the matrix.
Definition superlu.cpp:415
void SetParSymbFact(bool par)
Specify whether to perform parallel symbolic factorization.
Definition superlu.cpp:461
void * ScalePermstructPtr_
Definition superlu.hpp:288
~SuperLUSolver()
Default destructor.
Definition superlu.cpp:278
const SuperLURowLocMatrix * APtr_
Definition superlu.hpp:277
void SetReplaceTinyPivot(bool rtp)
Specify whether to replace tiny diagonals encountered during pivot with (default false)
Definition superlu.cpp:434
void SetNumLookAheads(int num_lookaheads)
Specify the number of levels in the look-ahead factorization (default 10)
Definition superlu.cpp:441
void MultTranspose(const Vector &x, Vector &y) const
Factor and solve the transposed linear system .
Definition superlu.cpp:701
void SetFact(superlu::Fact fact)
Specify what information has been provided ahead of time about the factorization of A.
Definition superlu.cpp:468
void ArrayMult(const Array< const Vector * > &X, Array< Vector * > &Y) const
Factor and solve the linear systems for all i in the X and Y arrays.
Definition superlu.cpp:596
void SetEquilibriate(bool equil)
Specify whether to equibrate the system scaling to make the rows and columns have unit norms....
Definition superlu.cpp:392
void Mult(const Vector &x, Vector &y) const
Factor and solve the linear system .
Definition superlu.cpp:587
void SetLookAheadElimTree(bool etree)
Specifies whether to use the elimination tree computed from the serial symbolic factorization to perf...
Definition superlu.cpp:447
void SetSymmetricPattern(bool sym)
Specify whether the matrix has a symmetric pattern to avoid extra work (default false)
Definition superlu.cpp:454
void SetOperator(const Operator &op)
Set the operator/matrix.
Definition superlu.cpp:475
void SetIterativeRefine(superlu::IterRefine iter_ref)
Specify how to handle iterative refinement.
Definition superlu.cpp:427
void SetPrintStatistics(bool print_stat)
Specify whether to print the solver statistics (default true)
Definition superlu.cpp:385
Vector data type.
Definition vector.hpp:80
HYPRE_Int HYPRE_BigInt
ColPerm
Define the type of column permutation.
Definition superlu.hpp:58
@ NATURAL
Natural ordering.
Definition superlu.hpp:60
@ MMD_ATA
Minimum degree ordering on structure of .
Definition superlu.hpp:62
@ METIS_AT_PLUS_A
Sequential ordering on structure of using the METIS package.
Definition superlu.hpp:68
@ MMD_AT_PLUS_A
Minimum degree ordering on structure of .
Definition superlu.hpp:64
@ PARMETIS
Sequential ordering on structure of using the PARMETIS package.
Definition superlu.hpp:71
@ MY_PERMC
User defined column permutation.
Definition superlu.hpp:75
@ ZOLTAN
Use the Zoltan library from Sandia to define the column ordering.
Definition superlu.hpp:73
@ COLAMD
Approximate minimum degree column ordering.
Definition superlu.hpp:66
IterRefine
Define how to do iterative refinement.
Definition superlu.hpp:80
@ SLU_SINGLE
Iterative refinement accumulating residuals in a float.
Definition superlu.hpp:84
@ SLU_DOUBLE
Iterative refinement accumulating residuals in a double.
Definition superlu.hpp:86
@ SLU_EXTRA
Iterative refinement accumulating residuals in a higher precision variable.
Definition superlu.hpp:88
@ NOREFINE
No interative refinement.
Definition superlu.hpp:82
@ NOROWPERM
No row permutation.
Definition superlu.hpp:34
@ LargeDiag_MC64
Duff/Koster algorithm to make the diagonals large compared to the off-diagonals. Use LargeDiag for Su...
Definition superlu.hpp:46
@ LargeDiag_HWPM
Parallel approximate weight perfect matching to make the diagonals large compared to the off-diagonal...
Definition superlu.hpp:50
@ MY_PERMR
User defined row permutation.
Definition superlu.hpp:36
Fact
Define the information that is provided about the matrix factorization ahead of time.
Definition superlu.hpp:94
@ DOFACT
No information is provided, do the full factorization.
Definition superlu.hpp:96
@ SamePattern_SameRowPerm
Matrix A will be factored assuming the sparsity is the same and the matrix as a previous are similar ...
Definition superlu.hpp:103
@ FACTORED
The matrix A was provided in fully factored form and no factorization is needed.
Definition superlu.hpp:106
@ SamePattern
Matrix A will be factored assuming the sparsity is the same as a previous factorization....
Definition superlu.hpp:99