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

VectorTools::interpolate: Make common case of vector problem faster #16843

Merged
merged 2 commits into from Apr 4, 2024

Conversation

kronbichler
Copy link
Member

In several applications, I have observed that VectorTools::interpolate is quite slow, most recently when looking at our timing-step_68 benchmark case. The reason is that we ask a DoFHandler's FESystem for the generalized support points and mix/match the local results inside

FETools::convert_generalized_support_point_values_to_dof_values(
fe[fe_index], function_values, dof_values);
via

dealii/source/fe/fe_system.cc

Lines 2674 to 2693 in c76154b

// populate base_point_values for a recursive call to
// convert_generalized_support_point_values_to_dof_values
for (unsigned int j = 0; j < base_point_values.size(); ++j)
{
base_point_values[j].reinit(n_base_components, false);
const auto n =
generalized_support_points_index_table[base][j];
// we have to extract the correct slice out of the global
// vector of values:
const auto *const begin =
std::begin(point_values[n]) + current_vector_component;
const auto *const end = begin + n_base_components;
std::copy(begin, end, std::begin(base_point_values[j]));
}
base_element
.convert_generalized_support_point_values_to_dof_values(
base_point_values, base_dof_values);

This is quite expensive and involves a lot of memory allocations. While we can't change the underlying interfaces easily, we can at least detect when the FiniteElement consists of a single base element that has support points, in which case we can just pick up the values directly without the indirections.

While there, also avoid some dynamic_cast to detect the case of FESystem recursively: We can use n_base_elements() for that query.

@kronbichler kronbichler force-pushed the improve_vector_tools_interpolate branch from 34e7831 to c1d60e0 Compare April 3, 2024 13:03
Copy link
Member

@tamiko tamiko left a comment

Choose a reason for hiding this comment

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

This looks good!

Thanks a lot for the cleanup and small refactoring as well. This made the whole logic a lot easier to follow and understand.

@tamiko tamiko merged commit 53f00ca into dealii:master Apr 4, 2024
16 checks passed
@tamiko
Copy link
Member

tamiko commented Apr 4, 2024

@kronbichler Will we see this in the performance graphs?

@kronbichler kronbichler deleted the improve_vector_tools_interpolate branch April 4, 2024 07:03
@kronbichler
Copy link
Member Author

Will we see this in the performance graphs?

I expected it to have. But look at https://dealii.org/performance_tests/graphs//whistler-bullseye-gcc-10/a8379e2009bdfcb9e6fcb9fdb7dd074668217145-timing-step_68.average.png - timing-step_68/local_advect went from 1.37s to below 0.6s. More than I measured on my system. 😉

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