]> https://gitweb.dealii.org/ - dealii.git/commitdiff
FEValues: Allow checking for cell similarities in multi-threaded mode
authorDaniel Arndt <arndtd@ornl.gov>
Fri, 25 Aug 2023 19:24:51 +0000 (15:24 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Fri, 25 Aug 2023 19:59:14 +0000 (15:59 -0400)
include/deal.II/fe/fe_values_base.h
include/deal.II/matrix_free/cuda_matrix_free.templates.h
source/fe/fe_values_base.cc
tests/performance/timing_matrix_free_kokkos.release.run_only [moved from tests/performance/timing_matrix_free_kokkos.threads=1.mpirun=max.exclusive.release.run_only with 100% similarity]

index 3947ac1ff16e144dc0607a8cf9fd4659114ed73d..1b275f1ee6d63f6398b2215181c5d2aa7f9702f4 100644 (file)
@@ -222,6 +222,12 @@ public:
    */
   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
   ///
@@ -1741,6 +1747,11 @@ private:
    */
   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>
index 68a47ae8daac8afc12b97a45ab6851fb347d8d17..c72b6f090b5976f55507ba6be380208208f1bbc0 100644 (file)
@@ -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);
     }
 
 
index c25863ca8598d295ceb65e1aa21fe5c231f6b3c7..cb932cdb1b0896259bf79f9d537d3b29a1d6a36f 100644 (file)
@@ -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 "
@@ -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
@@ -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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.