DOLFINx 0.11.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
17namespace dolfinx::la
18{
21{
22public:
23 struct SuperMatrix;
24 struct vec_int_t;
25 struct gridinfo_t;
27
28 struct sScalePermstruct_t;
29 struct dScalePermstruct_t;
30 struct zScalePermstruct_t;
31
32 struct sLUstruct_t;
33 struct dLUstruct_t;
34 struct zLUstruct_t;
35
36 struct sSOLVEstruct_t;
37 struct dSOLVEstruct_t;
38 struct zSOLVEstruct_t;
39};
40
41// SuperLU_DIST has structs that are 'typed' with prefixes d, s, z. This allows
42// the solver class to select the typed set based on T.
43namespace impl
44{
46template <typename...>
47constexpr bool always_false_v = false;
48
49template <typename T>
50struct map
51{
52 static_assert(always_false_v<T>, "Invalid scalar type");
53};
54
56template <>
57struct map<double>
58{
59 using ScalePermstruct_t = SuperLUDistStructs::dScalePermstruct_t;
60 using LUstruct_t = SuperLUDistStructs::dLUstruct_t;
61 using SOLVEstruct_t = SuperLUDistStructs::dSOLVEstruct_t;
62};
63
65template <>
66struct map<float>
67{
68 using ScalePermstruct_t = SuperLUDistStructs::sScalePermstruct_t;
69 using LUstruct_t = SuperLUDistStructs::sLUstruct_t;
70 using SOLVEstruct_t = SuperLUDistStructs::sSOLVEstruct_t;
71};
72
74template <>
75struct map<std::complex<double>>
76{
77 using ScalePermstruct_t = SuperLUDistStructs::zScalePermstruct_t;
78 using LUstruct_t = SuperLUDistStructs::zLUstruct_t;
79 using SOLVEstruct_t = SuperLUDistStructs::zSOLVEstruct_t;
80};
82
83} // namespace impl
84
86template <typename T>
87using map_t = impl::map<T>;
88
92{
95 void operator()(SuperLUDistStructs::SuperMatrix* A) const noexcept;
96};
97
99template <typename T>
101{
102public:
110
113
116
118 MPI_Comm comm() const;
119
122
123private:
124 dolfinx::MPI::Comm _comm;
125 // Deep copy of values from MatrixCSR.
126 std::vector<T> _matA_values;
127 // cols and rowptr are required in opaque type "int_t" of
128 // SuperLU_DIST.
129 std::unique_ptr<SuperLUDistStructs::vec_int_t> _cols;
130 std::unique_ptr<SuperLUDistStructs::vec_int_t> _rowptr;
131
132 // Pointer to native SuperMatrix for use in solver
133 std::unique_ptr<SuperLUDistStructs::SuperMatrix, SuperMatrixDeleter>
134 _supermatrix;
135};
136
140{
143 void operator()(SuperLUDistStructs::gridinfo_t* g) const noexcept;
144};
145
157
161{
163 void operator()(SuperLUDistStructs::dLUstruct_t* l) const noexcept;
165 void operator()(SuperLUDistStructs::sLUstruct_t* l) const noexcept;
167 void operator()(SuperLUDistStructs::zLUstruct_t* l) const noexcept;
168};
169
184
186template <typename T>
188{
189public:
199 SuperLUDistSolver(std::shared_ptr<const SuperLUDistMatrix<T>> A);
200
203
206
213 void set_option(std::string name, std::string value);
214
237
244 void set_A(std::shared_ptr<const SuperLUDistMatrix<T>> A);
245
258 int solve(const Vector<T>& b, Vector<T>& u) const;
259
260private:
261 // Assembled left-hand side matrix
262 std::shared_ptr<const SuperLUDistMatrix<T>> _superlu_matA;
263
264 // Pointer to struct superlu_dist_options_t
265 std::unique_ptr<SuperLUDistStructs::superlu_dist_options_t> _options;
266
267 // Pointer to struct gridinfo_t
268 std::unique_ptr<SuperLUDistStructs::gridinfo_t, GridInfoDeleter> _gridinfo;
269
270 // Pointer to 'typed' struct *ScalePermstruct_t
271 std::unique_ptr<typename map_t<T>::ScalePermstruct_t, ScalePermStructDeleter>
272 _scalepermstruct;
273 // Pointer to 'typed' struct *LUstruct_t
274 std::unique_ptr<typename map_t<T>::LUstruct_t, LUStructDeleter> _lustruct;
275 // Pointer to 'typed' struct *SOLVEstruct
276 std::unique_ptr<typename map_t<T>::SOLVEstruct_t, SolveStructDeleter>
277 _solvestruct;
278};
279} // namespace dolfinx::la
280#endif
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:42
Distributed sparse matrix using compressed sparse row storage.
Definition MatrixCSR.h:70
SuperLU_DIST matrix interface.
Definition superlu_dist.h:101
SuperLUDistMatrix & operator=(const SuperLUDistMatrix &)=delete
Copy assignment (deleted).
SuperLUDistStructs::SuperMatrix * supermatrix() const
Get pointer to SuperLU_DIST SuperMatrix (non-const).
Definition superlu_dist.cpp:154
SuperLUDistMatrix(const MatrixCSR< T > &A)
Create SuperLU_DIST matrix operator.
Definition superlu_dist.cpp:139
MPI_Comm comm() const
Get MPI communicator that matrix is defined on.
Definition superlu_dist.cpp:148
SuperLUDistMatrix(const SuperLUDistMatrix &)=delete
Copy constructor (deleted).
void set_A(std::shared_ptr< const SuperLUDistMatrix< T > > A)
Set assembled left-hand side matrix A.
Definition superlu_dist.cpp:468
void set_option(std::string name, std::string value)
Set solver option name to value.
Definition superlu_dist.cpp:391
SuperLUDistSolver(std::shared_ptr< const SuperLUDistMatrix< T > > A)
Create solver for a SuperLU_DIST matrix operator.
Definition superlu_dist.cpp:310
SuperLUDistSolver & operator=(const SuperLUDistSolver &)=delete
Copy assignment.
SuperLUDistSolver(const SuperLUDistSolver &)=delete
Copy constructor.
void set_options(SuperLUDistStructs::superlu_dist_options_t options)
Set all solver options (native struct).
Definition superlu_dist.cpp:383
int solve(const Vector< T > &b, Vector< T > &u) const
Solve linear system Au = b.
Definition superlu_dist.cpp:474
Forward declare structs to avoid exposing SuperLU_DIST headers.
Definition superlu_dist.h:21
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:87
Definition superlu_dist.h:140
void operator()(SuperLUDistStructs::gridinfo_t *g) const noexcept
Deletion of gridinfo_t.
Definition superlu_dist.cpp:236
Definition superlu_dist.h:161
void operator()(SuperLUDistStructs::dLUstruct_t *l) const noexcept
double implementation
Definition superlu_dist.cpp:264
Definition superlu_dist.h:149
void operator()(SuperLUDistStructs::dScalePermstruct_t *s) const noexcept
double implementation
Definition superlu_dist.cpp:243
Definition superlu_dist.h:173
void operator()(SuperLUDistStructs::dSOLVEstruct_t *S) const noexcept
double implementation
Definition superlu_dist.cpp:285
SuperLUDistStructs::superlu_dist_options_t * o
Pointer to options - required for *SOLVEstruct_t cleanup function.
Definition superlu_dist.h:175
Definition superlu_dist.cpp:30
Definition superlu_dist.cpp:213
Definition superlu_dist.cpp:189
Definition superlu_dist.cpp:217
Struct holding vector of type int_t.
Definition superlu_dist.cpp:35
Definition superlu_dist.cpp:221
Definition superlu_dist.h:92
void operator()(SuperLUDistStructs::SuperMatrix *A) const noexcept
Deletion on SuperMatrix.
Definition superlu_dist.cpp:40