diff --git a/docs/src/basics/FAQ.md b/docs/src/basics/FAQ.md index 8e07a9957..293468c6b 100644 --- a/docs/src/basics/FAQ.md +++ b/docs/src/basics/FAQ.md @@ -83,5 +83,5 @@ Pl = LinearSolve.ComposePreconditioner(LinearSolve.InvPreconditioner(Diagonal(we Pr = Diagonal(weights) prob = LinearProblem(A, b) -sol = solve(prob, KrylovJL_GMRES(precs=Returns((Pl,Pr)))) +sol = solve(prob, KrylovJL_GMRES(precs = Returns((Pl, Pr)))) ``` diff --git a/ext/LinearSolvePardisoExt.jl b/ext/LinearSolvePardisoExt.jl index 0318bb8a7..3f7db0c98 100644 --- a/ext/LinearSolvePardisoExt.jl +++ b/ext/LinearSolvePardisoExt.jl @@ -134,11 +134,14 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::PardisoJL; kwargs if cache.isfresh phase = alg.cache_analysis ? Pardiso.NUM_FACT : Pardiso.ANALYSIS_NUM_FACT Pardiso.set_phase!(cache.cacheval, phase) - Pardiso.pardiso(cache.cacheval, SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), eltype(A)[]) + Pardiso.pardiso(cache.cacheval, + SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), + eltype(A)[]) cache.isfresh = false end Pardiso.set_phase!(cache.cacheval, Pardiso.SOLVE_ITERATIVE_REFINE) - Pardiso.pardiso(cache.cacheval, u, SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), b) + Pardiso.pardiso(cache.cacheval, u, + SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), b) return SciMLBase.build_linear_solution(alg, cache.u, nothing, cache) end diff --git a/src/LinearSolve.jl b/src/LinearSolve.jl index 4e6c9e25d..ef86452b9 100644 --- a/src/LinearSolve.jl +++ b/src/LinearSolve.jl @@ -5,47 +5,48 @@ if isdefined(Base, :Experimental) && end import PrecompileTools - using ArrayInterface - using RecursiveFactorization - using Base: cache_dependencies, Bool - using LinearAlgebra - using SparseArrays - using SparseArrays: AbstractSparseMatrixCSC, nonzeros, rowvals, getcolptr - using LazyArrays: @~, BroadcastArray - using SciMLBase: AbstractLinearAlgorithm - using SciMLOperators - using SciMLOperators: AbstractSciMLOperator, IdentityOperator - using Setfield - using UnPack - using KLU - using Sparspak - using FastLapackInterface - using DocStringExtensions - using EnumX - using Markdown - using ChainRulesCore - import InteractiveUtils - - import StaticArraysCore: StaticArray, SVector, MVector, SMatrix, MMatrix - - using LinearAlgebra: BlasInt, LU - using LinearAlgebra.LAPACK: require_one_based_indexing, - chkfinite, chkstride1, - @blasfunc, chkargsok - - import GPUArraysCore - import Preferences - import ConcreteStructs: @concrete - - # wrap - import Krylov - using SciMLBase - import Preferences +using ArrayInterface +using RecursiveFactorization +using Base: cache_dependencies, Bool +using LinearAlgebra +using SparseArrays +using SparseArrays: AbstractSparseMatrixCSC, nonzeros, rowvals, getcolptr +using LazyArrays: @~, BroadcastArray +using SciMLBase: AbstractLinearAlgorithm +using SciMLOperators +using SciMLOperators: AbstractSciMLOperator, IdentityOperator +using Setfield +using UnPack +using KLU +using Sparspak +using FastLapackInterface +using DocStringExtensions +using EnumX +using Markdown +using ChainRulesCore +import InteractiveUtils + +import StaticArraysCore: StaticArray, SVector, MVector, SMatrix, MMatrix + +using LinearAlgebra: BlasInt, LU +using LinearAlgebra.LAPACK: require_one_based_indexing, + chkfinite, chkstride1, + @blasfunc, chkargsok + +import GPUArraysCore +import Preferences +import ConcreteStructs: @concrete + +# wrap +import Krylov +using SciMLBase +import Preferences const CRC = ChainRulesCore @static if Sys.ARCH === :x86_64 || Sys.ARCH === :i686 - if Preferences.@load_preference("LoadMKL_JLL", !occursin("EPYC", Sys.cpu_info()[1].model)) + if Preferences.@load_preference("LoadMKL_JLL", + !occursin("EPYC", Sys.cpu_info()[1].model)) using MKL_jll const usemkl = MKL_jll.is_available() else diff --git a/src/common.jl b/src/common.jl index 3f145fc69..bcaaab1f7 100644 --- a/src/common.jl +++ b/src/common.jl @@ -150,7 +150,7 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm, assumptions = OperatorAssumptions(issquare(prob.A)), sensealg = LinearSolveAdjoint(), kwargs...) - (;A, b, u0, p) = prob + (; A, b, u0, p) = prob A = if alias_A || A isa SMatrix A @@ -206,22 +206,21 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm, cache = LinearCache{typeof(A), typeof(b), typeof(u0_), typeof(p), typeof(alg), Tc, typeof(Pl), typeof(Pr), typeof(reltol), typeof(assumptions.issq), - typeof(sensealg)}(A, b, u0_, p, alg, cacheval, isfresh, precsisfresh, Pl, Pr, abstol, reltol, + typeof(sensealg)}( + A, b, u0_, p, alg, cacheval, isfresh, precsisfresh, Pl, Pr, abstol, reltol, maxiters, verbose, assumptions, sensealg) return cache end - function SciMLBase.reinit!(cache::LinearCache; - A = nothing, - b = cache.b, - u = cache.u, - p = nothing, - reinit_cache = false, - reuse_precs = false) + A = nothing, + b = cache.b, + u = cache.u, + p = nothing, + reinit_cache = false, + reuse_precs = false) (; alg, cacheval, abstol, reltol, maxiters, verbose, assumptions, sensealg) = cache - isfresh = !isnothing(A) precsisfresh = !reuse_precs && (isfresh || !isnothing(p)) isfresh |= cache.isfresh @@ -234,9 +233,11 @@ function SciMLBase.reinit!(cache::LinearCache; Pl = cache.Pl Pr = cache.Pr if reinit_cache - return LinearCache{typeof(A), typeof(b), typeof(u), typeof(p), typeof(alg), typeof(cacheval), + return LinearCache{ + typeof(A), typeof(b), typeof(u), typeof(p), typeof(alg), typeof(cacheval), typeof(Pl), typeof(Pr), typeof(reltol), typeof(assumptions.issq), - typeof(sensealg)}(A, b, u, p, alg, cacheval, precsisfresh, isfresh, Pl, Pr, abstol, reltol, + typeof(sensealg)}( + A, b, u, p, alg, cacheval, precsisfresh, isfresh, Pl, Pr, abstol, reltol, maxiters, verbose, assumptions, sensealg) else cache.A = A diff --git a/src/default.jl b/src/default.jl index 525c5360f..a0ebb705f 100644 --- a/src/default.jl +++ b/src/default.jl @@ -179,8 +179,8 @@ function defaultalg(A, b, assump::OperatorAssumptions{Bool}) __conditioning(assump) === OperatorCondition.WellConditioned) if length(b) <= 10 DefaultAlgorithmChoice.RFLUFactorization - elseif appleaccelerate_isavailable() && b isa Array && - eltype(b) <: Union{Float32, Float64, ComplexF32, ComplexF64} + elseif appleaccelerate_isavailable() && b isa Array && + eltype(b) <: Union{Float32, Float64, ComplexF32, ComplexF64} DefaultAlgorithmChoice.AppleAccelerateLUFactorization elseif (length(b) <= 100 || (isopenblas() && length(b) <= 500) || (usemkl && length(b) <= 200)) && @@ -189,8 +189,8 @@ function defaultalg(A, b, assump::OperatorAssumptions{Bool}) DefaultAlgorithmChoice.RFLUFactorization #elseif A === nothing || A isa Matrix # alg = FastLUFactorization() - elseif usemkl && b isa Array && - eltype(b) <: Union{Float32, Float64, ComplexF32, ComplexF64} + elseif usemkl && b isa Array && + eltype(b) <: Union{Float32, Float64, ComplexF32, ComplexF64} DefaultAlgorithmChoice.MKLLUFactorization else DefaultAlgorithmChoice.LUFactorization diff --git a/src/extension_algs.jl b/src/extension_algs.jl index 2559a210f..da444912b 100644 --- a/src/extension_algs.jl +++ b/src/extension_algs.jl @@ -217,7 +217,7 @@ All values default to `nothing` and the solver internally determines the values given the input types, and these keyword arguments are only for overriding the default handling process. This should not be required by most users. """ -struct PardisoJL{T1, T2} <: AbstractSparseFactorization +struct PardisoJL{T1, T2} <: AbstractSparseFactorization nprocs::Union{Int, Nothing} solver_type::T1 matrix_type::T2 diff --git a/test/basictests.jl b/test/basictests.jl index e9492e4d9..f9ddd302c 100644 --- a/test/basictests.jl +++ b/test/basictests.jl @@ -267,12 +267,12 @@ end @testset "KrylovJL" begin kwargs = (; gmres_restart = 5) - precs = (A,p=nothing) -> (BlockJacobiPreconditioner(A, 2), I) + precs = (A, p = nothing) -> (BlockJacobiPreconditioner(A, 2), I) algorithms = ( ("Default", KrylovJL(kwargs...)), ("CG", KrylovJL_CG(kwargs...)), ("GMRES", KrylovJL_GMRES(kwargs...)), - ("GMRES_prec", KrylovJL_GMRES(;precs, ldiv=false, kwargs...)), + ("GMRES_prec", KrylovJL_GMRES(; precs, ldiv = false, kwargs...)), # ("BICGSTAB",KrylovJL_BICGSTAB(kwargs...)), ("MINRES", KrylovJL_MINRES(kwargs...)) ) @@ -579,28 +579,27 @@ end # test default algorithn @time "solve MySparseMatrixCSC" u=solve(pr) @test norm(u - u0, Inf) < 1.0e-13 - + # test Krylov algorithm with reinit! pr = LinearProblem(B, b) - solver=KrylovJL_CG() - cache=init(pr,solver,maxiters=1000,reltol=1.0e-10) - u=solve!(cache) + solver = KrylovJL_CG() + cache = init(pr, solver, maxiters = 1000, reltol = 1.0e-10) + u = solve!(cache) A1 = spdiagm(1 => -ones(N - 1), 0 => fill(100.0, N), -1 => -ones(N - 1)) - b1=A1*u0 - B1= MySparseMatrixCSC(A1) + b1 = A1 * u0 + B1 = MySparseMatrixCSC(A1) @test norm(u - u0, Inf) < 1.0e-8 - reinit!(cache; A=B1, b=b1) - u=solve!(cache) + reinit!(cache; A = B1, b = b1) + u = solve!(cache) @test norm(u - u0, Inf) < 1.0e-8 - + # test factorization with reinit! pr = LinearProblem(B, b) - solver=SparspakFactorization() - cache=init(pr,solver) - u=solve!(cache) + solver = SparspakFactorization() + cache = init(pr, solver) + u = solve!(cache) @test norm(u - u0, Inf) < 1.0e-8 - reinit!(cache; A=B1, b=b1) - u=solve!(cache) + reinit!(cache; A = B1, b = b1) + u = solve!(cache) @test norm(u - u0, Inf) < 1.0e-8 - end diff --git a/test/enzyme.jl b/test/enzyme.jl index b09c0de54..1650c453b 100644 --- a/test/enzyme.jl +++ b/test/enzyme.jl @@ -207,9 +207,9 @@ end @show fd_jac en_jac = map(onehot(A)) do dA - return only(Enzyme.autodiff(set_runtime_activity(Forward), fnice, - Duplicated(A, dA), Const(b1), Const(alg))) - end |> collect + return only(Enzyme.autodiff(set_runtime_activity(Forward), fnice, + Duplicated(A, dA), Const(b1), Const(alg))) + end |> collect @show en_jac @test en_jac≈fd_jac rtol=1e-4 diff --git a/test/pardiso/pardiso.jl b/test/pardiso/pardiso.jl index c6af3cf4d..0a402005f 100644 --- a/test/pardiso/pardiso.jl +++ b/test/pardiso/pardiso.jl @@ -18,24 +18,23 @@ cache_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiter = 30) prob2 = LinearProblem(A2, b2) -algs=LinearSolve.SciMLLinearSolveAlgorithm[PardisoJL()] -solvers=Pardiso.AbstractPardisoSolver[] -extended_algs=LinearSolve.SciMLLinearSolveAlgorithm[PardisoJL()] +algs = LinearSolve.SciMLLinearSolveAlgorithm[PardisoJL()] +solvers = Pardiso.AbstractPardisoSolver[] +extended_algs = LinearSolve.SciMLLinearSolveAlgorithm[PardisoJL()] if Pardiso.mkl_is_available() - push!(algs,MKLPardisoFactorize()) - push!(solvers,Pardiso.MKLPardisoSolver()) - extended_algs=vcat(extended_algs,[MKLPardisoFactorize(), MKLPardisoIterate()]) + push!(algs, MKLPardisoFactorize()) + push!(solvers, Pardiso.MKLPardisoSolver()) + extended_algs = vcat(extended_algs, [MKLPardisoFactorize(), MKLPardisoIterate()]) @info "Testing MKL Pardiso" end - + if Pardiso.panua_is_available() - push!(algs,PanuaPardisoFactorize()) - push!(solvers,Pardiso.PardisoSolver()) - extended_algs=vcat(extended_algs,[PanuaPardisoFactorize(), PanuaPardisoIterate()]) + push!(algs, PanuaPardisoFactorize()) + push!(solvers, Pardiso.PardisoSolver()) + extended_algs = vcat(extended_algs, [PanuaPardisoFactorize(), PanuaPardisoIterate()]) @info "Testing Panua Pardiso" -end - +end for alg in extended_algs u = solve(prob1, alg; cache_kwargs...).u @@ -46,8 +45,6 @@ for alg in extended_algs @test A2 * u ≈ b2 end - - Random.seed!(10) A = sprand(n, n, 0.8); A2 = 2.0 .* A; @@ -55,7 +52,6 @@ b1 = rand(n); b2 = rand(n); prob = LinearProblem(copy(A), copy(b1)) - linsolve = init(prob, UMFPACKFactorization()) sol11 = solve!(linsolve) linsolve = LinearSolve.set_b(sol11.cache, copy(b2)) @@ -63,8 +59,6 @@ sol12 = solve!(linsolve) linsolve = LinearSolve.set_A(sol12.cache, copy(A2)) sol13 = solve!(linsolve) - - for alg in algs linsolve = init(prob, alg) sol31 = solve!(linsolve) @@ -77,29 +71,89 @@ for alg in algs @test sol13.u ≈ sol33.u end - # Test for problem from #497 function makeA() n = 60 - colptr = [1, 4, 7, 11, 15, 17, 22, 26, 30, 34, 38, 40, 46, 50, 54, 58, 62, 64, 70, 74, 78, 82, 86, 88, 94, 98, 102, 106, 110, 112, 118, 122, 126, 130, 134, 136, 142, 146, 150, 154, 158, 160, 166, 170, 174, 178, 182, 184, 190, 194, 198, 202, 206, 208, 214, 218, 222, 224, 226, 228, 232] - rowval = [1, 3, 4, 1, 2, 4, 2, 4, 9, 10, 3, 5, 11, 12, 1, 3, 2, 4, 6, 11, 12, 2, 7, 9, 10, 2, 7, 8, 10, 8, 10, 15, 16, 9, 11, 17, 18, 7, 9, 2, 8, 10, 12, 17, 18, 8, 13, 15, 16, 8, 13, 14, 16, 14, 16, 21, 22, 15, 17, 23, 24, 13, 15, 8, 14, 16, 18, 23, 24, 14, 19, 21, 22, 14, 19, 20, 22, 20, 22, 27, 28, 21, 23, 29, 30, 19, 21, 14, 20, 22, 24, 29, 30, 20, 25, 27, 28, 20, 25, 26, 28, 26, 28, 33, 34, 27, 29, 35, 36, 25, 27, 20, 26, 28, 30, 35, 36, 26, 31, 33, 34, 26, 31, 32, 34, 32, 34, 39, 40, 33, 35, 41, 42, 31, 33, 26, 32, 34, 36, 41, 42, 32, 37, 39, 40, 32, 37, 38, 40, 38, 40, 45, 46, 39, 41, 47, 48, 37, 39, 32, 38, 40, 42, 47, 48, 38, 43, 45, 46, 38, 43, 44, 46, 44, 46, 51, 52, 45, 47, 53, 54, 43, 45, 38, 44, 46, 48, 53, 54, 44, 49, 51, 52, 44, 49, 50, 52, 50, 52, 57, 58, 51, 53, 59, 60, 49, 51, 44, 50, 52, 54, 59, 60, 50, 55, 57, 58, 50, 55, 56, 58, 56, 58, 57, 59, 55, 57, 50, 56, 58, 60] - nzval = [-0.64, 1.0, -1.0, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -1.0806825309567203, 1.0, 2.370597639417811, -2.3705976394178108, 10.698449178570607, -11.083604432603583, -0.2770901108150896, 1.0] + colptr = [1, 4, 7, 11, 15, 17, 22, 26, 30, 34, 38, 40, 46, 50, 54, 58, + 62, 64, 70, 74, 78, 82, 86, 88, 94, 98, 102, 106, 110, 112, + 118, 122, 126, 130, 134, 136, 142, 146, 150, 154, 158, 160, + 166, 170, 174, 178, 182, 184, 190, 194, 198, 202, 206, 208, + 214, 218, 222, 224, 226, 228, 232] + rowval = [1, 3, 4, 1, 2, 4, 2, 4, 9, 10, 3, 5, 11, 12, 1, 3, 2, 4, 6, + 11, 12, 2, 7, 9, 10, 2, 7, 8, 10, 8, 10, 15, 16, 9, 11, 17, + 18, 7, 9, 2, 8, 10, 12, 17, 18, 8, 13, 15, 16, 8, 13, 14, 16, + 14, 16, 21, 22, 15, 17, 23, 24, 13, 15, 8, 14, 16, 18, 23, 24, + 14, 19, 21, 22, 14, 19, 20, 22, 20, 22, 27, 28, 21, 23, 29, 30, + 19, 21, 14, 20, 22, 24, 29, 30, 20, 25, 27, 28, 20, 25, 26, 28, + 26, 28, 33, 34, 27, 29, 35, 36, 25, 27, 20, 26, 28, 30, 35, 36, + 26, 31, 33, 34, 26, 31, 32, 34, 32, 34, 39, 40, 33, 35, 41, 42, + 31, 33, 26, 32, 34, 36, 41, 42, 32, 37, 39, 40, 32, 37, 38, 40, + 38, 40, 45, 46, 39, 41, 47, 48, 37, 39, 32, 38, 40, 42, 47, 48, + 38, 43, 45, 46, 38, 43, 44, 46, 44, 46, 51, 52, 45, 47, 53, 54, + 43, 45, 38, 44, 46, 48, 53, 54, 44, 49, 51, 52, 44, 49, 50, 52, + 50, 52, 57, 58, 51, 53, 59, 60, 49, 51, 44, 50, 52, 54, 59, 60, + 50, 55, 57, 58, 50, 55, 56, 58, 56, 58, 57, 59, 55, 57, 50, 56, + 58, 60] + nzval = [-0.64, 1.0, -1.0, 0.8606811145510832, -13.792569659442691, 1.0, + 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, + -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, + -2.3705976394178108, -11.083604432603583, -0.2770901108150896, + 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, -1.0, 13.792569659442691, + 0.8606811145510832, -13.792569659442691, 1.0, 0.03475000000000006, + 1.0, -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, + -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, + -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, + -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, + -13.792569659442691, 1.0, 0.03475000000000006, 1.0, + -0.03510101010101016, -0.975, -1.0806825309567203, 1.0, -0.95, + -0.025, 2.370597639417811, -2.3705976394178108, 10.698449178570607, + -11.083604432603583, -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, + -0.64, 1.0, -1.0, 13.792569659442691, 0.8606811145510832, + -13.792569659442691, 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, + -0.975, -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, + -2.3705976394178108, 10.698449178570607, -11.083604432603583, + -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, + -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, + 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, + -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, + -2.3705976394178108, 10.698449178570607, -11.083604432603583, + -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, + -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, + 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, + -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, + -2.3705976394178108, 10.698449178570607, -11.083604432603583, + -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, + -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, + 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, + -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, + -2.3705976394178108, 10.698449178570607, -11.083604432603583, + -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, + -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, + 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, + -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, + -2.3705976394178108, 10.698449178570607, -11.083604432603583, + -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, + -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, + 1.0, 0.03475000000000006, 1.0, -0.03510101010101016, -0.975, + -1.0806825309567203, 1.0, -0.95, -0.025, 2.370597639417811, + -2.3705976394178108, 10.698449178570607, -11.083604432603583, + -0.2770901108150896, 1.0, -0.025, -0.95, -0.3564, -0.64, 1.0, + -1.0, 13.792569659442691, 0.8606811145510832, -13.792569659442691, + 1.0, 0.03475000000000006, 1.0, -1.0806825309567203, 1.0, + 2.370597639417811, -2.3705976394178108, 10.698449178570607, + -11.083604432603583, -0.2770901108150896, 1.0] A = SparseMatrixCSC(n, n, colptr, rowval, nzval) - return(A) + return (A) end - for alg in algs - A=makeA() - u0=fill(0.1,size(A,2)) - linprob = LinearProblem(A, A*u0) + A = makeA() + u0 = fill(0.1, size(A, 2)) + linprob = LinearProblem(A, A * u0) u = LinearSolve.solve(linprob, alg) - @test norm(u-u0) < 1.0e-14 + @test norm(u - u0) < 1.0e-14 end - - - # Testing and demonstrating Pardiso.set_iparm! for MKLPardisoSolver for solver in solvers iparm = [ @@ -172,7 +226,7 @@ for solver in solvers for i in iparm Pardiso.set_iparm!(solver, i...) end - + for i in Base.OneTo(length(iparm)) @test Pardiso.get_iparm(solver, i) == iparm[i][2] end @@ -195,22 +249,21 @@ end b0 = A0 * u0 B0 = MySparseMatrixCSC2(A0) A1 = spdiagm(1 => -ones(N - 1), 0 => fill(100.0, N), -1 => -ones(N - 1)) - b1=A1*u0 - B1= MySparseMatrixCSC2(A1) + b1 = A1 * u0 + B1 = MySparseMatrixCSC2(A1) - pr = LinearProblem(B0, b0) # test default algorithn - u=solve(pr,alg) + u = solve(pr, alg) @test norm(u - u0, Inf) < 1.0e-13 - + # test factorization with reinit! pr = LinearProblem(B0, b0) - cache=init(pr,alg) - u=solve!(cache) + cache = init(pr, alg) + u = solve!(cache) @test norm(u - u0, Inf) < 1.0e-13 - reinit!(cache; A=B1, b=b1) - u=solve!(cache) + reinit!(cache; A = B1, b = b1) + u = solve!(cache) @test norm(u - u0, Inf) < 1.0e-13 end end diff --git a/test/resolve.jl b/test/resolve.jl index a567a90b1..5d0beb343 100644 --- a/test/resolve.jl +++ b/test/resolve.jl @@ -1,7 +1,12 @@ using LinearSolve, LinearAlgebra, SparseArrays, InteractiveUtils, Test using LinearSolve: AbstractDenseFactorization, AbstractSparseFactorization -for alg in vcat(InteractiveUtils.subtypes(AbstractDenseFactorization),InteractiveUtils.subtypes(AbstractSparseFactorization)) +for alg in vcat(InteractiveUtils.subtypes(AbstractDenseFactorization), + InteractiveUtils.subtypes(AbstractSparseFactorization)) + if alg in [PardisoJL] + ## Pardiso has extra tests in test/pardiso/pardiso.jl + continue + end @show alg if !(alg in [ DiagonalFactorization, diff --git a/test/retcodes.jl b/test/retcodes.jl index 61b4ecaa5..c75442d34 100644 --- a/test/retcodes.jl +++ b/test/retcodes.jl @@ -20,7 +20,7 @@ alglist = ( AppleAccelerateLUFactorization, MKLLUFactorization, KrylovJL_CRAIGMR, - KrylovJL_LSMR, + KrylovJL_LSMR ) @testset "Success" begin