From: Wolfgang Bangerth Date: Fri, 22 May 2020 17:33:02 +0000 (-0600) Subject: Move a class out of a surrounding class. X-Git-Tag: v9.3.0-rc1~1582^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2794dd3e46d855de2aebcd9b3cf3390ddd43cbda;p=dealii.git Move a class out of a surrounding class. --- diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index 2c0da3a2e3..adc7f3dec9 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -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 - 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 columns; + /** + * Stores whether the data is currently in use. + */ + bool in_use; - /** - * Temporary array for column values - */ - std::vector values; + /** + * Temporary array for column indices + */ + std::vector columns; - /** - * Temporary array for block start indices - */ - std::vector block_starts; + /** + * Temporary array for column values + */ + std::vector values; - /** - * Temporary array for vector indices - */ - std::vector vector_indices; + /** + * Temporary array for block start indices + */ + std::vector block_starts; - /** - * Temporary array for vector values - */ - std::vector vector_values; + /** + * Temporary array for vector indices + */ + std::vector vector_indices; - /** - * Data array for reorder row/column indices. - */ - GlobalRowsFromLocal global_rows; + /** + * Temporary array for vector values + */ + std::vector vector_values; - /** - * Data array for reorder row/column indices. - */ - GlobalRowsFromLocal global_columns; - }; + /** + * Data array for reorder row/column indices. + */ + GlobalRowsFromLocal global_rows; + /** + * Data array for reorder row/column indices. + */ + GlobalRowsFromLocal 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 + class AffineConstraintsData + { + public: /** * Accessor class to guard access to scratch_data */ @@ -2900,7 +2918,7 @@ namespace internal /** * Dereferencing operator. */ - ScratchData &operator*() + ScratchData &operator*() { return *my_scratch_data; } @@ -2908,20 +2926,20 @@ namespace internal /** * Dereferencing operator. */ - ScratchData *operator->() + ScratchData *operator->() { return my_scratch_data; } private: - ScratchData *my_scratch_data; + ScratchData *my_scratch_data; }; private: /** * The actual data object that contains a scratch data for each thread. */ - static Threads::ThreadLocalStorage scratch_data; + static Threads::ThreadLocalStorage> scratch_data; }; diff --git a/source/lac/affine_constraints.cc b/source/lac/affine_constraints.cc index 767ff5fc9f..dd160ed092 100644 --- a/source/lac/affine_constraints.cc +++ b/source/lac/affine_constraints.cc @@ -141,11 +141,11 @@ namespace internal { namespace AffineConstraints { -#define SCRATCH_INITIALIZER(number, Name) \ - AffineConstraintsData::ScratchData scratch_data_initializer_##Name; \ - template <> \ - Threads::ThreadLocalStorage::ScratchData> \ - AffineConstraintsData::scratch_data( \ +#define SCRATCH_INITIALIZER(number, Name) \ + ScratchData scratch_data_initializer_##Name; \ + template <> \ + Threads::ThreadLocalStorage> \ + AffineConstraintsData::scratch_data( \ scratch_data_initializer_##Name) SCRATCH_INITIALIZER(double, d);