Skip to content

Commit

Permalink
Merge pull request #238 from DilumAluthge/dpa/use-gpl-libs
Browse files Browse the repository at this point in the history
Use `Preferences` to toggle precompilation of code that requires GPL dependencies
  • Loading branch information
ChrisRackauckas authored Nov 28, 2022
2 parents 0857619 + fb6fd69 commit c7f44bb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ KLU = "ef3ab10e-7fda-4108-b977-705223b18434"
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
Expand All @@ -31,6 +32,7 @@ IterativeSolvers = "0.9.2"
KLU = "0.3.0, 0.4"
Krylov = "0.9"
KrylovKit = "0.5, 0.6"
Preferences = "1"
RecursiveFactorization = "0.2.8"
Reexport = "1"
SciMLBase = "1.68"
Expand Down
22 changes: 17 additions & 5 deletions src/LinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using KLU
using FastLapackInterface
using DocStringExtensions
import GPUArraysCore
import Preferences

# wrap
import Krylov
Expand All @@ -38,6 +39,8 @@ needs_concrete_A(alg::AbstractSolveFunction) = false

# Code

const INCLUDE_SPARSE = Preferences.@load_preference("include_sparse", Base.USE_GPL_LIBS)

include("common.jl")
include("factorization.jl")
include("simplelu.jl")
Expand All @@ -47,6 +50,10 @@ include("solve_function.jl")
include("default.jl")
include("init.jl")

@static if INCLUDE_SPARSE
include("factorization_sparse.jl")
end

const IS_OPENBLAS = Ref(true)
isopenblas() = IS_OPENBLAS[]

Expand All @@ -60,12 +67,17 @@ SnoopPrecompile.@precompile_all_calls begin
sol = solve(prob, LUFactorization())
sol = solve(prob, RFLUFactorization())
sol = solve(prob, KrylovJL_GMRES())
end

A = sprand(4, 4, 0.3) + I
prob = LinearProblem(A, b)
sol = solve(prob)
sol = solve(prob, KLUFactorization())
sol = solve(prob, UMFPACKFactorization())
@static if INCLUDE_SPARSE
SnoopPrecompile.@precompile_all_calls begin
A = sprand(4, 4, 0.3) + I
b = rand(4)
prob = LinearProblem(A, b)
sol = solve(prob)
sol = solve(prob, KLUFactorization())
sol = solve(prob, UMFPACKFactorization())
end
end

export LUFactorization, SVDFactorization, QRFactorization, GenericFactorization,
Expand Down
16 changes: 11 additions & 5 deletions src/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ function defaultalg(A::SymTridiagonal, b, ::OperatorAssumptions{true})
GenericFactorization(; fact_alg = ldlt!)
end

function defaultalg(A::SparseMatrixCSC, b, ::OperatorAssumptions{true})
if length(b) <= 10_000
KLUFactorization()
else
UMFPACKFactorization()
@static if INCLUDE_SPARSE
function defaultalg(A::SparseMatrixCSC, b, ::OperatorAssumptions{true})
if length(b) <= 10_000
KLUFactorization()
else
UMFPACKFactorization()
end
end
else
function defaultalg(A::SparseMatrixCSC, b, ::OperatorAssumptions{true})
KrylovJL_GMRES()
end
end

Expand Down
8 changes: 0 additions & 8 deletions src/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ function _ldiv!(x::Vector, A::Factorization, b::Vector)
ldiv!(A, x)
end

# Specialize QR for the non-square case
# Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242
function _ldiv!(x::Vector,
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY,
SuiteSparse.SPQR.QRSparse}, b::Vector)
x .= A \ b
end

function SciMLBase.solve(cache::LinearCache, alg::AbstractFactorization; kwargs...)
if cache.isfresh
fact = do_factorization(alg, cache.A, cache.b, cache.u)
Expand Down
7 changes: 7 additions & 0 deletions src/factorization_sparse.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Specialize QR for the non-square case
# Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242
function _ldiv!(x::Vector,
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY,
SuiteSparse.SPQR.QRSparse}, b::Vector)
x .= A \ b
end

0 comments on commit c7f44bb

Please sign in to comment.