Skip to content

Commit 4ed4b14

Browse files
Improve default sparse solver choice
Given the benchmarks with @chriselrod and @YingboMa, it seems there is some point where a cutoff to UMFPACK makes sense. I'm placing it at 10_000 for now as a reasonable guess because we're very sure that <10_000 is bad for UMFPACK, but this should get a bit more tuning in the future. It should also depend on whether someone is using OpenBLAS or not.
1 parent 0656cae commit 4ed4b14

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/default.jl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ function defaultalg(A, b)
3333
elseif A isa SymTridiagonal
3434
alg = GenericFactorization(; fact_alg = ldlt!)
3535
elseif A isa SparseMatrixCSC
36-
alg = KLUFactorization()
36+
if length(b) <= 10_000
37+
alg = KLUFactorization()
38+
else
39+
alg = UMFPACKFactorization()
40+
end
3741

3842
# This catches the cases where a factorization overload could exist
3943
# For example, BlockBandedMatrix
@@ -96,8 +100,13 @@ function SciMLBase.solve(cache::LinearCache, alg::Nothing,
96100
alg = GenericFactorization(; fact_alg = ldlt!)
97101
SciMLBase.solve(cache, alg, args...; kwargs...)
98102
elseif A isa SparseMatrixCSC
99-
alg = KLUFactorization()
100-
SciMLBase.solve(cache, alg, args...; kwargs...)
103+
if length(b) <= 10_000
104+
alg = KLUFactorization()
105+
SciMLBase.solve(cache, alg, args...; kwargs...)
106+
else
107+
alg = UMFPACKFactorization()
108+
SciMLBase.solve(cache, alg, args...; kwargs...)
109+
end
101110

102111
# This catches the cases where a factorization overload could exist
103112
# For example, BlockBandedMatrix
@@ -158,8 +167,13 @@ function init_cacheval(alg::Nothing, A, b, u, Pl, Pr, maxiters, abstol, reltol,
158167
alg = GenericFactorization(; fact_alg = ldlt!)
159168
init_cacheval(alg, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
160169
elseif A isa SparseMatrixCSC
161-
alg = KLUFactorization()
162-
init_cacheval(alg, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
170+
if length(b) <= 10_000
171+
alg = KLUFactorization()
172+
init_cacheval(alg, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
173+
else
174+
alg = UMFPACKFactorization()
175+
init_cacheval(alg, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
176+
end
163177

164178
# This catches the cases where a factorization overload could exist
165179
# For example, BlockBandedMatrix

0 commit comments

Comments
 (0)