Skip to content

Commit

Permalink
adding suitesparse::spqr
Browse files Browse the repository at this point in the history
  • Loading branch information
mtao committed Jan 4, 2025
1 parent 760ff26 commit d96792b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ option(POLYSOLVE_WITH_ACCELERATE "Enable Apple Accelerate" ${POLYSOLVE_ON_APP
option(POLYSOLVE_WITH_CHOLMOD "Enable Cholmod library" ON)
option(POLYSOLVE_WITH_UMFPACK "Enable UmfPack library" ON)
option(POLYSOLVE_WITH_SUPERLU "Enable SuperLU library" ON)
option(POLYSOLVE_WITH_SPQR "Enable SPQR library" ON)
option(POLYSOLVE_WITH_MKL "Enable MKL library" ${POLYSOLVE_NOT_ON_APPLE_SILICON})
option(POLYSOLVE_WITH_CUSOLVER "Enable cuSOLVER library" OFF)
option(POLYSOLVE_WITH_PARDISO "Enable Pardiso library" OFF)
Expand Down Expand Up @@ -269,6 +270,17 @@ if(POLYSOLVE_WITH_SUPERLU)
endif()
endif()

# SuperLU solver
if(POLYSOLVE_WITH_SPQR)
include(SPQR)
if(TARGET SuiteSparse::SPQR)
target_link_libraries(polysolve_linear PRIVATE SuiteSparse::SPQR)
target_compile_definitions(polysolve_linear PUBLIC POLYSOLVE_WITH_SPQR)
else()
message(WARNING "SPQR Not found, solver will not be available.")
endif()
endif()

# AMGCL solver
if(POLYSOLVE_WITH_AMGCL)
include(amgcl)
Expand Down
11 changes: 11 additions & 0 deletions cmake/recipes/spqr.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPQR solver

if(TARGET SparseSuite::SPQR)
return()
endif()

message(STATUS "Third-party: creating targets 'SuiteSparse::SPQR'")

# We do not have a build recipe for this, so find it as a system installed library.
find_package(SPQR)

27 changes: 27 additions & 0 deletions src/polysolve/linear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ template <typename _MatrixType, typename _OrderingType = COLAMDOrdering<typename
#ifdef POLYSOLVE_WITH_UMFPACK
#include <Eigen/UmfPackSupport>
#endif
#ifdef POLYSOLVE_WITH_SPQR
#include <Eigen/SPQRSupport>
namespace polysolve::linear {
template <>
void EigenDirect<Eigen::SPQR<StiffnessMatrix>>::analyze_pattern(const StiffnessMatrix& A, const int precond_num) {
m_Solver.compute(A);
}
template <>
void EigenDirect<Eigen::SPQR<StiffnessMatrix>>::factorize(const StiffnessMatrix &A)
{
m_Solver.compute(A);
if (m_Solver.info() == Eigen::NumericalIssue)
{
throw std::runtime_error("[EigenDirect] NumericalIssue encountered.");
}
}
}
#endif
#ifdef POLYSOLVE_WITH_SUPERLU
#include <Eigen/SuperLUSupport>
#endif
Expand Down Expand Up @@ -345,6 +363,12 @@ namespace polysolve::linear
{
RETURN_DIRECT_SOLVER_PTR(SuperLU, "Eigen::SuperLU");
#endif
#ifdef POLYSOLVE_WITH_SPQR
}
else if (solver == "Eigen::SPQR")
{
RETURN_DIRECT_SOLVER_PTR(SPQR, "Eigen::SPQR");
#endif
#ifdef POLYSOLVE_WITH_MKL
}
else if (solver == "Eigen::PardisoLLT")
Expand Down Expand Up @@ -492,6 +516,9 @@ namespace polysolve::linear
#ifdef POLYSOLVE_WITH_SUPERLU
"Eigen::SuperLU",
#endif
#ifdef POLYSOLVE_WITH_SPQR
"Eigen::SPQR",
#endif
#ifdef POLYSOLVE_WITH_MKL
"Eigen::PardisoLLT",
"Eigen::PardisoLDLT",
Expand Down

0 comments on commit d96792b

Please sign in to comment.