]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move a class out of a surrounding class. 10313/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 22 May 2020 17:33:02 +0000 (11:33 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 22 May 2020 17:33:02 +0000 (11:33 -0600)
include/deal.II/lac/affine_constraints.templates.h
source/lac/affine_constraints.cc

index 2c0da3a2e302f1345947d56b4450a214e66d1268..adc7f3dec9eac8eb52456e9060b7af3db28fbcbf 100644 (file)
@@ -2788,6 +2788,7 @@ namespace internal
         }
     }
 
+
     /**
      * Scratch data that is used during calls to distribute_local_to_global and
      * add_entries_local_to_global. In order to avoid frequent memory
@@ -2795,79 +2796,96 @@ namespace internal
      * variable. Since we want to allow for different number types in matrices,
      * this is a template.
      *
-     * Since each thread gets its private version of scratch data out of the
+     * Since each thread gets its private version of scratch data out of a
      * ThreadLocalStorage, no conflicting access can occur. For this to be
      * valid, we need to make sure that no call within
      * distribute_local_to_global is made that by itself can spawn tasks.
      * Otherwise, we might end up in a situation where several threads fight for
      * the data.
      *
-     * Access to the scratch data is only through the accessor class which
-     * handles the access as well as marking the data as used.
+     * Access to the scratch data is only through an accessor class which
+     * handles the access as well as marks the data as used.
      */
     template <typename number>
-    class AffineConstraintsData
+    struct ScratchData
     {
-    public:
-      struct ScratchData
-      {
-        /**
-         * Constructor, does nothing.
-         */
-        ScratchData()
-          : in_use(false)
-        {}
-
-        /**
-         * Copy constructor, does nothing
-         */
-        ScratchData(const ScratchData &)
-          : in_use(false)
-        {}
+      /**
+       * Constructor, does nothing.
+       */
+      ScratchData()
+        : in_use(false)
+      {}
 
-        /**
-         * Stores whether the data is currently in use.
-         */
-        bool in_use;
+      /**
+       * Copy constructor, does nothing
+       */
+      ScratchData(const ScratchData &)
+        : in_use(false)
+      {}
 
-        /**
-         * Temporary array for column indices
-         */
-        std::vector<size_type> columns;
+      /**
+       * Stores whether the data is currently in use.
+       */
+      bool in_use;
 
-        /**
-         * Temporary array for column values
-         */
-        std::vector<number> values;
+      /**
+       * Temporary array for column indices
+       */
+      std::vector<size_type> columns;
 
-        /**
-         * Temporary array for block start indices
-         */
-        std::vector<size_type> block_starts;
+      /**
+       * Temporary array for column values
+       */
+      std::vector<number> values;
 
-        /**
-         * Temporary array for vector indices
-         */
-        std::vector<size_type> vector_indices;
+      /**
+       * Temporary array for block start indices
+       */
+      std::vector<size_type> block_starts;
 
-        /**
-         * Temporary array for vector values
-         */
-        std::vector<number> vector_values;
+      /**
+       * Temporary array for vector indices
+       */
+      std::vector<size_type> vector_indices;
 
-        /**
-         * Data array for reorder row/column indices.
-         */
-        GlobalRowsFromLocal<number> global_rows;
+      /**
+       * Temporary array for vector values
+       */
+      std::vector<number> vector_values;
 
-        /**
-         * Data array for reorder row/column indices.
-         */
-        GlobalRowsFromLocal<number> global_columns;
-      };
+      /**
+       * Data array for reorder row/column indices.
+       */
+      GlobalRowsFromLocal<number> global_rows;
 
+      /**
+       * Data array for reorder row/column indices.
+       */
+      GlobalRowsFromLocal<number> global_columns;
+    };
 
 
+    /**
+     * Scratch data that is used during calls to distribute_local_to_global and
+     * add_entries_local_to_global. In order to avoid frequent memory
+     * allocation, we keep the data alive from one call to the next in a static
+     * variable. Since we want to allow for different number types in matrices,
+     * this is a template.
+     *
+     * Since each thread gets its private version of scratch data out of the
+     * ThreadLocalStorage, no conflicting access can occur. For this to be
+     * valid, we need to make sure that no call within
+     * distribute_local_to_global is made that by itself can spawn tasks.
+     * Otherwise, we might end up in a situation where several threads fight for
+     * the data.
+     *
+     * Access to the scratch data is only through the accessor class which
+     * handles the access as well as marking the data as used.
+     */
+    template <typename number>
+    class AffineConstraintsData
+    {
+    public:
       /**
        * Accessor class to guard access to scratch_data
        */
@@ -2900,7 +2918,7 @@ namespace internal
         /**
          * Dereferencing operator.
          */
-        ScratchData &operator*()
+        ScratchData<number> &operator*()
         {
           return *my_scratch_data;
         }
@@ -2908,20 +2926,20 @@ namespace internal
         /**
          * Dereferencing operator.
          */
-        ScratchData *operator->()
+        ScratchData<number> *operator->()
         {
           return my_scratch_data;
         }
 
       private:
-        ScratchData *my_scratch_data;
+        ScratchData<number> *my_scratch_data;
       };
 
     private:
       /**
        * The actual data object that contains a scratch data for each thread.
        */
-      static Threads::ThreadLocalStorage<ScratchData> scratch_data;
+      static Threads::ThreadLocalStorage<ScratchData<number>> scratch_data;
     };
 
 
index 767ff5fc9f292fc74f2ba3ec9af565c1add6ab43..dd160ed0926612e160aa159b6bf5d3be6438d298 100644 (file)
@@ -141,11 +141,11 @@ namespace internal
 {
   namespace AffineConstraints
   {
-#define SCRATCH_INITIALIZER(number, Name)                                     \
-  AffineConstraintsData<number>::ScratchData scratch_data_initializer_##Name; \
-  template <>                                                                 \
-  Threads::ThreadLocalStorage<AffineConstraintsData<number>::ScratchData>     \
-    AffineConstraintsData<number>::scratch_data(                              \
+#define SCRATCH_INITIALIZER(number, Name)              \
+  ScratchData<number> scratch_data_initializer_##Name; \
+  template <>                                          \
+  Threads::ThreadLocalStorage<ScratchData<number>>     \
+    AffineConstraintsData<number>::scratch_data(       \
       scratch_data_initializer_##Name)
 
     SCRATCH_INITIALIZER(double, d);

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.