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

Dof distribution slow #632

Closed
termi-official opened this issue Mar 22, 2023 · 5 comments
Closed

Dof distribution slow #632

termi-official opened this issue Mar 22, 2023 · 5 comments

Comments

@termi-official
Copy link
Member

termi-official commented Mar 22, 2023

The current dof distribution algorithm works well, but it is also very slow. This can be a deal-breaker for problems with changing mesh topology of on problems where multiple dof handlers may be used. We should explore different strategies to distribute the dofs faster, (e.g. via fast paths or by using additional information that can be precomputed).

Minimal example is takes from Kim ( #629 )

using Ferrite
using BenchmarkTools

grid = generate_grid(Quadrilateral, (1000, 1000))
ip_v = Lagrange{2,RefCube,2}()
ip_s = Lagrange{2,RefCube,1}()

function setup_close(grid, T)
    dh = T(grid)
    add!(dh, :v, 2, Lagrange{2,RefCube,2}()) 
    add!(dh, :s, 1, Lagrange{2,RefCube,1}()) 
    return dh
end

@btime close!(dh) setup=(dh=setup_close($grid, $DofHandler)) evals=1; # 1.542 s (224 allocations: 565.04 MiB)
@kimauth
Copy link
Member

kimauth commented Mar 23, 2023

I'm sure there are things that could be optimised in the dof distribution, but is ~0.65 s really that slow for a problem with ~9e6 dofs? Wouldn't the assembly or the linear solve be much more likely candidates for a performance bottleneck at that system size?

@termi-official
Copy link
Member Author

Depends on the problem. I have some traveling wave problem where I was able to optimize assembly and solve quite a lot, but my current implementation is capped by the AMR cost (have a quite customized C++ implementation).

Reference timings here are (not optimized dof distribution here either):

dof distribution time: 0.678458s
Number of finite element unknowns: 11'804'161

Ferrite timings are here

dof distribution time: 1.542 s
Total dofs: 9'010'003

^Sorry, copy pasted a wrong function above, which lead to wrong timings. Here is the updated one.

@KristofferC
Copy link
Collaborator

I would also push back a little bit about calling this "very slow" but yeah, I am sure the performance can be improved.

As it is right now the cost is basically completely in dictionary lookups in the part where we check if a dof has already been assigned to a certain entity.

@fredrikekre
Copy link
Member

fredrikekre commented Mar 25, 2023

it is also very slow

image

It is a bit faster now: #643 (comment)

@termi-official
Copy link
Member Author

termi-official commented Mar 25, 2023

sonic-the-hedgehog-classic-sonic

Will take a look at eliminating the other two dicts.

To elaborate, there is still a chunk of time spend the hash computation for the face and edges which we should be able to eliminate by vectors (as for the vertices now).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants