From b444a75e3aff128c2856a670dab88a33726f7546 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 15 Mar 2024 19:32:28 +0100 Subject: [PATCH 01/10] Added the posibility to modify the control paramteres of UMFPACK algorithm --- src/factorization.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/factorization.jl b/src/factorization.jl index 98c431d9e..fd4d81676 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -739,6 +739,7 @@ patterns with “more structure”. Base.@kwdef struct UMFPACKFactorization <: AbstractFactorization reuse_symbolic::Bool = true check_pattern::Bool = true # Check factorization re-use + control::Vector{Float64}=SparseArrays.UMFPACK.get_umfpack_control(Float64,Int64) # Control Parameters of UMFPACK end const PREALLOCATED_UMFPACK = SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC(0, 0, [1], @@ -782,15 +783,15 @@ function SciMLBase.solve!(cache::LinearCache, alg::UMFPACKFactorization; kwargs. fact = lu( SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), - check = false) + check = false, control=alg.control) else fact = lu!(cacheval, SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), - nonzeros(A)), check = false) + nonzeros(A)), check = false, control=alg.control) end else fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), - check = false) + check = false, control=alg.control) end cache.cacheval = fact cache.isfresh = false From a1b606ff7ef6dad0798ff504e695782747cf7451 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 15 Mar 2024 19:57:35 +0100 Subject: [PATCH 02/10] added a easy test to check that i didn't broke anything with the new control vector feature --- test/controlvectortest.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/controlvectortest.jl diff --git a/test/controlvectortest.jl b/test/controlvectortest.jl new file mode 100644 index 000000000..c805fbf9f --- /dev/null +++ b/test/controlvectortest.jl @@ -0,0 +1,12 @@ +using SparseArrays, LinearSolve + +A = sparse(rand(3,3)); +b=rand(3); +prob = LinearProblem(A, b); + +#check without contro Vector +u=solve(prob,UMFPACKFactorization()).u + +#check plugging in a control vector +controlv=SparseArrays.UMFPACK.get_umfpack_control(Float64,Int64) +u=solve(prob,UMFPACKFactorization(control=controlv)).u \ No newline at end of file From 26b2dcd844c93eddd7fa2e1a31f2b0f968cb336d Mon Sep 17 00:00:00 2001 From: Paolo Date: Sat, 16 Mar 2024 10:13:49 +0100 Subject: [PATCH 03/10] corrected typos into the comment --- test/controlvectortest.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/controlvectortest.jl b/test/controlvectortest.jl index c805fbf9f..7dccdceff 100644 --- a/test/controlvectortest.jl +++ b/test/controlvectortest.jl @@ -4,7 +4,7 @@ A = sparse(rand(3,3)); b=rand(3); prob = LinearProblem(A, b); -#check without contro Vector +#check without control Vector u=solve(prob,UMFPACKFactorization()).u #check plugging in a control vector From 0f57c41b72867279adab3ef45620e1fe0638f259 Mon Sep 17 00:00:00 2001 From: Paolo Date: Sat, 16 Mar 2024 10:23:24 +0100 Subject: [PATCH 04/10] Created a default array and set the default value of UMFPACK contro equal to nothing; in the solver if no control has been given use the default values --- src/factorization.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/factorization.jl b/src/factorization.jl index fd4d81676..dff848bb3 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -736,10 +736,12 @@ patterns with “more structure”. `A` has the same sparsity pattern as the previous `A`. If this algorithm is to be used in a context where that assumption does not hold, set `reuse_symbolic=false`. """ +const default_control::Array{FLoat64}=[1.0, 0.2, 0.2, 0.1, 32.0, 0.0, 0.7, 0.0, 1.0, 0.3, 1.0, 1.0, 0.9, 0.0, 10.0, 0.001, 1.0, 0.5, 0.0, 1.0] + Base.@kwdef struct UMFPACKFactorization <: AbstractFactorization reuse_symbolic::Bool = true check_pattern::Bool = true # Check factorization re-use - control::Vector{Float64}=SparseArrays.UMFPACK.get_umfpack_control(Float64,Int64) # Control Parameters of UMFPACK + control::Vector{Float64}=nothing end const PREALLOCATED_UMFPACK = SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC(0, 0, [1], @@ -772,6 +774,7 @@ end function SciMLBase.solve!(cache::LinearCache, alg::UMFPACKFactorization; kwargs...) A = cache.A A = convert(AbstractMatrix, A) + isnothing(alg.control) ? control=default_control : control=alg.control if cache.isfresh cacheval = @get_cacheval(cache, :UMFPACKFactorization) if alg.reuse_symbolic @@ -783,15 +786,15 @@ function SciMLBase.solve!(cache::LinearCache, alg::UMFPACKFactorization; kwargs. fact = lu( SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), - check = false, control=alg.control) + check = false, control=control) else fact = lu!(cacheval, SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), - nonzeros(A)), check = false, control=alg.control) + nonzeros(A)), check = false, control=control) end else fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), - check = false, control=alg.control) + check = false, control=control) end cache.cacheval = fact cache.isfresh = false From 95b87a0bb3f8def11f4ca26d7fda40fa7bfbe635 Mon Sep 17 00:00:00 2001 From: PaoloBiolghini <61747117+PaoloBiolghini@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:07:31 +0100 Subject: [PATCH 05/10] Update src/factorization.jl Co-authored-by: Christopher Rackauckas --- src/factorization.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/factorization.jl b/src/factorization.jl index dff848bb3..430b9865d 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -738,10 +738,10 @@ patterns with “more structure”. """ const default_control::Array{FLoat64}=[1.0, 0.2, 0.2, 0.1, 32.0, 0.0, 0.7, 0.0, 1.0, 0.3, 1.0, 1.0, 0.9, 0.0, 10.0, 0.001, 1.0, 0.5, 0.0, 1.0] -Base.@kwdef struct UMFPACKFactorization <: AbstractFactorization +Base.@kwdef struct UMFPACKFactorization{T <: Union{Nothing, Vector{Float64}} <: AbstractFactorization reuse_symbolic::Bool = true check_pattern::Bool = true # Check factorization re-use - control::Vector{Float64}=nothing + control::T=nothing end const PREALLOCATED_UMFPACK = SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC(0, 0, [1], From c02af4c4bcced8476b770e640a8b0b2ce293e9c5 Mon Sep 17 00:00:00 2001 From: PaoloBiolghini <61747117+PaoloBiolghini@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:18:53 +0100 Subject: [PATCH 06/10] Update src/factorization.jl Co-authored-by: Christopher Rackauckas --- src/factorization.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factorization.jl b/src/factorization.jl index 430b9865d..1b3e7a32a 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -736,7 +736,7 @@ patterns with “more structure”. `A` has the same sparsity pattern as the previous `A`. If this algorithm is to be used in a context where that assumption does not hold, set `reuse_symbolic=false`. """ -const default_control::Array{FLoat64}=[1.0, 0.2, 0.2, 0.1, 32.0, 0.0, 0.7, 0.0, 1.0, 0.3, 1.0, 1.0, 0.9, 0.0, 10.0, 0.001, 1.0, 0.5, 0.0, 1.0] +const default_control=[1.0, 0.2, 0.2, 0.1, 32.0, 0.0, 0.7, 0.0, 1.0, 0.3, 1.0, 1.0, 0.9, 0.0, 10.0, 0.001, 1.0, 0.5, 0.0, 1.0] Base.@kwdef struct UMFPACKFactorization{T <: Union{Nothing, Vector{Float64}} <: AbstractFactorization reuse_symbolic::Bool = true From a12297c84288301c8e1b0048e81d6c3f8b5cb36a Mon Sep 17 00:00:00 2001 From: Paolo Date: Sat, 16 Mar 2024 23:29:42 +0100 Subject: [PATCH 07/10] added the changes on the documentation, added the modification suggested --- src/factorization.jl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/factorization.jl b/src/factorization.jl index 1b3e7a32a..a46f19884 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -723,8 +723,14 @@ end ################################## Factorizations which require solve! overloads +# Default control array of 20 elements from Umfpack + +#!!!ATTENTION +#These array could change and whenever there will be a change in the SparseArrays package this array must be changed +const default_control=[1.0, 0.2, 0.2, 0.1, 32.0, 0.0, 0.7, 0.0, 1.0, 0.3, 1.0, 1.0, 0.9, 0.0, 10.0, 0.001, 1.0, 0.5, 0.0, 1.0] + """ -`UMFPACKFactorization(;reuse_symbolic=true, check_pattern=true)` +`UMFPACKFactorization(;reuse_symbolic=true, check_pattern=true, control=Vector{Float64}(20))` A fast sparse multithreaded LU-factorization which specializes on sparsity patterns with “more structure”. @@ -735,10 +741,14 @@ patterns with “more structure”. symbolic factorization. I.e., if `set_A` is used, it is expected that the new `A` has the same sparsity pattern as the previous `A`. If this algorithm is to be used in a context where that assumption does not hold, set `reuse_symbolic=false`. + + There is also the possibility to set your own control array for the factorization that will be + passed at the SparseArrays package. To do so u have to pass a Vector{Float64} with 20 elements. + If no vecetor is passed the default control array is used. + More details on the UMFPACK doc """ -const default_control=[1.0, 0.2, 0.2, 0.1, 32.0, 0.0, 0.7, 0.0, 1.0, 0.3, 1.0, 1.0, 0.9, 0.0, 10.0, 0.001, 1.0, 0.5, 0.0, 1.0] -Base.@kwdef struct UMFPACKFactorization{T <: Union{Nothing, Vector{Float64}} <: AbstractFactorization +Base.@kwdef struct UMFPACKFactorization{T <: Union{Nothing, Vector{Float64}}} <: AbstractFactorization reuse_symbolic::Bool = true check_pattern::Bool = true # Check factorization re-use control::T=nothing From 3afda6fc7dc48e2819aa207bca724c115ab52aed Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 17 Mar 2024 08:05:42 -0400 Subject: [PATCH 08/10] Update src/factorization.jl --- src/factorization.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/factorization.jl b/src/factorization.jl index a46f19884..f5c1d6884 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -735,6 +735,14 @@ const default_control=[1.0, 0.2, 0.2, 0.1, 32.0, 0.0, 0.7, 0.0, 1.0, 0.3, 1.0, 1 A fast sparse multithreaded LU-factorization which specializes on sparsity patterns with “more structure”. +## Fields + +* `reuse_symbolic`: Whether the symbolic factorization is reused between calls. This requires that the sparsity pattern is + preserved. Defaults to true. +* `check_pattern`: Whether the sparsity pattern is checked for changes to allow for symbolic factorization caching. + The default is true. +* `control`: A control vector for more options to pass to UMFPACK. See the UMFPACK documentation for more details. + !!! note By default, the SparseArrays.jl are implemented for efficiency by caching the From 963f8a4627bd0ae3b7f4616080b038f244bf630b Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 17 Mar 2024 08:06:56 -0400 Subject: [PATCH 09/10] Update src/factorization.jl --- src/factorization.jl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/factorization.jl b/src/factorization.jl index f5c1d6884..f53a4662f 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -750,10 +750,6 @@ patterns with “more structure”. `A` has the same sparsity pattern as the previous `A`. If this algorithm is to be used in a context where that assumption does not hold, set `reuse_symbolic=false`. - There is also the possibility to set your own control array for the factorization that will be - passed at the SparseArrays package. To do so u have to pass a Vector{Float64} with 20 elements. - If no vecetor is passed the default control array is used. - More details on the UMFPACK doc """ Base.@kwdef struct UMFPACKFactorization{T <: Union{Nothing, Vector{Float64}}} <: AbstractFactorization From 64d80d139356444a80ef5618d80daab0a33e59b2 Mon Sep 17 00:00:00 2001 From: PaoloBiolghini <61747117+PaoloBiolghini@users.noreply.github.com> Date: Sun, 17 Mar 2024 14:49:24 +0100 Subject: [PATCH 10/10] Update src/factorization.jl Co-authored-by: Christopher Rackauckas --- src/factorization.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factorization.jl b/src/factorization.jl index f53a4662f..3911e5d8e 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -727,7 +727,7 @@ end #!!!ATTENTION #These array could change and whenever there will be a change in the SparseArrays package this array must be changed -const default_control=[1.0, 0.2, 0.2, 0.1, 32.0, 0.0, 0.7, 0.0, 1.0, 0.3, 1.0, 1.0, 0.9, 0.0, 10.0, 0.001, 1.0, 0.5, 0.0, 1.0] +const default_control=SparseArrays.UMFPACK.get_umfpack_control(Float64,Int64) """ `UMFPACKFactorization(;reuse_symbolic=true, check_pattern=true, control=Vector{Float64}(20))`