-
Notifications
You must be signed in to change notification settings - Fork 112
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
Fix allocs #1695
Fix allocs #1695
Conversation
Review checklistThis checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging. Purpose and scope
Code quality
Documentation
Testing
Performance
Verification
Created with ❤️ by the Trixi.jl community. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1695 +/- ##
==========================================
- Coverage 94.25% 87.02% -7.23%
==========================================
Files 431 431
Lines 34690 34639 -51
==========================================
- Hits 32694 30143 -2551
- Misses 1996 4496 +2500
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Thanks for tackling this! Before merging it, I would like to understand what's going on here.
|
Type is NamedTuple{(:Slant, :Bezier, :Right, :Bottom, :Top), NTuple{5, BoundaryConditionDirichlet{typeof(initial_condition_convergence_test)}}} For julia 1.8.5 the results are the same: The proposed version does not allocate, while the existing one does. In terms of using foreach(boundary_conditions) do bc
foo()
end loops only over the But we also need the |
I think you are lucky since this uses a homogeneous tuple under the hood. Could you please check a heterogeneous tuple, too (different types of BCs)? I expect your |
What about foreach(boundary_conditions, keys(boundary_conditions)) do bc, name ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking this! I believe the original idea for "lispy tuple programming" came from Tim Holy (see for example https://stackoverflow.com/questions/55840333/type-stability-for-lists-of-closures/55849398#55849398) as a workaround for type stability when iterating over lists of functions. If iteration over NamedTuples
is now type stable that would be great.
Is the original MWE in the StackExchange post still type unstable on Julia 1.8.5 (or 1.9.3)?
So for boundary_conditions = (; :Slant => boundary_condition_convergence_test,
:Bezier => boundary_condition_convergence_test,
:Right => boundary_condition_convergence_test,
#:Bottom => boundary_condition_convergence_test,
:Bottom => boundary_condition_do_nothing,
:Top => boundary_condition_convergence_test ) with NamedTuple{(:Slant, :Bezier, :Right, :Bottom, :Top), Tuple{BoundaryConditionDirichlet{typeof(initial_condition_convergence_test)},
BoundaryConditionDirichlet{typeof(initial_condition_convergence_test)},
BoundaryConditionDirichlet{typeof(initial_condition_convergence_test)},
Trixi.BoundaryConditionDoNothing,
BoundaryConditionDirichlet{typeof(initial_condition_convergence_test)}}} this is still not allocating (had to reduce runtime to avoid divergence of the simulation):
|
That works 👍 |
Not sure: Body::Vector{Float64}
1 ─ %1 = Main.eltype(u)::Core.Const(Float64)
│ %2 = Main.length(u)::Int64
│ (ret = Main.zeros(%1, %2))
│ %4 = Main.functions::Any
│ (@_3 = Base.iterate(%4))
│ %6 = (@_3 === nothing)::Bool
│ %7 = Base.not_int(%6)::Bool
└── goto #4 if not %7
2 ┄ %9 = @_3::Any
│ (func = Core.getfield(%9, 1))
│ %11 = Core.getfield(%9, 2)::Any
│ %12 = ret::Vector{Float64}
│ %13 = Main.:+::Core.Const(+)
│ %14 = ret::Vector{Float64}
│ %15 = (func)(u)::Any
│ %16 = Base.broadcasted(%13, %14, %15)::Any
│ Base.materialize!(%12, %16)
│ (@_3 = Base.iterate(%4, %11))
│ %19 = (@_3 === nothing)::Bool
│ %20 = Base.not_int(%19)::Bool
└── goto #4 if not %20
3 ─ goto #2
4 ┄ return ret |
That still looks type unstable (note the presence of Any type variables, that means Julia cannot infer the type properly). However, if you are not observing allocations, maybe things have been partially fixed for our example? |
Looking more closely, the StackExchange MWE isn't really the same as our boundary condition setting. They are looping over functions and directly applying them. Trixi is passing functions as arguments to another function, so there might be a function barrier helping us? If you are not seeing allocations, and if this PR passes the allocation tests, I am ok with it. |
Is this expected to be more robust than |
If it works, let's use your approach. I woudl just like to understand why it didn't work before 😅 |
* Revise bounds check for MCL * Rename `idp_bounds_delta` for MCL to `mcl_bounds_delta` * Remove comment * Fix allocs (trixi-framework#1695) * Fix allocs * remove unnecessary code * rerun fmt * format * Allocation tests dgmulti 2d (trixi-framework#1698) * HLLE CEE 2D3D NonCartesian Meshes (trixi-framework#1692) * HLLE CEE 2D3D NonCartesian Meshes * format * hlle via hll * format test * format test * format * do not export hlle * Correct test vals * test values CI * Update src/equations/compressible_euler_2d.jl Co-authored-by: Hendrik Ranocha <[email protected]> * Update src/equations/compressible_euler_1d.jl Co-authored-by: Hendrik Ranocha <[email protected]> * Update src/equations/compressible_euler_2d.jl Co-authored-by: Hendrik Ranocha <[email protected]> * Update src/equations/compressible_euler_3d.jl Co-authored-by: Hendrik Ranocha <[email protected]> * Update src/equations/compressible_euler_3d.jl Co-authored-by: Hendrik Ranocha <[email protected]> * apply suggestions * additional sentence * Fix typo * typos * correct test vals --------- Co-authored-by: Hendrik Ranocha <[email protected]> * Bump crate-ci/typos from 1.16.15 to 1.16.21 (trixi-framework#1700) Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.16.15 to 1.16.21. - [Release notes](https://github.com/crate-ci/typos/releases) - [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md) - [Commits](crate-ci/typos@v1.16.15...v1.16.21) --- updated-dependencies: - dependency-name: crate-ci/typos dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add NumFOCUS + ACTRIX to acknowledgments (trixi-framework#1697) * Add NumFOCUS + ACTRIX to acknowledgments * Try to avoid spaces * Another try to avoid gaps between images * Hopefully fix image alignment in docs * Try new logo formats * Use smaller DUBS logo and add DUBS funding statement * Add markdown-based table for logos in docs * Try another table approach * Hopefully get a layout that finally *works*... * Arrrrrrgggggghhhhh * format examples (trixi-framework#1531) * format examples * check formatting of examples in CI * update style guide * fix weird formatting * fix formatting of binary operators * format again * Update differentiable_programming.jl (trixi-framework#1704) * Format subcell elixirs * Add warning for missing bounds check for entropy limiter (MCL) --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Daniel Doehring <[email protected]> Co-authored-by: Hendrik Ranocha <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Michael Schlottke-Lakemper <[email protected]> Co-authored-by: ArseniyKholod <[email protected]>
This fixes #1678 .
The comment in the code suggests that loops where sometime avoided due to allocations and the recursive procedure was used - seems like things have changed.
Trixi.jl/src/solvers/dgmulti/dg.jl
Line 468 in dc0dc1d
Compare Summary CB:
to
https://github.com/trixi-framework/Trixi.jl/actions/runs/6574426931/job/17859451194#step:7:8803