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

MatrixFree diagonal: Avoid repeated computations and binary search #15147

Merged

Conversation

kronbichler
Copy link
Member

This is a follow-up to #15135, fixing some additional performance problems:

  • In the reinit() function, we used to merge two sets of constraints, one containing generic constraints and the other hanging-node constraints (using the internal representation of MatrixFree introduced in Optimize hanging-node constraints in MatrixFree #12560) by going through all dofs and looking up on both lists by binary searches. That is not efficient as it is O(n log(n)) in the number of local dofs, with possibly many branch mispredictions. It is much better to use one list as the "base" object and only check (by simple array lookup) whether the list also contains information there. Using this setup, we also avoid some std::sort() calls.
  • We use an std::map to avoid re-computing the resulting matrix of hanging node interpolation. However, we through away the helper object every time MatrixFree::cell_loop calls back into the cell_operation, which can be quite frequent because we use this to interleave loops. Instead, we should keep one such object through the entire loop by creating it outside the loop. There are two complications here, one regarding the possibly threaded execution of cell_loop (resolved by ThreadLocalStorage<Helper>) and one regarding the fact that hp adaptivity might involve different interpolations. In the latter, I still need to throw away previous results as soon as I detect a new polynomial degree.

@kronbichler kronbichler force-pushed the matrix_free_diagonal_improve_reinit branch from dcf9aad to 46f76bb Compare April 27, 2023 07:19
Comment on lines +461 to +465
// if we are in hp mode and the number of unknowns changed, we must
// clear the map of entries
if (this->phi != nullptr &&
this->phi->dofs_per_component != phi.dofs_per_component)
locally_relevant_constraints_hn_map.clear();
Copy link
Member

Choose a reason for hiding this comment

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

👍 Looks good. In practice, the fast hn algorithm is disabled if hp is detected.

@peterrum peterrum merged commit aef0f70 into dealii:master May 1, 2023
14 checks passed
@kronbichler kronbichler deleted the matrix_free_diagonal_improve_reinit branch August 10, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants