Skip to content

Commit e3b1e85

Browse files
author
teseoch
authored
Merge pull request #84 from mtao/mtao/add_spqr
Add QR
2 parents 019d137 + 7bdb3eb commit e3b1e85

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

.github/workflows/continuous.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ jobs:
4242
libglu1-mesa-dev \
4343
xorg-dev \
4444
mpi \
45-
ccache
45+
ccache \
46+
libsuitesparse-dev
4647
echo 'CACHE_PATH=~/.ccache' >> "$GITHUB_ENV"
4748
4849
- name: Dependencies (macOS)
4950
if: runner.os == 'macOS'
5051
run: |
51-
brew install ccache open-mpi
52+
brew install ccache open-mpi suitesparse
5253
echo 'CACHE_PATH=~/Library/Caches/ccache' >> "$GITHUB_ENV"
5354
5455
- name: Cache Build

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ option(POLYSOLVE_WITH_ACCELERATE "Enable Apple Accelerate" ${POLYSOLVE_ON_APP
7474
option(POLYSOLVE_WITH_CHOLMOD "Enable Cholmod library" ON)
7575
option(POLYSOLVE_WITH_UMFPACK "Enable UmfPack library" ON)
7676
option(POLYSOLVE_WITH_SUPERLU "Enable SuperLU library" ON)
77+
option(POLYSOLVE_WITH_SPQR "Enable SPQR library" ON)
7778
option(POLYSOLVE_WITH_MKL "Enable MKL library" ${POLYSOLVE_NOT_ON_APPLE_SILICON})
7879
option(POLYSOLVE_WITH_CUSOLVER "Enable cuSOLVER library" OFF)
7980
option(POLYSOLVE_WITH_PARDISO "Enable Pardiso library" OFF)
@@ -269,6 +270,17 @@ if(POLYSOLVE_WITH_SUPERLU)
269270
endif()
270271
endif()
271272

273+
# SuperLU solver
274+
if(POLYSOLVE_WITH_SPQR)
275+
include(spqr)
276+
if(TARGET SuiteSparse::SPQR)
277+
target_link_libraries(polysolve_linear PRIVATE SuiteSparse::SPQR)
278+
target_compile_definitions(polysolve_linear PUBLIC POLYSOLVE_WITH_SPQR)
279+
else()
280+
message(WARNING "SPQR Not found, solver will not be available.")
281+
endif()
282+
endif()
283+
272284
# AMGCL solver
273285
if(POLYSOLVE_WITH_AMGCL)
274286
include(amgcl)

cmake/recipes/spqr.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPQR solver
2+
3+
if(TARGET SparseSuite::SPQR)
4+
return()
5+
endif()
6+
7+
message(STATUS "Third-party: creating targets 'SuiteSparse::SPQR'")
8+
9+
# We do not have a build recipe for this, so find it as a system installed library.
10+
find_package(SPQR)
11+

src/polysolve/linear/Solver.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include <fstream>
1212

1313
// -----------------------------------------------------------------------------
14+
//
15+
// Subsequent macros assume a single template parameter and SparseQR fails due to requiring 2 parameters. this is because the OrderingType is not filled in.
16+
// SparseLU has a default declaration of _OrderingType to use COLAMDOrdering but SparseQR doesn't - so this just mimics that behavior. If Eigen adds such a default in the future this line will need to be guarded to avoid multiple defaults
17+
namespace Eigen {
18+
template <typename _MatrixType, typename _OrderingType = COLAMDOrdering<typename _MatrixType::StorageIndex> > class SparseQR;
19+
}
1420
#include <Eigen/Sparse>
1521
#ifdef POLYSOLVE_WITH_ACCELERATE
1622
#include <Eigen/AccelerateSupport>
@@ -21,6 +27,24 @@
2127
#ifdef POLYSOLVE_WITH_UMFPACK
2228
#include <Eigen/UmfPackSupport>
2329
#endif
30+
#ifdef POLYSOLVE_WITH_SPQR
31+
#include <Eigen/SPQRSupport>
32+
namespace polysolve::linear {
33+
template <>
34+
void EigenDirect<Eigen::SPQR<StiffnessMatrix>>::analyze_pattern(const StiffnessMatrix& A, const int precond_num) {
35+
m_Solver.compute(A);
36+
}
37+
template <>
38+
void EigenDirect<Eigen::SPQR<StiffnessMatrix>>::factorize(const StiffnessMatrix &A)
39+
{
40+
m_Solver.compute(A);
41+
if (m_Solver.info() == Eigen::NumericalIssue)
42+
{
43+
throw std::runtime_error("[EigenDirect] NumericalIssue encountered.");
44+
}
45+
}
46+
}
47+
#endif
2448
#ifdef POLYSOLVE_WITH_SUPERLU
2549
#include <Eigen/SuperLUSupport>
2650
#endif
@@ -293,6 +317,10 @@ namespace polysolve::linear
293317
else if (solver == "Eigen::SparseLU")
294318
{
295319
RETURN_DIRECT_SOLVER_PTR(SparseLU, "Eigen::SparseLU");
320+
}
321+
else if (solver == "Eigen::SparseQR")
322+
{
323+
RETURN_DIRECT_SOLVER_PTR(SparseQR, "Eigen::SparseQR");
296324
#ifdef POLYSOLVE_WITH_ACCELERATE
297325
}
298326
else if (solver == "Eigen::AccelerateLLT")
@@ -335,6 +363,12 @@ namespace polysolve::linear
335363
{
336364
RETURN_DIRECT_SOLVER_PTR(SuperLU, "Eigen::SuperLU");
337365
#endif
366+
#ifdef POLYSOLVE_WITH_SPQR
367+
}
368+
else if (solver == "Eigen::SPQR")
369+
{
370+
RETURN_DIRECT_SOLVER_PTR(SPQR, "Eigen::SPQR");
371+
#endif
338372
#ifdef POLYSOLVE_WITH_MKL
339373
}
340374
else if (solver == "Eigen::PardisoLLT")
@@ -465,6 +499,7 @@ namespace polysolve::linear
465499
return {{
466500
"Eigen::SimplicialLDLT",
467501
"Eigen::SparseLU",
502+
"Eigen::SparseQR",
468503
#ifdef POLYSOLVE_WITH_ACCELERATE
469504
"Eigen::AccelerateLLT",
470505
"Eigen::AccelerateLDLT",
@@ -481,6 +516,9 @@ namespace polysolve::linear
481516
#ifdef POLYSOLVE_WITH_SUPERLU
482517
"Eigen::SuperLU",
483518
#endif
519+
#ifdef POLYSOLVE_WITH_SPQR
520+
"Eigen::SPQR",
521+
#endif
484522
#ifdef POLYSOLVE_WITH_MKL
485523
"Eigen::PardisoLLT",
486524
"Eigen::PardisoLDLT",

0 commit comments

Comments
 (0)