Skip to content

Commit 5c22570

Browse files
authored
Tweaks to SuperLU constructors (#4063)
* Construct unwrapped Python object at Python construction time. * std::move * clang-format * Don't use moved shared_ptr after move. * Fix * Update logging. * Remove assert, reference. * clang-format * Tweak * Do we really require pkgconfig at runtime? pkgconfig.py looks unused. * Tweaks
1 parent ab6fad1 commit 5c22570

4 files changed

Lines changed: 78 additions & 38 deletions

File tree

cpp/dolfinx/la/superlu_dist.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ template <typename T>
7070
std::unique_ptr<SuperLUDistStructs::SuperMatrix, SuperMatrixDeleter>
7171
create_supermatrix(const auto& A, auto& rowptr, auto& cols)
7272
{
73-
spdlog::info("Start set_operator");
73+
spdlog::info("Start create_supermatrix");
7474

7575
auto map0 = A.index_map(0);
7676
auto map1 = A.index_map(1);
@@ -113,7 +113,7 @@ create_supermatrix(const auto& A, auto& rowptr, auto& cols)
113113
else
114114
static_assert(dependent_false_v<T>, "Invalid scalar type");
115115

116-
spdlog::info("Finished set_operator");
116+
spdlog::info("Finished create_supermatrix");
117117
return p;
118118
}
119119
} // namespace
@@ -122,10 +122,12 @@ create_supermatrix(const auto& A, auto& rowptr, auto& cols)
122122
template <typename T>
123123
SuperLUDistMatrix<T>::SuperLUDistMatrix(std::shared_ptr<const MatrixCSR<T>> A,
124124
bool verbose)
125-
: _matA(A),
126-
_cols(std::make_unique<SuperLUDistStructs::vec_int_t>(col_indices(*A))),
127-
_rowptr(std::make_unique<SuperLUDistStructs::vec_int_t>(row_indices(*A))),
128-
_supermatrix(create_supermatrix<T>(*A, *_rowptr, *_cols)),
125+
: _matA(std::move(A)),
126+
_cols(
127+
std::make_unique<SuperLUDistStructs::vec_int_t>(col_indices(*_matA))),
128+
_rowptr(
129+
std::make_unique<SuperLUDistStructs::vec_int_t>(row_indices(*_matA))),
130+
_supermatrix(create_supermatrix<T>(*_matA, *_rowptr, *_cols)),
129131
_verbose(verbose)
130132
{
131133
}
@@ -137,6 +139,19 @@ SuperLUDistStructs::SuperMatrix* SuperLUDistMatrix<T>::supermatrix() const
137139
return _supermatrix.get();
138140
}
139141

