MFEM  v4.1.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
strumpack.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, 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_STRUMPACK
13 #define MFEM_STRUMPACK
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_STRUMPACK
18 #ifdef MFEM_USE_MPI
19 #include "operator.hpp"
20 #include "hypre.hpp"
21 
22 #include <mpi.h>
23 
24 #include "StrumpackSparseSolverMPIDist.hpp"
25 
26 namespace mfem
27 {
28 
30 {
31 public:
32  /** Creates a general parallel matrix from a local CSR matrix on each
33  processor described by the I, J and data arrays. The local matrix should
34  be of size (local) nrows by (global) glob_ncols. The new parallel matrix
35  contains copies of all input arrays (so they can be deleted). */
36  STRUMPACKRowLocMatrix(MPI_Comm comm,
37  int num_loc_rows, int first_loc_row,
38  int glob_nrows, int glob_ncols,
39  int *I, int *J, double *data);
40 
41  /** Creates a copy of the parallel matrix hypParMat in STRUMPACK's RowLoc
42  format. All data is copied so the original matrix may be deleted. */
43  STRUMPACKRowLocMatrix(const HypreParMatrix & hypParMat);
44 
46 
47  void Mult(const Vector &x, Vector &y) const
48  {
49  mfem_error("STRUMPACKRowLocMatrix::Mult(...)\n"
50  " matrix vector products are not supported.");
51  }
52 
53  MPI_Comm GetComm() const { return comm_; }
54 
55  strumpack::CSRMatrixMPI<double,int>* getA() const { return A_; }
56 
57 private:
58  MPI_Comm comm_;
59  strumpack::CSRMatrixMPI<double,int>* A_;
60 
61 }; // mfem::STRUMPACKRowLocMatrix
62 
63 /** The MFEM STRUMPACK Direct Solver class.
64 
65  The mfem::STRUMPACKSolver class uses the STRUMPACK library to perform LU
66  factorization of a parallel sparse matrix. The solver is capable of handling
67  double precision types. See http://portal.nersc.gov/project/sparse/strumpack
68 */
70 {
71 public:
72  // Constructor with MPI_Comm parameter.
73  STRUMPACKSolver( int argc, char* argv[], MPI_Comm comm );
74 
75  // Constructor with STRUMPACK Matrix Object.
77 
78  // Default destructor.
79  ~STRUMPACKSolver( void );
80 
81  // Factor and solve the linear system y = Op^{-1} x.
82  void Mult( const Vector & x, Vector & y ) const;
83 
84  // Set the operator.
85  void SetOperator( const Operator & op );
86 
87  // Set various solver options. Refer to STRUMPACK documentation for
88  // details.
89  void SetFromCommandLine( );
90  void SetPrintFactorStatistics( bool print_stat );
91  void SetPrintSolveStatistics( bool print_stat );
92  void SetRelTol( double rtol );
93  void SetAbsTol( double atol );
94 
95  /**
96  * STRUMPACK is an (approximate) direct solver. It can be used as a direct
97  * solver or as a preconditioner. To use STRUMPACK as only a preconditioner,
98  * set the Krylov solver to DIRECT. STRUMPACK also provides iterative solvers
99  * which can use the preconditioner, and these iterative solvers can also be
100  * used without preconditioner.
101  *
102  * Supported values are:
103  * AUTO: Use iterative refinement if no HSS compression is used,
104  * otherwise use GMRes.
105  * DIRECT: No outer iterative solver, just a single application of
106  * the multifrontal solver.
107  * REFINE: Iterative refinement.
108  * PREC_GMRES: Preconditioned GMRes.
109  * The preconditioner is the (approx) multifrontal solver.
110  * GMRES: UN-preconditioned GMRes. (for testing mainly)
111  * PREC_BICGSTAB: Preconditioned BiCGStab.
112  * The preconditioner is the (approx) multifrontal solver.
113  * BICGSTAB: UN-preconditioned BiCGStab. (for testing mainly)
114  */
115  void SetKrylovSolver( strumpack::KrylovSolver method );
116 
117  /**
118  * Supported reorderings are:
119  * METIS, PARMETIS, SCOTCH, PTSCOTCH, RCM
120  */
121  void SetReorderingStrategy( strumpack::ReorderingStrategy method );
122 
123  /**
124  * Disable static pivoting for stability. The static pivoting in strumpack
125  * permutes the sparse input matrix in order to get large (nonzero) elements
126  * on the diagonal. If the input matrix is already diagonally dominant, this
127  * reordering can be disabled.
128  */
129  void DisableMatching();
130 
131  /**
132  * Enable static pivoting for stability using the MC64 algorithm with
133  * job=5. Using a matching algorithm, this will permute the sparse input
134  * matrix in order to get nonzero elements (as large as possible) on the
135  * diagonal. And will also scale the rows and columns of the matrix.
136  */
137  void EnableMatching();
138 
139 #if STRUMPACK_VERSION_MAJOR >= 3
140  /**
141  * Use the AWPM (approximate weight perfect matching) algorithm from the
142  * Combinatorial BLAS library for static pivoting, i.e. getting large
143  * nonzeros on the diagonal. This requires that strumpack was compiled with
144  * support for Combinatorial BLAS.
145  */
146  void EnableParallelMatching();
147 #endif
148 
149 private:
150  void Init( int argc, char* argv[] );
151 
152 protected:
153 
154  MPI_Comm comm_;
156  int myid_;
157 
160 
162  strumpack::StrumpackSparseSolverMPIDist<double,int> * solver_;
163 
164 }; // mfem::STRUMPACKSolver class
165 
166 } // mfem namespace
167 
168 #endif // MFEM_USE_MPI
169 #endif // MFEM_USE_STRUMPACK
170 #endif // MFEM_STRUMPACK
MPI_Comm GetComm() const
Definition: strumpack.hpp:53
const STRUMPACKRowLocMatrix * APtr_
Definition: strumpack.hpp:161
STRUMPACKSolver(int argc, char *argv[], MPI_Comm comm)
Definition: strumpack.cpp:86
strumpack::StrumpackSparseSolverMPIDist< double, int > * solver_
Definition: strumpack.hpp:162
strumpack::CSRMatrixMPI< double, int > * getA() const
Definition: strumpack.hpp:55
void SetPrintFactorStatistics(bool print_stat)
Definition: strumpack.cpp:127
STRUMPACKRowLocMatrix(MPI_Comm comm, int num_loc_rows, int first_loc_row, int glob_nrows, int glob_ncols, int *I, int *J, double *data)
Definition: strumpack.cpp:25
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 SetPrintSolveStatistics(bool print_stat)
Definition: strumpack.cpp:132
void SetReorderingStrategy(strumpack::ReorderingStrategy method)
Definition: strumpack.cpp:142
void SetRelTol(double rtol)
Definition: strumpack.cpp:176
A class to initialize the size of a Tensor.
Definition: dtensor.hpp:54
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: strumpack.cpp:187
void SetKrylovSolver(strumpack::KrylovSolver method)
Definition: strumpack.cpp:137
void SetAbsTol(double atol)
Definition: strumpack.cpp:181
void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: strumpack.cpp:221
Vector data type.
Definition: vector.hpp:48
void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: strumpack.hpp:47
Base class for solvers.
Definition: operator.hpp:500
Abstract operator.
Definition: operator.hpp:24
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:187