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

Cache structs to save memory use on repeated calls to _taylorinteg! #203

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

PerezHz
Copy link
Owner

@PerezHz PerezHz commented Dec 9, 2024

This PR introduces some cache structs which allow reusing memory on repeated calls to _taylorinteg!.

@coveralls
Copy link

coveralls commented Dec 9, 2024

Coverage Status

coverage: 95.078% (-0.6%) from 95.697%
when pulling 3b40df6 on jp/cache
into de3e06a on main.

@PerezHz PerezHz changed the title Cache structs to avoid allocations on repeated calls to _taylorinteg! Cache structs to save memory use on repeated calls to _taylorinteg! Dec 10, 2024
@PerezHz PerezHz marked this pull request as ready for review December 10, 2024 15:44
@PerezHz
Copy link
Owner Author

PerezHz commented Dec 10, 2024

This is ready for review @lbenet @LuEdRaMo

@lbenet
Copy link
Collaborator

lbenet commented Dec 10, 2024

Thanks @PerezHz for the nice addition. Do you have some comparisons/benchmarks? I'll have a look into it in the next few days!

@PerezHz PerezHz marked this pull request as draft December 20, 2024 04:36
@PerezHz
Copy link
Owner Author

PerezHz commented Dec 20, 2024

@lbenet I'm trying out some changes in this PR which will help re-use more memory while making this cache concept more user-friendly. I'll run benchmarks once this is ready.

@LuEdRaMo
Copy link
Contributor

@PerezHz: If I create a cache object once and then reuse it, do I have to update de cache.t, cache.x and cache.dx variables before every integration? If so, I think it would be nice to have a function for this.

@PerezHz
Copy link
Owner Author

PerezHz commented Feb 8, 2025

@PerezHz: If I create a cache object once and then reuse it, do I have to update de cache.t, cache.x and cache.dx variables before every integration? If so, I think it would be nice to have a function for this.

Thank you for the suggestion! Right now, the workflow with these caches looks as follows:

# allocation
cache = TaylorIntegration.init_cache(Val(true), t0, q0, maxsteps, order)
# handle parsing
parse_eqs, rv = TaylorIntegration._determine_parsing!(true, f!, cache.t, cache.x, cache.dx, params);
# first integration
sol = taylorinteg!(Val(true), f!, q0, t0, tmax, abstol, rv, cache, params; parse_eqs, maxsteps)
# update
t0 = # new time
q0 = # new initial condition
# second integration
sol2 = taylorinteg!(Val(true), f!, q0, t0, tmax, abstol, rv, cache, params; parse_eqs, maxsteps)

That is, the cache is initialized only once, and the update to the new initial condition is handled internally by taylorinteg!.

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.

4 participants