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

FEEval: do not cast const away during read_dof_values() #13240

Merged
merged 1 commit into from Jan 15, 2022

Conversation

peterrum
Copy link
Member

This was an interesting "bug". I have passed to FEEval::read_dof_values() a clearly not ghosted vector and did not get any assert. The reason is that we (maybe me) do cast away the constness of the vector and when calling LA::d:V::local_element() we do not get the assert which is only available in the const version of this function.

Comment on lines +4270 to +4273
const_cast<typename internal::BlockVectorSelector<
typename std::remove_const<VectorType>::type,
IsBlockVector<typename std::remove_const<VectorType>::type>::value>::
BaseVectorType &>(*src_data.first[d]),
Copy link
Member Author

Choose a reason for hiding this comment

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

We should also remove this const_cast but this is more work. Also in that code path there are no asserts of this type.

Copy link
Member

@bangerth bangerth left a comment

Choose a reason for hiding this comment

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

Just a couple suggestions, but these are not important.

@@ -3270,6 +3270,22 @@ FEEvaluationBase<dim, n_components_, Number, is_face, VectorizedArrayType>::

namespace internal
{
template <typename VectorType, bool>
struct ConstBlockVectorSelector
{};
Copy link
Member

Choose a reason for hiding this comment

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

You might as well remove the whole body of this class and just provide a forward declaration since there is no case you are not covering via a specialization.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review. I have removed the body (I just did it how it was below).

include/deal.II/matrix_free/fe_evaluation.h Show resolved Hide resolved
@peterrum
Copy link
Member Author

/rebuild

Copy link
Member

@kronbichler kronbichler left a comment

Choose a reason for hiding this comment

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

I think the code gets confusing if the same operation is done twice. I suggest we do an if/else setup and write a comment on why we choose the different path in debug mode.

Comment on lines 250 to 255
#ifdef DEBUG
for (unsigned int i = 0; i < dofs_per_cell; ++i)
for (unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
vector_access(vec, dof_index + v + i * VectorizedArrayType::size());
#endif

Copy link
Member

Choose a reason for hiding this comment

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

This is at least surprising for someone reading the code because you load the vector twice. I would prefer to do not do the load part below in debug mode (i.e., use an #if / #else branch) or at the very least a extensive comment. The former assumes we have other paths where we test VectorizedArray::load.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added the #if/#else structure and added some comments.

Comment on lines 349 to 352
#ifdef DEBUG
for (unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
vector_access(vec, indices[v] + constant_offset);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I'd prefer an #if/#else statement to avoid confusion about doing the same thing twice.

@kronbichler
Copy link
Member

I have passed to FEEval::read_dof_values() a clearly not ghosted vector and did not get any assert.

Just for my understanding, you had a vector that has the right ghost elements in the partitioner (i.e., the partitioners match) but has not called update_ghost_values? Because we have an assert in the other function,

AssertIndexRange(local_index,
partitioner->locally_owned_size() +
partitioner->n_ghost_indices());

@peterrum
Copy link
Member Author

Just for my understanding, you had a vector that has the right ghost elements in the partitioner (i.e., the partitioners match) but has not called update_ghost_values? Because we have an assert in the other function,

Yes. Everything correct, just that vector_is_ghosted == true is not checked in the non-const version.

@kronbichler kronbichler merged commit ad13824 into dealii:master Jan 15, 2022
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

3 participants