Add parallel-safe LRU cache and global cache manager objects #703
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are occasions in PyOP2/Firedrake where we repeatedly perform expensive operations but are unable to cache them because:
A classic example of this is something like computing the
adjoint
of a form. Forms are often non-persistent (e.g.solve(u*v*dx == f*v*dx, ...)
) and they hold references to the coefficients so a global cache is not suitable. Computingadjoint
is a significant cost when computing the derivative of adjoint problems so caching results is desirable.This PR introduces parallel-safe LRU caches. I believe that this would address the problems described above.
I have also introduced the concept of a "cache manager" (#693) to facilitate cache cleaning and inspection.
Closes #696 #693
TODOs: