MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
mumps.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, 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 #include "operator.hpp"
20 #include "hypre.hpp"
21 
22 #include <mpi.h>
23 #include "dmumps_c.h"
24 #include <vector>
25 
26 namespace mfem
27 {
28 
29 /**
30  * @brief MUMPS: A Parallel Sparse Direct Solver
31  *
32  * Interface for the distributed MUMPS solver
33  */
34 class MUMPSSolver : public mfem::Solver
35 {
36 public:
37  enum MatType
38  {
42  };
43 
44  /**
45  * @brief Default Constructor
46  */
48 
49  /**
50  * @brief Set the Operator and perform factorization
51  *
52  * @a op needs to be of type HypreParMatrix.
53  *
54  * @param op Operator used in factorization and solve
55  */
56  void SetOperator(const Operator &op);
57 
58  /**
59  * @brief Solve y = Op^{-1} x.
60  *
61  * @param x RHS vector
62  * @param y Solution vector
63  */
64  void Mult(const Vector &x, Vector &y) const;
65 
66  /**
67  * @brief Transpose Solve y = Op^{-T} x.
68  *
69  * @param x RHS vector
70  * @param y Solution vector
71  */
72  void MultTranspose(const Vector &x, Vector &y) const;
73 
74  /**
75  * @brief Set the error print level for MUMPS
76  *
77  * @param print_lvl Print level
78  *
79  * @note This method has to be called before SetOperator.
80  */
81  void SetPrintLevel(int print_lvl);
82 
83  /**
84  * @brief Set the matrix type
85  *
86  * Supported matrix types: General, symmetric indefinite and
87  * symmetric positive definite
88  *
89  * @param mtype Matrix type
90  *
91  * @note This method has to be called before SetOperator.
92  */
93  void SetMatrixSymType(MatType mtype);
94 
95  // Destructor
96  ~MUMPSSolver();
97 
98 private:
99 
100  // MPI communicator
101  MPI_Comm comm;
102 
103  // Number of procs
104  int numProcs;
105 
106  // local mpi id
107  int myid;
108 
109  // parameter controlling the matrix type
110  MatType mat_type = MatType::UNSYMMETRIC;
111 
112  // parameter controlling the printing level
113  int print_level = 0;
114 
115  // local row offsets
116  int row_start;
117 
118  // MUMPS object
119  DMUMPS_STRUC_C *id=nullptr;
120 
121  // Method for setting MUMPS internal parameters
122  void SetParameters();
123 
124 #if MFEM_MUMPS_VERSION >= 530
125 
126  // row offsets array on all procs
127  Array<int> row_starts;
128 
129  // row map
130  int * irhs_loc = nullptr;
131 
132  // These two methods are needed to distribute the local solution
133  // vectors returned by MUMPS to the original MFEM parallel partition
134  int GetRowRank(int i, const Array<int> &row_starts_) const;
135 
136  void RedistributeSol(const int * row_map,
137  const double * x,
138  double * y) const;
139 #else
140 
141  // Arrays needed for MPI_Gather and MPI_Scatter
142  int * recv_counts = nullptr;
143 
144  int * displs = nullptr;
145 
146  double * rhs_glob = nullptr;
147 
148 #endif
149 
150 }; // mfem::MUMPSSolver class
151 
152 } // namespace mfem
153 
154 #endif // MFEM_USE_MPI
155 #endif // MFEM_USE_MUMPS
156 #endif // MFEM_MUMPS
void SetOperator(const Operator &op)
Set the Operator and perform factorization.
Definition: mumps.cpp:30
void SetPrintLevel(int print_lvl)
Set the error print level for MUMPS.
Definition: mumps.cpp:249
void MultTranspose(const Vector &x, Vector &y) const
Transpose Solve y = Op^{-T} x.
Definition: mumps.cpp:239
void Mult(const Vector &x, Vector &y) const
Solve y = Op^{-1} x.
Definition: mumps.cpp:199
void SetMatrixSymType(MatType mtype)
Set the matrix type.
Definition: mumps.cpp:254
Vector data type.
Definition: vector.hpp:60
Base class for solvers.
Definition: operator.hpp:655
Abstract operator.
Definition: operator.hpp:24
MUMPSSolver()
Default Constructor.
Definition: mumps.hpp:47
MUMPS: A Parallel Sparse Direct Solver.
Definition: mumps.hpp:34