142+
//----------------------------------------------------------------------------
143+
template <typename T>
144+
const MatrixCSR<T>& SuperLUDistMatrix<T>::matA() const
145+
{
146+
return *_matA;
147+
}
148+
149+
//----------------------------------------------------------------------------
150+
template class la::SuperLUDistMatrix<double>;
151+
template class la::SuperLUDistMatrix<float>;
152+
template class la::SuperLUDistMatrix<std::complex<double>>;
153+
//----------------------------------------------------------------------------
154+
140155
//----------------------------------------------------------------------------
141156
// Trick for declaring anonymous typedef structs from SuperLU_DIST
142157
struct dolfinx::la::SuperLUDistStructs::gridinfo_t : public ::gridinfo_t
@@ -153,11 +168,11 @@ void GridInfoDeleter::operator()(
153168

154169
//----------------------------------------------------------------------------
155170
template <typename T>
156-
SuperLUDistSolver<T>::SuperLUDistSolver(std::shared_ptr<const MatrixCSR<T>> A,
157-
bool verbose)
158-
: _superlu_matA(SuperLUDistMatrix<T>(A, verbose)),
171+
SuperLUDistSolver<T>::SuperLUDistSolver(
172+
std::shared_ptr<const SuperLUDistMatrix<T>> A, bool verbose)
173+
: _superlu_matA(std::move(A)),
159174
_gridinfo(
160-
[comm = A->comm()]
175+
[comm = _superlu_matA->matA().comm()]
161176
{
162177
int nprow = dolfinx::MPI::size(comm);
163178
int npcol = 1;
@@ -174,8 +189,8 @@ SuperLUDistSolver<T>::SuperLUDistSolver(std::shared_ptr<const MatrixCSR<T>> A,
174189
template <typename T>
175190
int SuperLUDistSolver<T>::solve(const la::Vector<T>& b, la::Vector<T>& u) const
176191
{
177-
int_t m = _superlu_matA.supermatrix()->nrow;
178-
int_t m_loc = ((NRformat_loc*)(_superlu_matA.supermatrix()->Store))->m_loc;
192+
int_t m = _superlu_matA->supermatrix()->nrow;
193+
int_t m_loc = ((NRformat_loc*)(_superlu_matA->supermatrix()->Store))->m_loc;
179194

180195
// RHS
181196
int_t ldb = m_loc;
@@ -207,7 +222,7 @@ int SuperLUDistSolver<T>::solve(const la::Vector<T>& b, la::Vector<T>& u) const
207222
dSOLVEstruct_t SOLVEstruct;
208223

209224
spdlog::info("Call SuperLU_DIST pdgssvx()");
210-
pdgssvx(&options, _superlu_matA.supermatrix(), &ScalePermstruct,
225+
pdgssvx(&options, _superlu_matA->supermatrix(), &ScalePermstruct,
211226
u.array().data(), ldb, nrhs, _gridinfo.get(), &LUstruct,
212227
&SOLVEstruct, berr.data(), &stat, &info);
213228

@@ -226,7 +241,7 @@ int SuperLUDistSolver<T>::solve(const la::Vector<T>& b, la::Vector<T>& u) const
226241
sSOLVEstruct_t SOLVEstruct;
227242

228243
spdlog::info("Call SuperLU_DIST psgssvx()");
229-
psgssvx(&options, _superlu_matA.supermatrix(), &ScalePermstruct,
244+
psgssvx(&options, _superlu_matA->supermatrix(), &ScalePermstruct,
230245
u.array().data(), ldb, nrhs, _gridinfo.get(), &LUstruct,
231246
&SOLVEstruct, berr.data(), &stat, &info);
232247

@@ -245,7 +260,7 @@ int SuperLUDistSolver<T>::solve(const la::Vector<T>& b, la::Vector<T>& u) const
245260
zSOLVEstruct_t SOLVEstruct;
246261

247262
spdlog::info("Call SuperLU_DIST pzgssvx()");
248-
pzgssvx(&options, _superlu_matA.supermatrix(), &ScalePermstruct,
263+
pzgssvx(&options, _superlu_matA->supermatrix(), &ScalePermstruct,
249264
reinterpret_cast<doublecomplex*>(u.array().data()), ldb, nrhs,
250265
_gridinfo.get(), &LUstruct, &SOLVEstruct, berr.data(), &stat,
251266
&info);

cpp/dolfinx/la/superlu_dist.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ class SuperLUDistMatrix
5353
/// Copy assignment
5454
SuperLUDistMatrix& operator=(const SuperLUDistMatrix&) = delete;
5555

56-
/// Get non-const pointer to SuperLU_DIST native SuperMatrix.
56+
/// Get non-const pointer to SuperLU_DIST SuperMatrix.
5757
SuperLUDistStructs::SuperMatrix* supermatrix() const;
5858

59+
/// Get MatrixCSR (const).
60+
const MatrixCSR<T>& matA() const;
61+
5962
private:
6063
// Saved matrix operator with rows and cols in required integer type.
6164
// cols and rowptr are required in opaque type "int_t" of
@@ -93,7 +96,7 @@ class SuperLUDistSolver
9396
/// @tparam T Scalar type.
9497
/// @param A Matrix to solve for.
9598
/// @param verbose Verbose output.
96-
SuperLUDistSolver(std::shared_ptr<const MatrixCSR<T>> A,
99+
SuperLUDistSolver(std::shared_ptr<const SuperLUDistMatrix<T>> A,
97100
bool verbose = false);
98101

99102
/// Copy constructor
@@ -113,7 +116,7 @@ class SuperLUDistSolver
113116

114117
private:
115118
// Wrapped SuperLU SuperMatrix
116-
const SuperLUDistMatrix<T> _superlu_matA;
119+
std::shared_ptr<const SuperLUDistMatrix<T>> _superlu_matA;
117120

118121
// Pointer to struct gridinfo_t
119122
std::unique_ptr<SuperLUDistStructs::gridinfo_t, GridInfoDeleter> _gridinfo;

python/doc/source/installation.rst

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ C++
3131
- `Boost <https://www.boost.org>`_
3232
- `CMake <https://cmake.org>`_ [build dependency]
3333
- HDF5 (with MPI support enabled)
34-
- MPI (MPI-3 or later).
35-
- `pkg-config <https://www.freedesktop.org/wiki/Software/pkg-config/>`_
34+
- MPI (MPI-3 or later)
35+
- `pkg-config <https://www.freedesktop.org/wiki/Software/pkg-config/>`_ [build dependency]
3636
- `pugixml <https://pugixml.org/>`_
3737
- `spdlog <https://github.com/gabime/spdlog/>`_
38-
- UFCx [``ufcx.h``, provided by FFCx package or FFCx UFCx CMake install
38+
- UFCx [``ufcx.h``, provided by FFCx Python package or FFCx UFCx CMake install
3939
at ``ffcx/cmake/*``]
4040
- At least one of ParMETIS [2]_, KaHIP or PT-SCOTCH [2]_
4141

@@ -45,8 +45,9 @@ From ParMETIS, KaHIP or PT-SCOTCH, ParMETIS is recommended.
4545

4646
- `ADIOS2 <https://github.com/ornladios/ADIOS2/>`_ (additional parallel
4747
IO support)
48-
- `PETSc <https://petsc.org/>`_ [1]_
49-
- `SLEPc <https://slepc.upv.es/>`_ (eigenvalue computations)
48+
- `PETSc <https://petsc.org/>`_ [1]_ (linear and non-linear problems)
49+
- `SLEPc <https://slepc.upv.es/>`_ (eigenvalue problems)
50+
- `SuperLU_DIST <https://github.com/xiaoyeli/superlu_dist/>`_ [2]_ (linear problems with ``dolfinx::la::MatrixCSR``).
5051

5152
.. rubric:: Optional for demos
5253

@@ -57,28 +58,43 @@ PETSc and FFCx are optional but recommended.
5758
Python interface
5859
****************
5960

60-
Requirements for the Python interface, in addition to the C++
61-
requirements.
61+
Requirements for the Python interface. Please see ``python/pyproject.toml`` for
62+
precise specification. Below we use the `pypi <https://pypi.org>`_ package names.
6263

63-
.. rubric:: Required
64+
.. rubric:: Build system requirements
6465

6566
- Python
66-
- Python CFFI (https://cffi.readthedocs.io/)
67-
- FFCx, UFL and Basix Python interface.
68-
- mpi4py (https://mpi4py.readthedocs.io/)
69-
- nanobind (https://github.com/wjakob/nanobind)
70-
- NumPy (https://www.numpy.org)
71-
- scikit-build-core[pyproject] (https://scikit-build-core.readthedocs.io)
67+
- DOLFINx C++ interface and all requirements
68+
- `scikit-build-core[pyproject] <https://scikit-build-core.readthedocs.io>`_
69+
- `mpi4py <https://mpi4py.readthedocs.io/>`_
70+
- `nanobind <https://github.com/wjakob/nanobind>`_ (static linking)
71+
- petsc4py (recommended, optional)
7272

73-
.. rubric:: Optional
73+
.. rubric:: Required runtime dependencies
74+
75+
- Python
76+
- fenics-basix, fenics-ffcx and fenics-ufl
77+
- `cffi <https://cffi.readthedocs.io/>`_
78+
- `mpi4py <https://mpi4py.readthedocs.io/>`_
79+
- `numpy <https://www.numpy.org>`_
80+
- `pkg-config <https://www.freedesktop.org/wiki/Software/pkg-config/>`_
81+
82+
.. rubric:: Optional runtime dependencies
7483

75-
- petsc4py (recommended)
84+
- petsc4py (linear and non-linear problems, recommended)
85+
- numba (custom kernels and assemblers)
86+
- `pyamg <https://github.com/pyamg/pyamg>`_ + scipy (serial linear problems)
7687

7788
.. rubric:: Optional for demos
7889

79-
- Numba
90+
- gmsh
91+
- networkx
92+
- numba
93+
- matplotlib
94+
- petsc4py
8095
- pyamg
81-
- pyvista (for plotting)
96+
- pyvista
97+
- scipy
8298
- slepc4py
8399

84100
Building and installing
@@ -118,4 +134,4 @@ the Python interface can be installed using::
118134
additionally configure MUMPS via PETSc with
119135
``--download-mumps-avoid-mpi-in-place``.
120136
121-
.. [2] PETSc can download and configure and build these libraries.
137+
.. [2] PETSc can also download, configure and build these libraries.

python/dolfinx/wrappers/la.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,13 @@ void declare_superlu_dist_solver(nb::module_& m, const std::string& type)
229229
[](dolfinx::la::SuperLUDistSolver<T>* solver,
230230
std::shared_ptr<const dolfinx::la::MatrixCSR<T>> Amat,
231231
bool verbose)
232-
{ new (solver) dolfinx::la::SuperLUDistSolver<T>(Amat, verbose); },
232+
{
233+
auto A_superlu
234+
= std::make_shared<const dolfinx::la::SuperLUDistMatrix<T>>(
235+
std::move(Amat), verbose);
236+
new (solver) dolfinx::la::SuperLUDistSolver<T>(std::move(A_superlu),
237+
verbose);
238+
},
233239
nb::arg("A"), nb::arg("verbose"))
234240
.def("solve", &dolfinx::la::SuperLUDistSolver<T>::solve);
235241
}

0 commit comments

Comments
 (0)