]> https://gitweb.dealii.org/ - dealii.git/commitdiff
MatrixFree: optional assert to prevent ghosted vectors in loop 12538/head
authorPeter Munch <peterrmuench@gmail.com>
Fri, 2 Jul 2021 09:14:23 +0000 (11:14 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Mon, 5 Jul 2021 13:28:31 +0000 (15:28 +0200)
include/deal.II/matrix_free/matrix_free.h
include/deal.II/matrix_free/matrix_free.templates.h
include/deal.II/matrix_free/task_info.h

index c616e2f33a59525698f20ea90b2a5e201cd0f99e..d3221b30a8f5a3e22320c8da1c15f3ded754d303 100644 (file)
@@ -225,7 +225,8 @@ public:
       const bool         initialize_mapping  = true,
       const bool         overlap_communication_computation    = true,
       const bool         hold_all_faces_to_owned_cells        = false,
-      const bool         cell_vectorization_categories_strict = false)
+      const bool         cell_vectorization_categories_strict = false,
+      const bool         allow_ghosted_vectors_in_loops       = true)
       : tasks_parallel_scheme(tasks_parallel_scheme)
       , tasks_block_size(tasks_block_size)
       , mapping_update_flags(mapping_update_flags)
@@ -240,6 +241,7 @@ public:
       , hold_all_faces_to_owned_cells(hold_all_faces_to_owned_cells)
       , cell_vectorization_categories_strict(
           cell_vectorization_categories_strict)
+      , allow_ghosted_vectors_in_loops(allow_ghosted_vectors_in_loops)
       , communicator_sm(MPI_COMM_SELF)
     {}
 
@@ -265,6 +267,7 @@ public:
       , cell_vectorization_category(other.cell_vectorization_category)
       , cell_vectorization_categories_strict(
           other.cell_vectorization_categories_strict)
+      , allow_ghosted_vectors_in_loops(other.allow_ghosted_vectors_in_loops)
       , communicator_sm(other.communicator_sm)
     {}
 
@@ -292,7 +295,8 @@ public:
       cell_vectorization_category   = other.cell_vectorization_category;
       cell_vectorization_categories_strict =
         other.cell_vectorization_categories_strict;
-      communicator_sm = other.communicator_sm;
+      allow_ghosted_vectors_in_loops = other.allow_ghosted_vectors_in_loops;
+      communicator_sm                = other.communicator_sm;
 
       return *this;
     }
@@ -519,6 +523,18 @@ public:
      */
     bool cell_vectorization_categories_strict;
 
+    /**
+     * Assert that vectors passed to the MatrixFree loops are not ghosted.
+     * This variable is primarily intended to reveal bugs or performance
+     * problems caused by vectors that are involuntarily in ghosted mode,
+     * by adding a check that this is not the case. In terms of correctness,
+     * the MatrixFree::loop() and MatrixFree::cell_loop() methods support
+     * both cases and perform similar operations. In particular, ghost values
+     * are always updated on the source vector within the loop, and the
+     * difference is only in whether the initial non-ghosted state is restored.
+     */
+    bool allow_ghosted_vectors_in_loops;
+
     /**
      * Shared-memory MPI communicator. Default: MPI_COMM_SELF.
      */
@@ -3355,6 +3371,11 @@ namespace internal
     {
       (void)component_in_block_vector;
       bool ghosts_set = vec.has_ghost_elements();
+
+      Assert(matrix_free.get_task_info().allow_ghosted_vectors_in_loops ||
+               ghosts_set == false,
+             ExcNotImplemented());
+
       if (ghosts_set)
         ghosts_were_set = true;
 
@@ -3379,6 +3400,11 @@ namespace internal
     {
       (void)component_in_block_vector;
       bool ghosts_set = vec.has_ghost_elements();
+
+      Assert(matrix_free.get_task_info().allow_ghosted_vectors_in_loops ||
+               ghosts_set == false,
+             ExcNotImplemented());
+
       if (ghosts_set)
         ghosts_were_set = true;
 
@@ -3407,6 +3433,11 @@ namespace internal
         "Type mismatch between VectorType and VectorDataExchange");
       (void)component_in_block_vector;
       bool ghosts_set = vec.has_ghost_elements();
+
+      Assert(matrix_free.get_task_info().allow_ghosted_vectors_in_loops ||
+               ghosts_set == false,
+             ExcNotImplemented());
+
       if (ghosts_set)
         ghosts_were_set = true;
 
index 061ea1c461bfbdb8e2f9c587fc1a6bb71100dbec..0325470e71c9a572e4032a117cd1f1ac04582491 100644 (file)
@@ -401,6 +401,9 @@ MatrixFree<dim, Number, VectorizedArrayType>::internal_reinit(
       AssertDimension(dof_handler.size(), constraint.size());
       AssertDimension(dof_handler.size(), locally_owned_dofs.size());
 
+      task_info.allow_ghosted_vectors_in_loops =
+        additional_data.allow_ghosted_vectors_in_loops;
+
       // set variables that are independent of FE
       if (Utilities::MPI::job_supports_mpi() == true)
         {
index 4e85d7a7c2ed302a7a6819d58c7ff84766027066..56f0ba86a56725dd87e6a8f3af05d2419a413606 100644 (file)
@@ -614,6 +614,11 @@ namespace internal
        */
       MPI_Comm communicator_sm;
 
+      /**
+       * Assert that vectors passed to the MatrixFree loops are not ghosted.
+       */
+      bool allow_ghosted_vectors_in_loops;
+
       /**
        * Rank of MPI process
        */

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.