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

Memory leak when calling associate_rhs!() many times #136

Closed
johnomotani opened this issue Oct 10, 2024 · 2 comments · Fixed by #137
Closed

Memory leak when calling associate_rhs!() many times #136

johnomotani opened this issue Oct 10, 2024 · 2 comments · Fixed by #137

Comments

@johnomotani
Copy link
Contributor

I have a program where I factorize a matrix once, and apply it many times to different rhs vectors (they are generated sequentially, in a time-stepping loop). I noticed that the memory usage grows linearly.

I noticed that every time I call associate_rhs!(), another entry is added to the mumps._gc_haven(), but I think the real culprit is that these two lines make copies of the rhs

associate_rhs!(mumps::Mumps, rhs::AbstractVector) = associate_rhs!(mumps, repeat(rhs, 1, 1))

y = convert(Matrix{T}, rhs)[:]

Is there a reason for this? Am I using the wrong calls for this use case?

Is an easy fix to replace those lines with:

associate_rhs!(mumps::Mumps, rhs::AbstractVector) = associate_rhs!(mumps, reshape(rhs, length(rhs), 1))

and

y = convert(Matrix{T}, rhs)

I think that way at least if you pass a Vector or Matrix, there would be no copy - you'd end up with y pointing to the same memory as the original rhs that the user passed in.

@amontoison
Copy link
Member

amontoison commented Oct 10, 2024

Is it not possible to replace y = convert(Matrix{T}, rhs)[:] by y = vec(convert(Matrix{T}, rhs))?
We developed the interface a few years ago and didn’t optimize it.
We have not been careful with the allocations.

Can you open a PR?
I can review it before the end of the week.

@johnomotani
Copy link
Contributor Author

yes, I think I can make a PR - will look into it today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants