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

Compute deformation gradient in matrix form #38

Merged
merged 3 commits into from
Dec 29, 2022

Conversation

efaulhaber
Copy link
Member

Turns out, computing the deformation gradient in matrix form takes pretty much the same time as computing only one entry of the matrix. Thus, computing the whole gradient in matrix form is about 4x faster (in 2D) than computing every single entry.

Benchmarks are based on #36, but this PR can be merged independently.
Before:

julia> pixie_include("examples/solid/oscillating_beam_2d.jl", tspan=(0.0, 1.0));
[...]
────────────────────────────────────────────────────────────────────────────────────────────────────
Pixie simulation finished.  Final time: 1.0  Time steps: 2973 (accepted), 3168 (total)
────────────────────────────────────────────────────────────────────────────────────────────────────

 ────────────────────────────────────────────────────────────────────────────────────
              Pixie.jl                      Time                    Allocations      
                                   ───────────────────────   ────────────────────────
         Tot / % measured:              33.0s /  99.8%           1.68MiB /   0.2%    

 Section                   ncalls     time    %tot     avg     alloc    %tot      avg
 ────────────────────────────────────────────────────────────────────────────────────
 rhs!                       28.6k    32.9s  100.0%  1.15ms   3.67KiB  100.0%    0.13B
   update containers        28.6k    24.4s   74.1%   853μs      752B   20.0%    0.03B
     precompute pk1         28.6k    24.4s   74.0%   853μs     0.00B    0.0%    0.00B
     ~update containers~    28.6k   16.2ms    0.0%   569ns      752B   20.0%    0.03B
   container interaction    28.6k    8.52s   25.9%   298μs     0.00B    0.0%    0.00B
   ~rhs!~                   28.6k   8.09ms    0.0%   283ns   2.94KiB   80.0%    0.11B
   reset ∂u/∂t              28.6k   3.60ms    0.0%   126ns     0.00B    0.0%    0.00B
   update nhs               28.6k    636μs    0.0%  22.3ns     0.00B    0.0%    0.00B
 ────────────────────────────────────────────────────────────────────────────────────

julia> using BenchmarkTools

julia> @benchmark Pixie.deformation_gradient($1, $(semi.neighborhood_searches[1][1]), $particle_container)
BenchmarkTools.Trial: 10000 samples with 10 evaluations.
 Range (min … max):  1.458 μs …  4.026 μs  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     1.495 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.498 μs ± 41.374 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

               ▂▃▆▆█▃                                         
  ▂▂▂▂▂▂▂▂▂▂▃▃▄███████▆▅▄▃▂▂▂▂▂▂▂▂▂▂▂▂▁▁▂▁▁▁▂▁▁▁▁▁▁▂▂▁▁▂▁▁▁▂ ▃
  1.46 μs        Histogram: frequency by time        1.59 μs <

 Memory estimate: 0 bytes, allocs estimate: 0.

After:

julia> pixie_include("examples/solid/oscillating_beam_2d.jl", tspan=(0.0, 1.0));
[...]
────────────────────────────────────────────────────────────────────────────────────────────────────
Pixie simulation finished.  Final time: 1.0  Time steps: 2973 (accepted), 3168 (total)
────────────────────────────────────────────────────────────────────────────────────────────────────

 ────────────────────────────────────────────────────────────────────────────────────
              Pixie.jl                      Time                    Allocations      
                                   ───────────────────────   ────────────────────────
         Tot / % measured:              15.4s /  99.5%           1.69MiB /   0.2%    

 Section                   ncalls     time    %tot     avg     alloc    %tot      avg
 ────────────────────────────────────────────────────────────────────────────────────
 rhs!                       28.6k    15.3s  100.0%   537μs   3.67KiB  100.0%    0.13B
   container interaction    28.6k    8.44s   55.0%   295μs     0.00B    0.0%    0.00B
   update containers        28.6k    6.88s   44.9%   241μs      752B   20.0%    0.03B
     precompute pk1         28.6k    6.86s   44.8%   240μs     0.00B    0.0%    0.00B
     ~update containers~    28.6k   19.8ms    0.1%   692ns      752B   20.0%    0.03B
   ~rhs!~                   28.6k   8.07ms    0.1%   282ns   2.94KiB   80.0%    0.11B
   reset ∂u/∂t              28.6k   3.48ms    0.0%   122ns     0.00B    0.0%    0.00B
   update nhs               28.6k    634μs    0.0%  22.2ns     0.00B    0.0%    0.00B
 ────────────────────────────────────────────────────────────────────────────────────

julia> using BenchmarkTools

julia> @benchmark Pixie.deformation_gradient($1, $(semi.neighborhood_searches[1][1]), $particle_container)
BenchmarkTools.Trial: 10000 samples with 211 evaluations.
 Range (min … max):  352.659 ns … 506.550 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     362.993 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   363.593 ns ±   4.560 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

                ▃█▃▅▇▃▄▃▄▃▄▁                                     
  ▁▁▁▁▁▁▁▁▁▁▂▃▄▆████████████▆▆▄▃▃▂▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▃
  353 ns           Histogram: frequency by time          384 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

@efaulhaber efaulhaber requested a review from LasNikas December 28, 2022 23:35
@efaulhaber efaulhaber mentioned this pull request Dec 29, 2022
7 tasks
Copy link
Collaborator

@LasNikas LasNikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good! This small modification has such a big impact.
just one comment

src/containers/solid_container.jl Outdated Show resolved Hide resolved
@efaulhaber efaulhaber merged commit ca20dca into trixi-framework:main Dec 29, 2022
@efaulhaber efaulhaber deleted the performance2 branch December 29, 2022 15:39
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

Successfully merging this pull request may close these issues.

2 participants