|
1 | 1 | ## Default algorithm
|
2 | 2 |
|
| 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 | + |
3 | 53 | function SciMLBase.solve(cache::LinearCache, alg::Nothing,
|
4 | 54 | args...; kwargs...)
|
5 | 55 | @unpack A = cache
|
|
0 commit comments