DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
superlu_dist.h
1// Copyright (C) 2026 Jack S. Hale, Chris N. Richardson
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#ifdef HAS_SUPERLU_DIST
10
11#include <complex>
12#include <dolfinx/common/MPI.h>
13#include <dolfinx/la/MatrixCSR.h>
14#include <dolfinx/la/Vector.h>
15#include <memory>
16#include <string>
17#include <string_view>
18#include <vector>
19
20namespace dolfinx::la
21{
24{
25public:
26 struct SuperMatrix;
27 struct vec_int_t;
28 struct gridinfo_t;
30
31 struct sScalePermstruct_t;
32 struct dScalePermstruct_t;
33 struct zScalePermstruct_t;
34
35 struct sLUstruct_t;
36 struct dLUstruct_t;
37 struct zLUstruct_t;
38
39 struct sSOLVEstruct_t;
40 struct dSOLVEstruct_t;
41 struct zSOLVEstruct_t;
42};
43
44// SuperLU_DIST has structs that are 'typed' with prefixes d, s, z. This allows
45// the solver class to select the typed set based on T.
46namespace impl
47{
49template <typename...>
50constexpr bool always_false_v = false;
51
52template <typename T>
53struct map
54{
55 static_assert(always_false_v<T>, "Invalid scalar type");
56};
57
59template <>
60struct map<double>
61{
62 using ScalePermstruct_t = SuperLUDistStructs::dScalePermstruct_t;
63 using LUstruct_t = SuperLUDistStructs::dLUstruct_t;
64 using SOLVEstruct_t = SuperLUDistStructs::dSOLVEstruct_t;
65};
66
68template <>
69struct map<float>
70{
71 using ScalePermstruct_t = SuperLUDistStructs::sScalePermstruct_t;
72 using LUstruct_t = SuperLUDistStructs::sLUstruct_t;
73 using SOLVEstruct_t = SuperLUDistStructs::sSOLVEstruct_t;
74};
75
77template <>
78struct map<std::complex<double>>
79{
80 using ScalePermstruct_t = SuperLUDistStructs::zScalePermstruct_t;
81 using LUstruct_t = SuperLUDistStructs::zLUstruct_t;
82 using SOLVEstruct_t = SuperLUDistStructs::zSOLVEstruct_t;
83};
85
86} // namespace impl
87
89template <typename T>
90using map_t = impl::map<T>;
91
95{
98 void operator()(SuperLUDistStructs::SuperMatrix* A) const noexcept;
99};
100
103template <typename T>
105{
106public:
113
116
119
121 MPI_Comm comm() const;
122
125
126private:
127 dolfinx::MPI::Comm _comm;
128 // Deep copy of values from MatrixCSR.
129 std::vector<T> _matA_values;
130 // cols and rowptr are required in opaque type "int_t" of
131 // SuperLU_DIST.
132 std::unique_ptr<SuperLUDistStructs::vec_int_t> _cols;
133 std::unique_ptr<SuperLUDistStructs::vec_int_t> _rowptr;
134
135 // Pointer to native SuperMatrix for use in solver
136 std::unique_ptr<SuperLUDistStructs::SuperMatrix, SuperMatrixDeleter>
137 _supermatrix;
138};
139
143{
146 void operator()(SuperLUDistStructs::gridinfo_t* g) const noexcept;
147};
148
160
164{
166 void operator()(SuperLUDistStructs::dLUstruct_t* l) const noexcept;
168 void operator()(SuperLUDistStructs::sLUstruct_t* l) const noexcept;
170 void operator()(SuperLUDistStructs::zLUstruct_t* l) const noexcept;
171};
172
187
190template <typename T>
192{
193public:
202 SuperLUDistSolver(std::shared_ptr<const SuperLUDistMatrix<T>> A);
203
206
209
212
219 void set_option(std::string_view name, std::string_view value);
220
243
253 void set_A(std::shared_ptr<const SuperLUDistMatrix<T>> A,
254 std::string_view fact);
255
268 int solve(const Vector<T>& b, Vector<T>& u);
269
270private:
271 // Assembled left-hand side matrix
272 std::shared_ptr<const SuperLUDistMatrix<T>> _superlu_matA;
273
274 // Pointer to struct superlu_dist_options_t
275 std::unique_ptr<SuperLUDistStructs::superlu_dist_options_t> _options;
276
277 // Pointer to struct gridinfo_t
278 std::unique_ptr<SuperLUDistStructs::gridinfo_t, GridInfoDeleter> _gridinfo;
279
280 // Pointer to 'typed' struct *ScalePermstruct_t
281 std::unique_ptr<typename map_t<T>::ScalePermstruct_t, ScalePermStructDeleter>
282 _scalepermstruct;
283 // Pointer to 'typed' struct *LUstruct_t
284 std::unique_ptr<typename map_t<T>::LUstruct_t, LUStructDeleter> _lustruct;
285 // Pointer to 'typed' struct *SOLVEstruct
286 std::unique_ptr<typename map_t<T>::SOLVEstruct_t, SolveStructDeleter>
287 _solvestruct;
288
289 // True once pdgssvx has populated LUstruct with per-block-column arrays
290 // that must be released via Destroy_LU before LUstructFree.
291 bool _factored = false;
292};
293} // namespace dolfinx::la
294#endif
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:45
Distributed sparse matrix using compressed sparse row storage.
Definition MatrixCSR.h:71
Definition superlu_dist.h:105
SuperLUDistMatrix & operator=(const SuperLUDistMatrix &)=delete
Copy assignment (deleted).
SuperLUDistStructs::SuperMatrix * supermatrix() const
Get pointer to SuperLU_DIST SuperMatrix (non-const).
Definition superlu_dist.cpp:233
SuperLUDistMatrix(const MatrixCSR< T > &A)
Create SuperLU_DIST matrix operator.
Definition superlu_dist.cpp:218
MPI_Comm comm() const
Get MPI communicator that matrix is defined on.
Definition superlu_dist.cpp:227
SuperLUDistMatrix(const SuperLUDistMatrix &)=delete
Copy constructor (deleted).
void set_options(const SuperLUDistStructs::superlu_dist_options_t &options)
Set all solver options (native struct).
Definition superlu_dist.cpp:466
SuperLUDistSolver(std::shared_ptr< const SuperLUDistMatrix< T > > A)
Create solver for a SuperLU_DIST matrix operator.
Definition superlu_dist.cpp:389
void set_A(std::shared_ptr< const SuperLUDistMatrix< T > > A, std::string_view fact)
Set assembled left-hand side matrix A.
Definition superlu_dist.cpp:569
SuperLUDistSolver & operator=(const SuperLUDistSolver &)=delete
Copy assignment.
SuperLUDistSolver(const SuperLUDistSolver &)=delete
Copy constructor.
void set_option(std::string_view name, std::string_view value)
Set solver option name to value.
Definition superlu_dist.cpp:473
int solve(const Vector< T > &b, Vector< T > &u)
Solve linear system Au = b.
Definition superlu_dist.cpp:625
~SuperLUDistSolver()
Destructor. Frees internal LU arrays before LUstructFree.
Definition superlu_dist.cpp:552
Forward declare structs to avoid exposing SuperLU_DIST headers.
Definition superlu_dist.h:24
A vector that can be distributed across processes.
Definition Vector.h:50
Fetch the rows of B that correspond to the ghost columns of A.
Definition matmul.h:36
Linear algebra interface.
Definition dolfinx_la.h:7
impl::map< T > map_t
Map scalar type to SuperLU_DIST 'typed' structs.
Definition superlu_dist.h:90
Definition superlu_dist.h:143
void operator()(SuperLUDistStructs::gridinfo_t *g) const noexcept
Deletion of gridinfo_t.
Definition superlu_dist.cpp:315
Definition superlu_dist.h:164
void operator()(SuperLUDistStructs::dLUstruct_t *l) const noexcept
double implementation
Definition superlu_dist.cpp:343
Definition superlu_dist.h:152
void operator()(SuperLUDistStructs::dScalePermstruct_t *s) const noexcept
double implementation
Definition superlu_dist.cpp:322
Definition superlu_dist.h:176
void operator()(SuperLUDistStructs::dSOLVEstruct_t *S) const noexcept
double implementation
Definition superlu_dist.cpp:364
SuperLUDistStructs::superlu_dist_options_t * o
Pointer to options - required for *SOLVEstruct_t cleanup function.
Definition superlu_dist.h:178
Definition superlu_dist.cpp:34
Definition superlu_dist.cpp:292
Definition superlu_dist.cpp:268
Definition superlu_dist.cpp:296
Struct holding vector of type int_t.
Definition superlu_dist.cpp:39
Definition superlu_dist.cpp:300
Definition superlu_dist.h:95
void operator()(SuperLUDistStructs::SuperMatrix *A) const noexcept
Deletion on SuperMatrix.
Definition superlu_dist.cpp:44