Skip to content

Commit 3a1c60e

Browse files
Merge pull request #93 from SciML/default
Expose a default algorithm choice alg
2 parents c09bca2 + 43c97da commit 3a1c60e

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LinearSolve"
22
uuid = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
33
authors = ["SciML"]
4-
version = "1.6.0"
4+
version = "1.7.0"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/default.jl

+50
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
## Default algorithm
22

3+
# Allows A === nothing as a stand-in for dense matrix
4+
function defaultalg(A,b)
5+
if A isa DiffEqArrayOperator
6+
A = A.A
7+
end
8+
9+
# Special case on Arrays: avoid BLAS for RecursiveFactorization.jl when
10+
# it makes sense according to the benchmarks, which is dependent on
11+
# whether MKL or OpenBLAS is being used
12+
if A === nothing || A isa Matrix
13+
if (A === nothing || eltype(A) <: Union{Float32,Float64,ComplexF32,ComplexF64}) &&
14+
ArrayInterface.can_setindex(b) && (length(b) <= 100 ||
15+
(isopenblas() && length(b) <= 500)
16+
)
17+
alg = RFLUFactorization()
18+
else
19+
alg = LUFactorization()
20+
end
21+
22+
# These few cases ensure the choice is optimal without the
23+
# dynamic dispatching of factorize
24+
elseif A isa Tridiagonal
25+
alg = GenericFactorization(;fact_alg=lu!)
26+
elseif A isa SymTridiagonal
27+
alg = GenericFactorization(;fact_alg=ldlt!)
28+
elseif A isa SparseMatrixCSC
29+
alg = UMFPACKFactorization()
30+
31+
# This catches the cases where a factorization overload could exist
32+
# For example, BlockBandedMatrix
33+
elseif ArrayInterface.isstructured(A)
34+
alg = GenericFactorization()
35+
36+
# This catches the case where A is a CuMatrix
37+
# Which does not have LU fully defined
38+
elseif !(A isa AbstractDiffEqOperator)
39+
alg = QRFactorization(false)
40+
41+
# Not factorizable operator, default to only using A*x
42+
# IterativeSolvers is faster on CPU but not GPU-compatible
43+
elseif cache.u isa Array
44+
alg = IterativeSolversJL_GMRES()
45+
else
46+
alg = KrylovJL_GMRES()
47+
end
48+
alg
49+
end
50+
51+
## Other dispatches are to decrease the dispatch cost
52+
353
function SciMLBase.solve(cache::LinearCache, alg::Nothing,
454
args...; kwargs...)
555
@unpack A = cache

0 commit comments

Comments
 (0)