I am unsure if this is an issue or I just don’t understand how memory allocation works with ensemble problems.
I start Julia with --track-allocation=user
and run the following small script
using DifferentialEquations
using Profile
function lorenz!(du,u,p,t)
du[1] = 10.0*(u[2]-u[1])
du[2] = u[1]*(28.0-u[3]) - u[2]
du[3] = u[1]*u[2] - (8/3)*u[3]
end
u0 = [1.0;0.0;0.0]
tspan = (0.0, 100.0)
prob = ODEProblem(lorenz!, u0, tspan)
function prob_func(prob,i,repeat)
remake(prob, tspan=(rand(), 100.0))
end
ensemble_prob = EnsembleProblem(prob,prob_func=prob_func)
sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories=100)
Profile.clear_malloc_data()
sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories=100)
The function Lorenz!(du, u, p, t)
should not allocate any memory.
However, looking at the output of the .mem file, I get the following
- using DifferentialEquations
- using Profile
-
- function lorenz!(du,u,p,t)
1284544 du[1] = 10.0*(u[2]-u[1])
1220016 du[2] = u[1]*(28.0-u[3]) - u[2]
1456704 du[3] = u[1]*u[2] - (8/3)*u[3]
- end
-
- u0 = [1.0;0.0;0.0]
- tspan = (0.0, 100.0)
- prob = ODEProblem(lorenz!, u0, tspan)
-
- function prob_func(prob,i,repeat)
- remake(prob, tspan=(rand(), 100.0))
- end
-
- ensemble_prob = EnsembleProblem(prob,prob_func=prob_func)
-
- sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories=100)
- Profile.clear_malloc_data()
- sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories=100)
There are memory allocations inside the lorenz! function. If I change the ensemblealg
to EnsembleSerial
then I don’t observe any memory allocation in the .mem file.