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

Test allocations in simple simulations #227

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion test/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -782,4 +782,34 @@ end
sim_Tracer = evalsim(Tracer)
@test sim_Tracer(d_rect, generate, DiagonalHodge()) isa Any

end
end

@testset "Allocations" begin
# Test the heat equation Decapode has expected memory allocation.
Heat = @decapode begin
C::Form0
D::Constant
∂ₜ(C) == D*Δ(C)
end
sim = eval(gensim(Heat))
s = loadmesh(Icosphere(1))
sd = EmbeddedDeltaDualComplex2D{Bool,Float64,Point3D}(s)
subdivide_duals!(sd, Circumcenter())
f = sim(sd,nothing)
u₀ = ComponentArray(
C = map(x -> x[3], point(sd)))
p = (D=1e-1,)
du = copy(u₀)
# The first call to the function makes many allocations.
_ = @allocations f(du, u₀, p, (0,1.0)) # 55259
_ = @allocated f(du, u₀, p, (0,1.0)) # 3962696
# Test that subsequent calls make a reasonable amount.
bytes = @allocated f(du, u₀, p, (0,1.0))
nallocs = @allocations f(du, u₀, p, (0,1.0))
@test nallocs == 4
@test bytes ==
sizeof(u₀.C) +
sizeof(p.D) +
sizeof(Decapodes.FixedSizeDiffCache(Vector{Float64}(undef , nparts(sd, :V))))
end

Loading