Skip to content

Delete lock interface implementation from UmfpackLU #617

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 16 additions & 31 deletions src/solvers/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@
has_refinement(control::AbstractVector) = control[JL_UMFPACK_IRSTEP] > 0

# auto magick resize, should this only expand and not shrink?
getworkspace(F::UmfpackLU) = @lock F.lock begin
return resize!(F.workspace, F, has_refinement(F); expand_only=true)
function getworkspace(F::UmfpackLU)
@lock F.lock begin
return resize!(F.workspace, F, has_refinement(F); expand_only = true)
end
end

UmfpackWS(F::UmfpackLU{Tv, Ti}, refinement::Bool=has_refinement(F)) where {Tv, Ti} = UmfpackWS(
Vector{Ti}(undef, size(F, 2)),
Expand Down Expand Up @@ -297,29 +299,12 @@

Base.transpose(F::UmfpackLU) = TransposeFactorization(F)

function Base.lock(f::Function, F::UmfpackLU)
lock(F)
try
f()
finally
unlock(F)
end
end
Base.lock(F::UmfpackLU) = if !trylock(F.lock)
@info """waiting for UmfpackLU's lock, it's safe to ignore this message.
see the documentation for Umfpack""" maxlog = 1
lock(F.lock)
end

@inline Base.trylock(F::UmfpackLU) = trylock(F.lock)
@inline Base.unlock(F::UmfpackLU) = unlock(F.lock)

show_umf_ctrl(F::UmfpackLU, level::Real=2.0) =
@lock F show_umf_ctrl(F.control, level)
@lock F.lock show_umf_ctrl(F.control, level)

Check warning on line 303 in src/solvers/umfpack.jl

View check run for this annotation

Codecov / codecov/patch

src/solvers/umfpack.jl#L303

Added line #L303 was not covered by tests


show_umf_info(F::UmfpackLU, level::Real=2.0) =
@lock F show_umf_info(F.control, F.info, level)
@lock F.lock show_umf_info(F.control, F.info, level)

Check warning on line 307 in src/solvers/umfpack.jl

View check run for this annotation

Codecov / codecov/patch

src/solvers/umfpack.jl#L307

Added line #L307 was not covered by tests


"""
Expand Down Expand Up @@ -598,7 +583,7 @@
@eval begin
function umfpack_symbolic!(U::UmfpackLU{Float64,$itype}, q::Union{Nothing, StridedVector{$itype}})
_isnotnull(U.symbolic) && return U
@lock U begin
@lock U.lock begin
tmp = Ref{Ptr{Cvoid}}(C_NULL)
if q === nothing
@isok $sym_r(U.m, U.n, U.colptr, U.rowval, U.nzval, tmp, U.control, U.info)
Expand All @@ -613,7 +598,7 @@
end
function umfpack_symbolic!(U::UmfpackLU{ComplexF64,$itype}, q::Union{Nothing, StridedVector{$itype}})
_isnotnull(U.symbolic) && return U
@lock U begin
@lock U.lock begin
tmp = Ref{Ptr{Cvoid}}(C_NULL)
if q === nothing
@isok $sym_c(U.m, U.n, U.colptr, U.rowval, real(U.nzval), imag(U.nzval), tmp,
Expand All @@ -627,7 +612,7 @@
return U
end
function umfpack_numeric!(U::UmfpackLU{Float64,$itype}; reuse_numeric=true, q=nothing)
@lock U begin
@lock U.lock begin
(reuse_numeric && _isnotnull(U.numeric)) && return U
if _isnull(U.symbolic)
umfpack_symbolic!(U, q)
Expand All @@ -643,7 +628,7 @@
return U
end
function umfpack_numeric!(U::UmfpackLU{ComplexF64,$itype}; reuse_numeric=true, q=nothing)
@lock U begin
@lock U.lock begin
(reuse_numeric && _isnotnull(U.numeric)) && return U
_isnull(U.symbolic) && umfpack_symbolic!(U, q)
tmp = Ref{Ptr{Cvoid}}(C_NULL)
Expand Down Expand Up @@ -672,7 +657,7 @@
if workspace_W_size(lu) > length(workspace.W)
throw(ArgumentError("W should be larger than `workspace_W_size(Af)`"))
end
@lock lu begin
@lock lu.lock begin
umfpack_numeric!(lu)
(size(b, 1) == lu.m) && (size(b) == size(x)) || throw(DimensionMismatch())

Expand All @@ -697,7 +682,7 @@
if workspace_W_size(lu) > length(workspace.W)
throw(ArgumentError("W should be larger than `workspace_W_size(Af)`"))
end
@lock lu begin
@lock lu.lock begin
umfpack_numeric!(lu)
(size(b, 1) == lu.m) && (size(b) == size(x)) || throw(DimensionMismatch())
@isok $wsol_c(typ, lu.colptr, lu.rowval, lu.nzval, C_NULL, x, C_NULL, b,
Expand All @@ -707,14 +692,14 @@
end
function det(lu::UmfpackLU{Float64,$itype})
mx = Ref{Float64}(zero(Float64))
@lock lu @isok($det_r(mx, C_NULL, lu.numeric, lu.info))
@lock lu.lock @isok($det_r(mx, C_NULL, lu.numeric, lu.info))
mx[]
end

function det(lu::UmfpackLU{ComplexF64,$itype})
mx = Ref{Float64}(zero(Float64))
mz = Ref{Float64}(zero(Float64))
@lock lu @isok($det_z(mx, mz, C_NULL, lu.numeric, lu.info))
@lock lu.lock @isok($det_z(mx, mz, C_NULL, lu.numeric, lu.info))
complex(mx[], mz[])
end
function logabsdet(F::UmfpackLU{T, $itype}) where {T<:Union{Float64,ComplexF64}} # return log(abs(det)) and sign(det)
Expand Down Expand Up @@ -1030,7 +1015,7 @@

_report_symbolic = Symbol(umf_nm("report_symbolic", Tv, Ti))
@eval umfpack_report_symbolic(lu::UmfpackLU{$Tv,$Ti}, level::Real=4; q=nothing) =
@lock lu begin
@lock lu.lock begin
umfpack_symbolic!(lu, q)
old_prl = lu.control[JL_UMFPACK_PRL]
lu.control[JL_UMFPACK_PRL] = level
Expand All @@ -1040,7 +1025,7 @@
end
_report_numeric = Symbol(umf_nm("report_numeric", Tv, Ti))
@eval umfpack_report_numeric(lu::UmfpackLU{$Tv,$Ti}, level::Real=4; q=nothing) =
@lock lu begin
@lock lu.lock begin
umfpack_numeric!(lu; q)
old_prl = lu.control[JL_UMFPACK_PRL]
lu.control[JL_UMFPACK_PRL] = level
Expand Down
2 changes: 0 additions & 2 deletions test/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ end
umfpack_report(Af)
Af1 = lu!(copy(Af))
umfpack_report(Af1)
@test trylock(Af)
@test trylock(Af1)
end

@testset "test similar" begin
Expand Down
Loading