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 allocations of PresetTimeCallback after v3.2.0 #211

Closed
albertomercurio opened this issue Mar 25, 2024 · 5 comments
Closed

Memory allocations of PresetTimeCallback after v3.2.0 #211

albertomercurio opened this issue Mar 25, 2024 · 5 comments

Comments

@albertomercurio
Copy link

albertomercurio commented Mar 25, 2024

Describe the example

I get a lot of memory allocations, never obtained before v3.2.0

Minimal Reproducible Example 👇

# Define a simple ODE system
function simple_ode!(du, u, p, t)
    mul!(du, p.A, u, p.α[1], 0)
end

# Initial condition
u0 = rand(ComplexF64, 10)
A = rand(ComplexF64, 10, 10)

# Time span for the solution
tlist = range(0, 10, 1000)
tspan = (tlist[1], tlist[end])

p = (A=A,α=rand(2))

# Define the ODE problem
prob = ODEProblem(simple_ode!, u0, tspan, p)

# Callback function to modify the parameter
function change_param!(integrator)
    integrator.p.α[1] = 0.5 # Change the parameter value
end

callback = PresetTimeCallback(tlist, change_param!, save_positions=(false,false))

# Solve the ODE with the callback
sol = solve(prob, Tsit5(), callback=callback);

@time solve(prob, Tsit5(), callback=callback);
0.001125 seconds (26.55 k allocations: 2.361 MiB)

@time solve(prob, Tsit5());
0.000074 seconds (980 allocations: 101.891 KiB)
@ChrisRackauckas
Copy link
Member

@oscardssmith could I get help with this? I think it's from the views I added to fix the adjoint floating point issues, but the views should be... fine?

@oscardssmith
Copy link
Contributor

oscardssmith commented Mar 27, 2024

I think the problem here is the fun closure capture performance bug.

@oscardssmith
Copy link
Contributor

This is now fixed On DiffEqCallbacks version 3.1, this gives (9.06 k allocations: 1.926 MiB) and with #212, we're at (10.07 k allocations: 1.946 MiB).

@ChrisRackauckas
Copy link
Member

That's a typo right?

@oscardssmith
Copy link
Contributor

no 3.1 had 9k allocations, 3.2 had 26k allocations, and main has 10k.

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

No branches or pull requests

3 participants