Skip to content

Commit c7f44bb

Browse files
Merge pull request #238 from DilumAluthge/dpa/use-gpl-libs
Use `Preferences` to toggle precompilation of code that requires GPL dependencies
2 parents 0857619 + fb6fd69 commit c7f44bb

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ KLU = "ef3ab10e-7fda-4108-b977-705223b18434"
1313
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
1414
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
1515
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
16+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1617
RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
1718
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1819
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
@@ -31,6 +32,7 @@ IterativeSolvers = "0.9.2"
3132
KLU = "0.3.0, 0.4"
3233
Krylov = "0.9"
3334
KrylovKit = "0.5, 0.6"
35+
Preferences = "1"
3436
RecursiveFactorization = "0.2.8"
3537
Reexport = "1"
3638
SciMLBase = "1.68"

src/LinearSolve.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using KLU
1515
using FastLapackInterface
1616
using DocStringExtensions
1717
import GPUArraysCore
18+
import Preferences
1819

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

3940
# Code
4041

42+
const INCLUDE_SPARSE = Preferences.@load_preference("include_sparse", Base.USE_GPL_LIBS)
43+
4144
include("common.jl")
4245
include("factorization.jl")
4346
include("simplelu.jl")
@@ -47,6 +50,10 @@ include("solve_function.jl")
4750
include("default.jl")
4851
include("init.jl")
4952

53+
@static if INCLUDE_SPARSE
54+
include("factorization_sparse.jl")
55+
end
56+
5057
const IS_OPENBLAS = Ref(true)
5158
isopenblas() = IS_OPENBLAS[]
5259

@@ -60,12 +67,17 @@ SnoopPrecompile.@precompile_all_calls begin
6067
sol = solve(prob, LUFactorization())
6168
sol = solve(prob, RFLUFactorization())
6269
sol = solve(prob, KrylovJL_GMRES())
70+
end
6371

64-
A = sprand(4, 4, 0.3) + I
65-
prob = LinearProblem(A, b)
66-
sol = solve(prob)
67-
sol = solve(prob, KLUFactorization())
68-
sol = solve(prob, UMFPACKFactorization())
72+
@static if INCLUDE_SPARSE
73+
SnoopPrecompile.@precompile_all_calls begin
74+
A = sprand(4, 4, 0.3) + I
75+
b = rand(4)
76+
prob = LinearProblem(A, b)
77+
sol = solve(prob)
78+
sol = solve(prob, KLUFactorization())
79+
sol = solve(prob, UMFPACKFactorization())
80+
end
6981
end
7082

7183
export LUFactorization, SVDFactorization, QRFactorization, GenericFactorization,

src/default.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ function defaultalg(A::SymTridiagonal, b, ::OperatorAssumptions{true})
3434
GenericFactorization(; fact_alg = ldlt!)
3535
end
3636

37-
function defaultalg(A::SparseMatrixCSC, b, ::OperatorAssumptions{true})
38-
if length(b) <= 10_000
39-
KLUFactorization()
40-
else
41-
UMFPACKFactorization()
37+
@static if INCLUDE_SPARSE
38+
function defaultalg(A::SparseMatrixCSC, b, ::OperatorAssumptions{true})
39+
if length(b) <= 10_000
40+
KLUFactorization()
41+
else
42+
UMFPACKFactorization()
43+
end
44+
end
45+
else
46+
function defaultalg(A::SparseMatrixCSC, b, ::OperatorAssumptions{true})
47+
KrylovJL_GMRES()
4248
end
4349
end
4450

src/factorization.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ function _ldiv!(x::Vector, A::Factorization, b::Vector)
55
ldiv!(A, x)
66
end
77

8-
# Specialize QR for the non-square case
9-
# Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242
10-
function _ldiv!(x::Vector,
11-
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY,
12-
SuiteSparse.SPQR.QRSparse}, b::Vector)
13-
x .= A \ b
14-
end
15-
168
function SciMLBase.solve(cache::LinearCache, alg::AbstractFactorization; kwargs...)
179
if cache.isfresh
1810
fact = do_factorization(alg, cache.A, cache.b, cache.u)

src/factorization_sparse.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Specialize QR for the non-square case
2+
# Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242
3+
function _ldiv!(x::Vector,
4+
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY,
5+
SuiteSparse.SPQR.QRSparse}, b::Vector)
6+
x .= A \ b
7+
end

0 commit comments

Comments
 (0)