MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
solver_utils.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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_PARALLEL_DIRECT_SOLVER
13#define MFEM_PARALLEL_DIRECT_SOLVER
14
15#include "mfem.hpp"
16
17
18namespace mfem
19{
20
21/**
22 * @class ParallelDirectSolver
23 * @brief Wrapper around parallel sparse direct solvers (MUMPS, SuperLU_DIST,
24 * STRUMPACK, CPARDISO).
25 *
26 * ParallelDirectSolver provides a uniform interface to several parallel sparse
27 * direct solvers. The solver is selected at
28 * runtime via the Type enum or a string name, while the actual availability
29 * of each backend depends on how MFEM was configured and built.
30 *
31 * Supported backends (if enabled at configure time):
32 * - MUMPS (MFEM_USE_MUMPS)
33 * - SuperLU (MFEM_USE_SUPERLU)
34 * - STRUMPACK (MFEM_USE_STRUMPACK)
35 * - CPARDISO (MFEM_USE_MKL_CPARDISO)
36 *
37 * The typical usage pattern is:
38 * - Construct a ParallelDirectSolver with an MPI communicator and a backend.
39 * - Call SetOperator() with the system operator (usually a HypreParMatrix).
40 * - Call Mult() to apply the inverse (i.e. solve).
41 *
42 */
44{
45public:
46 /**
47 * @brief Type of parallel direct solver to use.
48 *
49 * AUTO selects the first available backend at runtime according to an
50 * internal priority order.
51 */
52 enum class Type
53 {
54 AUTO,
55 MUMPS,
56 SUPERLU,
59 };
60
61private:
62 /// Selected solver type
63 Type type;
64 /// MPI communicator
65 MPI_Comm comm;
66
67#ifdef MFEM_USE_SUPERLU
68 /// Row-local matrix for SuperLU.
69 mutable std::unique_ptr<SuperLURowLocMatrix> superlu_mat;
70#endif
71
72#ifdef MFEM_USE_STRUMPACK
73 /// Row-local matrix for STRUMPACK.
74 mutable std::unique_ptr<STRUMPACKRowLocMatrix> strumpack_mat;
75#endif
76
77 /// Owning pointer to the underlying backend solver.
78 std::unique_ptr<Solver> solver;
79
80 /// Helper that constructs the underlying backend solver based on #type.
81 void InitSolver();
82
83public:
84 /**
85 * @brief Construct a ParallelDirectSolver from an MPI communicator and a Type.
86 *
87 * If @p type_ is Type::AUTO, the constructor will select the first
88 * available backend according to an internal priority order and store the
89 * resolved type in #type. No factorization is performed here; that happens
90 * when SetOperator() is called.
91 */
92 ParallelDirectSolver(MPI_Comm comm_, Type type_ = Type::AUTO);
93 /**
94 * @brief Construct a ParallelDirectSolver from a string name.
95 * Accepted strings:
96 * "auto", "mumps", "superlu", "cpardiso", "strumpack".
97 * The string is converted to a Type and the other constructor is invoked.
98 */
99 ParallelDirectSolver(MPI_Comm comm_, const std::string &name);
100
101 /// Virtual destructor. The underlying solver and any auxiliary matrices
102 /// (SuperLURowLocMatrix, STRUMPACKRowLocMatrix) are destroyed automatically.
104
105 /**
106 * @brief Set the operator to be factored/solved by the direct solver.
107 *
108 * The expected dynamic type of @p op depends on the chosen backend:
109 * - MUMPS / CPARDISO :
110 * - Usually expects a HypreParMatrix (assembled parallel sparse matrix).
111 * - SUPERLU :
112 * - A SuperLURowLocMatrix is constructed internally from @p op and
113 * kept in #superlu_mat. The SuperLUSolver then uses this row-local
114 * representation.
115 * - STRUMPACK :
116 * - A STRUMPACKRowLocMatrix is constructed internally from @p op and
117 * kept in #strumpack_mat. The STRUMPACKSolver then uses this row-local
118 * representation.
119 *
120 * @param op The operator representing the system matrix to factor.
121 */
122 virtual void SetOperator(const Operator &op) override;
123
124 /// Apply the inverse of the operator: y = A^{-1} x.
125 virtual void Mult(const Vector &x, Vector &y) const override;
126
127 virtual void SetPrintLevel(int print_lvl);
128
129};
130
131
132} // namespace mfem
133
134#endif // MFEM_PARALLEL_DIRECT_SOLVER
Abstract operator.
Definition operator.hpp:25
Wrapper around parallel sparse direct solvers (MUMPS, SuperLU_DIST, STRUMPACK, CPARDISO).
Type
Type of parallel direct solver to use.
ParallelDirectSolver(MPI_Comm comm_, Type type_=Type::AUTO)
Construct a ParallelDirectSolver from an MPI communicator and a Type.
virtual void SetPrintLevel(int print_lvl)
virtual void Mult(const Vector &x, Vector &y) const override
Apply the inverse of the operator: y = A^{-1} x.
virtual void SetOperator(const Operator &op) override
Set the operator to be factored/solved by the direct solver.
Base class for solvers.
Definition operator.hpp:792
Vector data type.
Definition vector.hpp:82