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

VariationalSolver and Assembler LRU caching #2998

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

connorjward
Copy link
Contributor

@connorjward connorjward commented Jun 21, 2023

This PR is a draft. It is intended to be a proof of concept to allow discussion. Significant cleanup is needed.

Adding an LRU cache for solvers means that we can make the code

for ...:
    solve(u*v*dx == v*f*dx, ...)

just* as fast as

problem = LinearVariationalProblem(u*v*dx == f*v*dx, ...)
solver = LinearVariationalSolver(problem)  # or NonLinearVariationalSolver
for ...:
    solver.solve()

* there is a small additional cost to hash the forms to determine a cache hit or miss.

It is significant to note that in the former case non-persistent forms have been used, that is, u*v*dx instead of form = u*v*dx; ...; solve(form...). The code is still fast.

Discussion

This is somewhat of a controversial suggestion. Solvers consume a lot of memory so we really don't want to leak them. I believe that easy configuration, sufficient documentation and sane defaults are enough to handle this.

One of the things that most appeals to me about this solution is that we can apply it generally across all of Firedrake to improve our strong scaling. Things like Assembler, Interpolator can reuse the same concepts. It could also help in the adjoint where stashing Assembler, Interpolator etc objects is difficult.

Related GitHub discussion: #2946

Required PRs

Remaining tasks

  • Add configuration so users can easily control the cache sizes.
  • Code cleanup
  • Documentation (manual?)

@connorjward connorjward changed the title DRAFT LRU solver and assembler caching VariationalSolver and Assembler LRU caching Jun 29, 2023
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 this pull request may close these issues.

1 participant