-
-
Notifications
You must be signed in to change notification settings - Fork 61
Added the posibility to modify the control paramteres of UMFPACK alg #482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b444a75
a1b606f
26b2dcd
0f57c41
95b87a0
c02af4c
a12297c
3afda6f
963f8a4
64d80d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -723,22 +723,39 @@ 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=SparseArrays.UMFPACK.get_umfpack_control(Float64,Int64) | ||
|
||
""" | ||
`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”. | ||
|
||
## 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should fill in the details here, since it has been unchanged for 20 years. Is there something simple that can be pasted, quoted, or linked to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do u think would be appropriate? |
||
|
||
!!! note | ||
|
||
By default, the SparseArrays.jl are implemented for efficiency by caching the | ||
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 | ||
ChrisRackauckas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
be used in a context where that assumption does not hold, set `reuse_symbolic=false`. | ||
|
||
""" | ||
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::T=nothing | ||
end | ||
|
||
const PREALLOCATED_UMFPACK = SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC(0, 0, [1], | ||
|
@@ -771,6 +788,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 | ||
|
@@ -782,15 +800,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=control) | ||
else | ||
fact = lu!(cacheval, | ||
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), | ||
nonzeros(A)), check = false) | ||
nonzeros(A)), check = false, control=control) | ||
end | ||
else | ||
fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), | ||
check = false) | ||
check = false, control=control) | ||
end | ||
cache.cacheval = fact | ||
cache.isfresh = false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using SparseArrays, LinearSolve | ||
|
||
A = sparse(rand(3,3)); | ||
b=rand(3); | ||
prob = LinearProblem(A, b); | ||
|
||
#check without control 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 |
Uh oh!
There was an error while loading. Please reload this page.