Skip to content

Commit

Permalink
FEValues: Allow checking for cell similarities in multi-threaded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Aug 25, 2023
1 parent 26c7c44 commit 208418a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
11 changes: 11 additions & 0 deletions include/deal.II/fe/fe_values_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ class FEValuesBase : public Subscriptor
*/
virtual ~FEValuesBase() override;

/**
* Explicitly allow to check for cell similarity. By default, this is only
* enabled when the number of threads is 1.
*/
void
allow_check_for_cell_similarity(bool allow);

/// @name Access to shape function values
///
Expand Down Expand Up @@ -1741,6 +1747,11 @@ class FEValuesBase : public Subscriptor
*/
dealii::internal::FEValuesViews::Cache<dim, spacedim> fe_values_views_cache;

/**
* Whether checking for cell similarity is allowed.
*/
bool check_for_cell_similarity_allowed;

// Make the view classes friends of this class, since they access internal
// data.
template <int, int>
Expand Down
1 change: 1 addition & 0 deletions include/deal.II/matrix_free/cuda_matrix_free.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace CUDAWrappers
{
local_dof_indices.resize(data->dofs_per_cell);
lexicographic_dof_indices.resize(dofs_per_cell);
fe_values.allow_check_for_cell_similarity(true);
}


Expand Down
21 changes: 14 additions & 7 deletions source/fe/fe_values_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ FEValuesBase<dim, spacedim>::FEValuesBase(
, fe(&fe, typeid(*this).name())
, cell_similarity(CellSimilarity::Similarity::none)
, fe_values_views_cache(*this)
, check_for_cell_similarity_allowed(MultithreadInfo::n_threads() == 1)
{
Assert(n_q_points > 0,
ExcMessage("There is nothing useful you can do with an FEValues "
Expand All @@ -246,6 +247,15 @@ FEValuesBase<dim, spacedim>::~FEValuesBase()



template <int dim, int spacedim>
void
FEValuesBase<dim, spacedim>::allow_check_for_cell_similarity(bool allow)
{
check_for_cell_similarity_allowed = allow;
}



namespace internal
{
// put shape function part of get_function_xxx methods into separate
Expand Down Expand Up @@ -1413,15 +1423,12 @@ FEValuesBase<dim, spacedim>::check_cell_similarity(
// initialized to the first cell the thread sees. As this number might
// different between different runs (after all, the tasks are scheduled
// dynamically onto threads), this slight deviation leads to difference in
// roundoff errors that propagate through the program. Therefore, we need to
// disable CellSimilarity in case there is more than one thread in the
// problem. This will likely not affect many MPI test cases as there
// roundoff errors that propagate through the program. Therefore, we
// disable CellSimilarity by default in case there is more than one thread in
// the problem. This will likely not affect many MPI test cases as there
// multithreading is disabled on default, but in many other situations
// because we rarely explicitly set the number of threads.
//
// TODO: Is it reasonable to introduce a flag "unsafe" in the constructor of
// FEValues to re-enable this feature?
if (MultithreadInfo::n_threads() > 1)
if (!check_for_cell_similarity_allowed)
{
cell_similarity = CellSimilarity::none;
return;
Expand Down

0 comments on commit 208418a

Please sign in to comment.