Skip to content
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

Preallocate references to values for qrm_get in qrm_spfct #115

Merged
merged 2 commits into from
Jan 22, 2025
Merged
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
4 changes: 2 additions & 2 deletions src/wrapper/qr_mumps_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,10 @@ for (finame, frname, elty) in ((:sqrm_spfct_get_i8_c, :sqrm_spfct_get_r4_c, :Flo
@eval begin
function qrm_get(spfct :: qrm_spfct{$elty}, str :: String)
if (str ∈ PICNTL) || (str ∈ STATS)
val = Ref{Clonglong}(0)
val = spfct.ref_int
err = $finame(spfct, str, val)
elseif str ∈ RCNTL
val = Ref{Float32}(0)
val = spfct.ref_float
err = $frname(spfct, str, val)
else
err = Int32(23)
Expand Down
4 changes: 3 additions & 1 deletion src/wrapper/qr_mumps_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ mutable struct qrm_spfct{T} <: Factorization{T}
cperm_in :: Vector{Cint}
ptr_rp :: Ref{Ptr{Cint}}
ptr_cp :: Ref{Ptr{Cint}}
ref_int :: Ref{Clonglong}
ref_float:: Ref{Float32}
fct :: c_spfct{T}

function qrm_spfct{T}() where T
spfct = new(Cint[], Ref{Ptr{Cint}}(), Ref{Ptr{Cint}}(), c_spfct{T}())
spfct = new(Cint[], Ref{Ptr{Cint}}(), Ref{Ptr{Cint}}(), Ref{Clonglong}(0), Ref{Float32}(0), c_spfct{T}())
finalizer(qrm_spfct_destroy!, spfct)
return spfct
end
Expand Down
24 changes: 24 additions & 0 deletions test/test_qrm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,27 @@ end
@test norm(b - A'*(A*x)) ≥ norm(b - A'*(A*x_refined))
end
end

@testset "allocations" begin
for T in (Float32, Float64, ComplexF32, ComplexF64)
tol = (real(T) == Float32) ? 1e-3 : 1e-12
transp = (T <: Real) ? 't' : 'c'

for I in (Int32 , Int64)
A = sprand(T, m, n, 0.3)
A = convert(SparseMatrixCSC{T,I}, A)

spmat = qrm_spmat_init(T)
qrm_spmat_init!(spmat, A)

spfct = qrm_spfct_init(spmat)

qrm_set(spfct, "qrm_rd_eps", tol)
qrm_analyse!(spmat, spfct)
qrm_factorize!(spmat, spfct)
@test (@allocated qrm_get(spfct, "qrm_rd_num")) == 0

end
end

end
Loading