OrdinaryDiffEq.jl icon indicating copy to clipboard operation
OrdinaryDiffEq.jl copied to clipboard

reinit! and solve! allocates even with saving turned off

Open Elycoo opened this issue 2 years ago • 0 comments

Hi, reinit! and solve! allocates some memory even with saving turned off. Here is a MWE:

module CheckAlloc
using DifferentialEquations, Profile, PProf, GraphViz
function f(dx,x,p,t) 
    for i in eachindex(x)
        dx[i] = -x[i]
    end
end

function timeit()
    prob = ODEProblem(f,ones(Float64,10),(0.0,1.5),save_on=false, save_start=false,save_everystep=false,calck=false,alias_u0=true)
    int = init(prob, Tsit5())
    x = 5.5*ones(10)
    reinit!(int,x)
    solve!(int)
    reinit!(int,x)
    solve!(int)
    Profile.Allocs.clear()
    @time Profile.Allocs.@profile sample_rate=1 reinit!(int,x)
    @time Profile.Allocs.@profile sample_rate=1 solve!(int)
    PProf.Allocs.pprof(out="slow")
    nothing
end
end # CheckAlloc
using .CheckAlloc

CheckAlloc.timeit();

@time output:

 0.005007 seconds (11 allocations: 1.531 KiB)
 0.000856 seconds (2 allocations: 960 bytes)

The file from the allocation profile: profile.pb.gz

Thanks! Elyco

Elycoo avatar Oct 04 '22 12:10 Elycoo