Skip to content
Closed
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
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MKL_jll = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
Expand All @@ -25,6 +27,7 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"

[weakdeps]
Expand All @@ -45,7 +48,6 @@ KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LAPACK_jll = "51474c39-65e3-53ba-86ba-03b1b862ec14"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2"
RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Sparspak = "e56a9233-b9d6-4f03-8d0f-1825330902ac"
Expand Down Expand Up @@ -99,6 +101,7 @@ GPUArraysCore = "0.2"
HYPRE = "1.7"
InteractiveUtils = "1.10"
IterativeSolvers = "0.9.4"
JuliaFormatter = "2.1.6"
KernelAbstractions = "0.9.30"
Krylov = "0.10"
KrylovKit = "0.10"
Expand Down
11 changes: 8 additions & 3 deletions ext/LinearSolvePardisoExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ function LinearSolve.init_cacheval(alg::PardisoJL,
b)
end

# Add finalizer to release Pardiso internal memory when solver is garbage collected
finalizer(solver) do s
Pardiso.set_phase!(s, Pardiso.RELEASE_ALL)
Pardiso.pardiso(s, eltype(b)[],
SparseMatrixCSC(0, 0, Int32[1], Int32[], eltype(A)[]),
eltype(b)[])
end

return solver
end

Expand All @@ -145,7 +153,4 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::PardisoJL; kwargs
return SciMLBase.build_linear_solution(alg, cache.u, nothing, cache)
end

# Add finalizer to release memory
# Pardiso.set_phase!(cache.cacheval, Pardiso.RELEASE_ALL)

end
25 changes: 25 additions & 0 deletions test_pardiso_memory.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using LinearSolve, SparseArrays, Random, LinearAlgebra, Test
using Pardiso

println("Testing Pardiso memory leak fix...")

n = 100
A = sprand(n, n, 0.1) + sparse(I, n, n) * 5.0
b = rand(n)

println("Creating and solving multiple problems to check for memory leaks...")
for i in 1:5
prob = LinearProblem(A, b)
sol = LinearSolve.solve(prob, PardisoJL())
println("Iteration $i: residual norm = ", norm(A * sol.u - b))
@test norm(A * sol.u - b) < 1e-10
end

println("\nTesting that solver cleanup happens properly...")
prob = LinearProblem(A, b)
cache = LinearSolve.init(prob, PardisoJL())
sol = LinearSolve.solve!(cache)
@test norm(A * sol.u - b) < 1e-10

println("\nMemory leak fix test completed successfully!")
println("The finalizer should release Pardiso memory when cache is garbage collected.")
Loading