MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
cudss.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, 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_CUDSS
13#define MFEM_CUDSS
14
15#include "../config/config.hpp"
16
17#ifdef MFEM_USE_CUDSS
18
19#include "cudss.h"
20#include <memory>
21
22#ifdef MFEM_USE_MPI
23#include <mpi.h>
24#include "hypre.hpp"
25#else
26#include "operator.hpp"
27#include "sparsemat.hpp"
28#endif
29
30namespace mfem
31{
32/**
33 * @brief cuDSS: A high-performance CUDA Library for Direct Sparse Solvers
34 *
35 * Interface for the distributed cuDSS solver
36 */
37class CuDSSSolver : public Solver
38{
39public:
40 /// Specify the type of matrix we are applying the solver to
42 {
43 /// CUDSS_MTYPE_GENERAL: General matrix [default].
45 /// CUDSS_MTYPE_SYMMETRIC: Real symmetric matrix.
47 /// CUDSS_MTYPE_SPD: Symmetric positive-definite matrix.
49 };
50
51 /// Specify the view type of matrix we are applying the solver to
53 {
54 /// CUDSS_MVIEW_FULL: Full matrix [default]
55 FULL = 0,
56 /// CUDSS_MVIEW_LOWER: Lower-triangular matrix (including the diagonal).
57 LOWER = 1,
58 /// CUDSS_MVIEW_UPPER: Upper-triangular matrix (including the diagonal).
59 UPPER = 2,
60 };
61
62 /**
63 * @brief Constructor.
64 */
66
67#ifdef MFEM_USE_MPI
68 /**
69 * @brief Constructor with MPI_Comm parameter.
70 */
71 CuDSSSolver(MPI_Comm comm);
72#endif
73
74 // Note: CuDSSSolver disables the move copy constructor and move assignment
75 // operator
78
79 /**
80 * @brief Set the matrix type
81 *
82 * Supported matrix types:
83 * CuDSSSolver::NONSYMMETRIC,
84 * CuDSSSolver::SYMMETRIC_INDEFINITE,
85 * and CuDSSSolver::SYMMETRIC_POSITIVE_DEFINITE
86 *
87 * @param mtype_ Matrix type
88 *
89 * @note This method has to be called before SetOperator
90 */
91 void SetMatrixSymType(MatType mtype_);
92
93 /**
94 * @brief Set the matrix view type
95 *
96 * Supported matrix types:
97 * CuDSSSolver::FULL,
98 * CuDSSSolver::LOWER,
99 * and CuDSSSolver::UPPER
100 *
101 * @param mvtype Matrix view type
102 *
103 * @note This method has to be called before SetOperator
104 */
105 void SetMatrixViewType(MatViewType mvtype);
106
107 /**
108 * @brief Set the flag controlling reuse of the symbolic factorization
109 * for multiple operators
110 *
111 * @param reuse Flag to reuse symbolic factorization
112 *
113 * @note This method has to be called before repeated calls to SetOperator
114 */
115 void SetReorderingReuse(bool reuse);
116
117 void SetOperator(const Operator &op) override;
118
119 /**
120 * @brief Solve $ y = Op^{-1} x $
121 *
122 * @param x RHS vector
123 * @param y Solution vector
124 */
125 void Mult(const Vector &x, Vector &y) const override;
126
127 /**
128 * @brief Solve $ Y_i = Op^{-1} X_i $
129 *
130 * @param X Array of RHS vectors
131 * @param Y Array of Solution vectors
132 */
133 void ArrayMult(const Array<const Vector *> &X,
134 Array<Vector *> &Y) const override;
135
136 ~CuDSSSolver();
137
138private:
139#ifdef MFEM_USE_MPI
140 // MPI_Comm
141 MPI_Comm mpi_comm = MPI_COMM_NULL;
142
143 int row_start = 0; // the first row index in CSR matrix operator
144 int row_end = 0; // the end row index in CSR matrix operator
145#endif
146
147 // Parameter controlling whether or not to reuse the symbolic factorization
148 // for multiple calls to SetOperator
149 bool reorder_reuse = false;
150
151 // Parameter controlling the matrix type
152 cudssMatrixType_t mat_type = CUDSS_MTYPE_GENERAL;
153
154 int n_global = 0; // global number of rows
155 int n_loc = 0; // the number of the rows in CSR matrix operator
156
157 mutable int nrhs = 0; // the number of the RHSs
158 int nnz = 0; // the number of non zeros
159
160 // copy and keep the I and J arrays in device memory
161 void *csr_offsets_d = NULL; // copy and keep I in device
162 void *csr_columns_d = NULL; // copy and keep J in device
163 void *csr_values_d = NULL; // copy and keep csr data in device
164
165 // cuDSS object specifies available matrix types for sparse matrices
166 cudssMatrixViewType_t mview = CUDSS_MVIEW_FULL;
167
168 // cuDSS objects storage for sparse matrix Ac, RHS yc and solution xc
169 std::unique_ptr<cudssMatrix_t> Ac;
170 mutable cudssMatrix_t xc, yc;
171
172 // common for all cuDSS solver instances.
173 // cuDSS object holds the cuDSS library context
174 cudssHandle_t handle;
175
176 // cuDSS object stores configuration settings for the solver
177 mutable cudssConfig_t solverConfig;
178 // cuDSS object holds internal data
179 mutable cudssData_t solverData;
180
181 /// Method for configuring storage for distributed/centralized RHS and
182 /// solution
183 void SetNumRHS(int nrhs_) const;
184
185#ifdef MFEM_USE_MPI
186 /**
187 * @brief Set the HypreParMatrix object
188 *
189 * @param op HypreParMatrix object
190 *
191 * @note This method is called inside SetOperator
192 */
193 void SetMatrix(const HypreParMatrix &op);
194#endif
195
196 /**
197 * @brief Set the SparseMatrix object
198 *
199 * @param op SparseMatrix object
200 *
201 * @note This method is called inside SetOperator
202 */
203 void SetMatrix(const SparseMatrix &op);
204
205 /**
206 * @brief Set the matrix values for cuDSS
207 *
208 * @param csr_offsets Row offsets of the CSR matrix
209 * @param csr_columns Column indices of the CSR matrix
210 * @param csr_values Non-zero values of the CSR matrix
211 *
212 * @note This method is called inside SetMatrix.
213 */
214 void SetMatrixCuDSS(int* csr_offsets, int* csr_columns, real_t* csr_values);
215
216 /// Method for initializing the cuDSS library and creating the cuDSS handle
217 void InitCuDSS();
218};
219
220} // namespace mfem
221
222#endif // MFEM_USE_CUDSS
223#endif // MFEM_CUDSS
cuDSS: A high-performance CUDA Library for Direct Sparse Solvers
Definition cudss.hpp:38
void Mult(const Vector &x, Vector &y) const override
Solve .
Definition cudss.cpp:401
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition cudss.cpp:350
MatType
Specify the type of matrix we are applying the solver to.
Definition cudss.hpp:42
@ NONSYMMETRIC
CUDSS_MTYPE_GENERAL: General matrix [default].
Definition cudss.hpp:44
@ SYMMETRIC_INDEFINITE
CUDSS_MTYPE_SYMMETRIC: Real symmetric matrix.
Definition cudss.hpp:46
@ SYMMETRIC_POSITIVE_DEFINITE
CUDSS_MTYPE_SPD: Symmetric positive-definite matrix.
Definition cudss.hpp:48
void SetReorderingReuse(bool reuse)
Set the flag controlling reuse of the symbolic factorization for multiple operators.
Definition cudss.cpp:191
CuDSSSolver & operator=(CuDSSSolver &&)=delete
MatViewType
Specify the view type of matrix we are applying the solver to.
Definition cudss.hpp:53
@ UPPER
CUDSS_MVIEW_UPPER: Upper-triangular matrix (including the diagonal).
Definition cudss.hpp:59
@ FULL
CUDSS_MVIEW_FULL: Full matrix [default].
Definition cudss.hpp:55
@ LOWER
CUDSS_MVIEW_LOWER: Lower-triangular matrix (including the diagonal).
Definition cudss.hpp:57
CuDSSSolver()
Constructor.
Definition cudss.cpp:60
void SetMatrixViewType(MatViewType mvtype)
Set the matrix view type.
Definition cudss.cpp:167
CuDSSSolver(CuDSSSolver &&)=delete
void SetMatrixSymType(MatType mtype_)
Set the matrix type.
Definition cudss.cpp:151
void ArrayMult(const Array< const Vector * > &X, Array< Vector * > &Y) const override
Solve .
Definition cudss.cpp:410
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:419
Abstract operator.
Definition operator.hpp:27
Base class for solvers.
Definition operator.hpp:855
Data type sparse matrix.
Definition sparsemat.hpp:51
Vector data type.
Definition vector.hpp:82
float real_t
Definition config.hpp:46