MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
mumps.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_MUMPS
13#define MFEM_MUMPS
14
15#include "../config/config.hpp"
16
17#ifdef MFEM_USE_MUMPS
18#ifdef MFEM_USE_MPI
19
20#include "operator.hpp"
21#include "hypre.hpp"
22#include <mpi.h>
23
24#ifdef MFEM_USE_SINGLE
25#include "smumps_c.h"
26#else
27#include "dmumps_c.h"
28#endif
29
30namespace mfem
31{
32
33/**
34 * @brief MUMPS: A Parallel Sparse Direct Solver
35 *
36 * Interface for the distributed MUMPS solver
37 */
38class MUMPSSolver : public Solver
39{
40public:
41 /// Specify the type of matrix we are applying the solver to
43 {
44 /// General sparse matrix, no symmetry is assumed
46 /// A sparse symmetric positive definite matrix
48 /// A sparse symmetric matrix that is not necessarily positive definite
50 };
51
52 /// Specify the reordering strategy for the MUMPS solver
54 {
55 /// Let MUMPS automatically decide the reording strategy
57 /// Approximate Minimum Degree with auto quasi-dense row detection is used
59 /// Approximate Minimum Fill method will be used
61 /// The PORD library will be used
63 /// The METIS library will be used
65 /// The ParMETIS library will be used
67 /// The Scotch library will be used
69 /// The PTScotch library will be used
71 };
72
73 /**
74 * @brief Constructor with MPI_Comm parameter.
75 */
76 MUMPSSolver(MPI_Comm comm_);
77
78 /**
79 * @brief Constructor with a HypreParMatrix Operator.
80 */
81 MUMPSSolver(const Operator &op);
82
83 /**
84 * @brief Set the Operator and perform factorization
85 *
86 * @a op needs to be of type HypreParMatrix.
87 *
88 * @param op Operator used in factorization and solve
89 */
90 void SetOperator(const Operator &op);
91
92 /**
93 * @brief Solve $ y = Op^{-1} x $
94 *
95 * @param x RHS vector
96 * @param y Solution vector
97 */
98 void Mult(const Vector &x, Vector &y) const;
99
100 /**
101 * @brief Solve $ Y_i = Op^{-T} X_i $
102 *
103 * @param X Array of RHS vectors
104 * @param Y Array of Solution vectors
105 */
106 void ArrayMult(const Array<const Vector *> &X, Array<Vector *> &Y) const;
107
108 /**
109 * @brief Transpose Solve $ y = Op^{-T} x $
110 *
111 * @param x RHS vector
112 * @param y Solution vector
113 */
114 void MultTranspose(const Vector &x, Vector &y) const;
115
116 /**
117 * @brief Transpose Solve $ Y_i = Op^{-T} X_i $
118 *
119 * @param X Array of RHS vectors
120 * @param Y Array of Solution vectors
121 */
123 Array<Vector *> &Y) const;
124
125 /**
126 * @brief Set the error print level for MUMPS
127 *
128 * Supported values are:
129 * - 0: No output printed
130 * - 1: Only errors printed
131 * - 2: Errors, warnings, and main stats printed
132 * - 3: Errors, warning, main stats, and terse diagnostics printed
133 * - 4: Errors, warning, main stats, diagnostics, and input/output printed
134 *
135 * @param print_lvl Print level, default is 2
136 *
137 * @note This method has to be called before SetOperator
138 */
139 void SetPrintLevel(int print_lvl);
140
141 /**
142 * @brief Set the matrix type
143 *
144 * Supported matrix types: MUMPSSolver::UNSYMMETRIC,
145 * MUMPSSolver::SYMMETRIC_POSITIVE_DEFINITE,
146 * and MUMPSSolver::SYMMETRIC_INDEFINITE
147 *
148 * @param mtype Matrix type
149 *
150 * @note This method has to be called before SetOperator
151 */
152 void SetMatrixSymType(MatType mtype);
153
154 /**
155 * @brief Set the reordering strategy
156 *
157 * Supported reorderings are: MUMPSSolver::AUTOMATIC,
158 * MUMPSSolver::AMD, MUMPSSolver::AMF, MUMPSSolver::PORD,
159 * MUMPSSolver::METIS, MUMPSSolver::PARMETIS,
160 * MUMPSSolver::SCOTCH, and MUMPSSolver::PTSCOTCH
161 *
162 * @param method Reordering method
163 *
164 * @note This method has to be called before SetOperator
165 */
167
168 /**
169 * @brief Set the flag controlling reuse of the symbolic factorization
170 * for multiple operators
171 *
172 * @param reuse Flag to reuse symbolic factorization
173 *
174 * @note This method has to be called before repeated calls to SetOperator
175 */
176 void SetReorderingReuse(bool reuse);
177
178 /**
179 * @brief Set the tolerance for activating block low-rank (BLR) approximate
180 * factorization
181 *
182 * @param tol Tolerance
183 *
184 * @note This method has to be called before SetOperator
185 */
186#if MFEM_MUMPS_VERSION >= 510
187 void SetBLRTol(double tol);
188#endif
189
190 // Destructor
191 ~MUMPSSolver();
192
193private:
194 // MPI communicator
195 MPI_Comm comm;
196
197 // Number of procs
198 int numProcs;
199
200 // MPI rank
201 int myid;
202
203 // Parameter controlling the matrix type
204 MatType mat_type;
205
206 // Parameter controlling the printing level
207 int print_level;
208
209 // Parameter controlling the reordering strategy
210 ReorderingStrategy reorder_method;
211
212 // Parameter controlling whether or not to reuse the symbolic factorization
213 // for multiple calls to SetOperator
214 bool reorder_reuse;
215
216#if MFEM_MUMPS_VERSION >= 510
217 // Parameter controlling the Block Low-Rank (BLR) feature in MUMPS
218 double blr_tol;
219#endif
220
221 // Local row offsets
222 int row_start;
223
224 // MUMPS object
225#ifdef MFEM_USE_SINGLE
226 SMUMPS_STRUC_C *id;
227#else
228 DMUMPS_STRUC_C *id;
229#endif
230
231 /// Method for initialization
232 void Init(MPI_Comm comm_);
233
234 /// Method for setting MUMPS internal parameters
235 void SetParameters();
236
237 /// Method for configuring storage for distributed/centralized RHS and
238 /// solution
239 void InitRhsSol(int nrhs) const;
240
241#if MFEM_MUMPS_VERSION >= 530
242 // Row offests array on all procs
243 Array<int> row_starts;
244
245 // Row maps and storage for distributed RHS and solution
246 int *irhs_loc, *isol_loc;
247 mutable real_t *rhs_loc, *sol_loc;
248
249 // These two methods are needed to distribute the local solution
250 // vectors returned by MUMPS to the original MFEM parallel partition
251 int GetRowRank(int i, const Array<int> &row_starts_) const;
252 void RedistributeSol(const int *rmap, const real_t *x, const int lx_loc,
253 Array<Vector *> &Y) const;
254#else
255 // Arrays needed for MPI_Gatherv and MPI_Scatterv
256 int *recv_counts, *displs;
257 mutable real_t *rhs_glob;
258#endif
259}; // mfem::MUMPSSolver class
260
261} // namespace mfem
262
263#endif // MFEM_USE_MPI
264#endif // MFEM_USE_MUMPS
265#endif // MFEM_MUMPS
A class to initialize the size of a Tensor.
Definition dtensor.hpp:55
MUMPS: A Parallel Sparse Direct Solver.
Definition mumps.hpp:39
ReorderingStrategy
Specify the reordering strategy for the MUMPS solver.
Definition mumps.hpp:54
@ AMD
Approximate Minimum Degree with auto quasi-dense row detection is used.
Definition mumps.hpp:58
@ METIS
The METIS library will be used.
Definition mumps.hpp:64
@ PARMETIS
The ParMETIS library will be used.
Definition mumps.hpp:66
@ AMF
Approximate Minimum Fill method will be used.
Definition mumps.hpp:60
@ PORD
The PORD library will be used.
Definition mumps.hpp:62
@ AUTOMATIC
Let MUMPS automatically decide the reording strategy.
Definition mumps.hpp:56
@ PTSCOTCH
The PTScotch library will be used.
Definition mumps.hpp:70
@ SCOTCH
The Scotch library will be used.
Definition mumps.hpp:68
MUMPSSolver(MPI_Comm comm_)
Constructor with MPI_Comm parameter.
Definition mumps.cpp:41
void MultTranspose(const Vector &x, Vector &y) const
Transpose Solve .
Definition mumps.cpp:424
void SetBLRTol(double tol)
Set the tolerance for activating block low-rank (BLR) approximate factorization.
Definition mumps.cpp:466
void SetPrintLevel(int print_lvl)
Set the error print level for MUMPS.
Definition mumps.cpp:445
void Mult(const Vector &x, Vector &y) const
Solve .
Definition mumps.cpp:353
void SetReorderingStrategy(ReorderingStrategy method)
Set the reordering strategy.
Definition mumps.cpp:455
void ArrayMultTranspose(const Array< const Vector * > &X, Array< Vector * > &Y) const
Transpose Solve .
Definition mumps.cpp:434
MatType
Specify the type of matrix we are applying the solver to.
Definition mumps.hpp:43
@ UNSYMMETRIC
General sparse matrix, no symmetry is assumed.
Definition mumps.hpp:45
@ SYMMETRIC_INDEFINITE
A sparse symmetric matrix that is not necessarily positive definite.
Definition mumps.hpp:49
@ SYMMETRIC_POSITIVE_DEFINITE
A sparse symmetric positive definite matrix.
Definition mumps.hpp:47
void SetMatrixSymType(MatType mtype)
Set the matrix type.
Definition mumps.cpp:450
void SetReorderingReuse(bool reuse)
Set the flag controlling reuse of the symbolic factorization for multiple operators.
Definition mumps.cpp:460
void SetOperator(const Operator &op)
Set the Operator and perform factorization.
Definition mumps.cpp:103
void ArrayMult(const Array< const Vector * > &X, Array< Vector * > &Y) const
Solve .
Definition mumps.cpp:362
Abstract operator.
Definition operator.hpp:25
Base class for solvers.
Definition operator.hpp:683
Vector data type.
Definition vector.hpp:80
float real_t
Definition config.hpp:43