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 <dolfinx/common/MPI.h>
12#include <dolfinx/la/MatrixCSR.h>
13#include <dolfinx/la/Vector.h>
14#include <memory>
15#include <string>
16#include <string_view>
17
18namespace dolfinx::la
19{
22{
23public:
24 struct SuperMatrix;
25 struct vec_int_t;
26 struct gridinfo_t;
28
29 struct sScalePermstruct_t;
30 struct dScalePermstruct_t;
31 struct zScalePermstruct_t;
32
33 struct sLUstruct_t;
34 struct dLUstruct_t;
35 struct zLUstruct_t;
36
37 struct sSOLVEstruct_t;
38 struct dSOLVEstruct_t;
39 struct zSOLVEstruct_t;
40};
41
42// SuperLU_DIST has structs that are 'typed' with prefixes d, s, z. This allows
43// the solver class to select the typed set based on T.
44namespace impl
45{
47template <typename...>
48constexpr bool always_false_v = false;
49
50template <typename T>
51struct map
52{
53 static_assert(always_false_v<T>, "Invalid scalar type");
54};
55
57template <>
58struct map<double>
59{
60 using ScalePermstruct_t = SuperLUDistStructs::dScalePermstruct_t;
61 using LUstruct_t = SuperLUDistStructs::dLUstruct_t;
62 using SOLVEstruct_t = SuperLUDistStructs::dSOLVEstruct_t;
63};
64
66template <>
67struct map<float>
68{
69 using ScalePermstruct_t = SuperLUDistStructs::sScalePermstruct_t;
70 using LUstruct_t = SuperLUDistStructs::sLUstruct_t;
71 using SOLVEstruct_t = SuperLUDistStructs::sSOLVEstruct_t;
72};
73
75template <>
76struct map<std::complex<double>>
77{
78 using ScalePermstruct_t = SuperLUDistStructs::zScalePermstruct_t;
79 using LUstruct_t = SuperLUDistStructs::zLUstruct_t;
80 using SOLVEstruct_t = SuperLUDistStructs::zSOLVEstruct_t;
81};
83
84} // namespace impl
85
87template <typename T>
88using map_t = impl::map<T>;
89
93{
96 void operator()(SuperLUDistStructs::SuperMatrix* A) const noexcept;
97};
98
101template <typename T>
103{
104public:
111
114
117
119 MPI_Comm comm() const;
120
123
124private:
125 dolfinx::MPI::Comm _comm;
126 // Deep copy of values from MatrixCSR.
127 std::vector<T> _matA_values;
128 // cols and rowptr are required in opaque type "int_t" of
129 // SuperLU_DIST.
130 std::unique_ptr<SuperLUDistStructs::vec_int_t> _cols;
131 std::unique_ptr<SuperLUDistStructs::vec_int_t> _rowptr;
132
133 // Pointer to native SuperMatrix for use in solver
134 std::unique_ptr<SuperLUDistStructs::SuperMatrix, SuperMatrixDeleter>
135 _supermatrix;
136};
137
141{
144 void operator()(SuperLUDistStructs::gridinfo_t* g) const noexcept;
145};
146
158
162{
164 void operator()(SuperLUDistStructs::dLUstruct_t* l) const noexcept;
166 void operator()(SuperLUDistStructs::sLUstruct_t* l) const noexcept;
168 void operator()(SuperLUDistStructs::zLUstruct_t* l) const noexcept;
169};
170
185
188template <typename T>
190{
191public:
200 SuperLUDistSolver(std::shared_ptr<const SuperLUDistMatrix<T>> A);
201
204
207
210
217 void set_option(std::string_view name, std::string_view value);
218
241
251 void set_A(std::shared_ptr<const SuperLUDistMatrix<T>> A, std::string fact);
252
265 int solve(const Vector<T>& b, Vector<T>& u);
266
267private:
268 // Assembled left-hand side matrix
269 std::shared_ptr<const SuperLUDistMatrix<T>> _superlu_matA;
270
271 // Pointer to struct superlu_dist_options_t
272 std::unique_ptr<SuperLUDistStructs::superlu_dist_options_t> _options;
273
274 // Pointer to struct gridinfo_t
275 std::unique_ptr<SuperLUDistStructs::gridinfo_t, GridInfoDeleter> _gridinfo;
276
277 // Pointer to 'typed' struct *ScalePermstruct_t
278 std::unique_ptr<typename map_t<T>::ScalePermstruct_t, ScalePermStructDeleter>
279 _scalepermstruct;
280 // Pointer to 'typed' struct *LUstruct_t
281 std::unique_ptr<typename map_t<T>::LUstruct_t, LUStructDeleter> _lustruct;
282 // Pointer to 'typed' struct *SOLVEstruct
283 std::unique_ptr<typename map_t<T>::SOLVEstruct_t, SolveStructDeleter>
284 _solvestruct;
285
286 // True once pdgssvx has populated LUstruct with per-block-column arrays
287 // that must be released via Destroy_LU before LUstructFree.
288 bool _factored = false;
289};
290} // namespace dolfinx::la
291#endif
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:43
Distributed sparse matrix using compressed sparse row storage.
Definition MatrixCSR.h:70
Definition superlu_dist.h:103
SuperLUDistMatrix & operator=(const SuperLUDistMatrix &)=delete
Copy assignment (deleted).
SuperLUDistStructs::SuperMatrix * supermatrix() const
Get pointer to SuperLU_DIST SuperMatrix (non-const).
Definition superlu_dist.cpp:235
SuperLUDistMatrix(const MatrixCSR< T > &A)
Create SuperLU_DIST matrix operator.
Definition superlu_dist.cpp:220
MPI_Comm comm() const
Get MPI communicator that matrix is defined on.
Definition superlu_dist.cpp:229
SuperLUDistMatrix(const SuperLUDistMatrix &)=delete
Copy constructor (deleted).
SuperLUDistSolver(std::shared_ptr< const SuperLUDistMatrix< T > > A)
Create solver for a SuperLU_DIST matrix operator.
Definition superlu_dist.cpp:391
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:475
void set_options(SuperLUDistStructs::superlu_dist_options_t options)
Set all solver options (native struct).
Definition superlu_dist.cpp:468
int solve(const Vector< T > &b, Vector< T > &u)
Solve linear system Au = b.
Definition superlu_dist.cpp:615
~SuperLUDistSolver()
Destructor. Frees internal LU arrays before LUstructFree.
Definition superlu_dist.cpp:553
void set_A(std::shared_ptr< const SuperLUDistMatrix< T > > A, std::string fact)
Set assembled left-hand side matrix A.
Definition superlu_dist.cpp:570
Forward declare structs to avoid exposing SuperLU_DIST headers.
Definition superlu_dist.h:22
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:88
Definition superlu_dist.h:141
void operator()(SuperLUDistStructs::gridinfo_t *g) const noexcept
Deletion of gridinfo_t.
Definition superlu_dist.cpp:317
Definition superlu_dist.h:162
void operator()(SuperLUDistStructs::dLUstruct_t *l) const noexcept
double implementation
Definition superlu_dist.cpp:345
Definition superlu_dist.h:150
void operator()(SuperLUDistStructs::dScalePermstruct_t *s) const noexcept
double implementation
Definition superlu_dist.cpp:324
Definition superlu_dist.h:174
void operator()(SuperLUDistStructs::dSOLVEstruct_t *S) const noexcept
double implementation
Definition superlu_dist.cpp:366
SuperLUDistStructs::superlu_dist_options_t * o
Pointer to options - required for *SOLVEstruct_t cleanup function.
Definition superlu_dist.h:176
Definition superlu_dist.cpp:33
Definition superlu_dist.cpp:294
Definition superlu_dist.cpp:270
Definition superlu_dist.cpp:298
Struct holding vector of type int_t.
Definition superlu_dist.cpp:38
Definition superlu_dist.cpp:302
Definition superlu_dist.h:93
void operator()(SuperLUDistStructs::SuperMatrix *A) const noexcept
Deletion on SuperMatrix.
Definition superlu_dist.cpp:43