From 197b9ffc3e82e7485625a2d3ff9f63f5d8b5bb45 Mon Sep 17 00:00:00 2001 From: Sam Mish Date: Mon, 5 Aug 2024 10:30:19 -0700 Subject: [PATCH 1/3] defer initialization of sparse matrix LUTs to when they're requested, rather than eagerly evaluating --- src/serac/numerics/functional/dof_numbering.hpp | 12 ++++++++++-- src/serac/numerics/functional/functional.hpp | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/serac/numerics/functional/dof_numbering.hpp b/src/serac/numerics/functional/dof_numbering.hpp index 8dce4e5f19..87a5b954d8 100644 --- a/src/serac/numerics/functional/dof_numbering.hpp +++ b/src/serac/numerics/functional/dof_numbering.hpp @@ -276,6 +276,9 @@ struct GradientAssemblyLookupTables { } }; }; + + /// dummy default ctor to enable deferred initialization + GradientAssemblyLookupTables() : initialized{false} {}; /** * @param block_test_dofs object containing information about dofs for the test space @@ -284,8 +287,8 @@ struct GradientAssemblyLookupTables { * @brief create lookup tables describing which degrees of freedom * correspond to each domain/boundary element */ - GradientAssemblyLookupTables(const serac::BlockElementRestriction& block_test_dofs, - const serac::BlockElementRestriction& block_trial_dofs) + void init(const serac::BlockElementRestriction& block_test_dofs, + const serac::BlockElementRestriction& block_trial_dofs) { // we start by having each element and boundary element emit the (i,j) entry that it // touches in the global "stiffness matrix", and also keep track of some metadata about @@ -342,6 +345,8 @@ struct GradientAssemblyLookupTables { } row_ptr.back() = static_cast(nnz); + + initialized = true; } /** @@ -368,6 +373,9 @@ struct GradientAssemblyLookupTables { * corresponding to the (i,j) entry */ std::unordered_map nz_LUT; + + bool initialized; + }; } // namespace serac diff --git a/src/serac/numerics/functional/functional.hpp b/src/serac/numerics/functional/functional.hpp index 9930b3b84a..8f32a3096b 100644 --- a/src/serac/numerics/functional/functional.hpp +++ b/src/serac/numerics/functional/functional.hpp @@ -537,7 +537,6 @@ class Functional { Gradient(Functional& f, uint32_t which = 0) : mfem::Operator(f.test_space_->GetTrueVSize(), f.trial_space_[which]->GetTrueVSize()), form_(f), - lookup_tables(f.G_test_[Domain::Type::Elements], f.G_trial_[Domain::Type::Elements][which]), which_argument(which), test_space_(f.test_space_), trial_space_(f.trial_space_[which]), @@ -575,6 +574,10 @@ class Functional { constexpr bool col_ind_is_sorted = true; + if (!lookup_tables.initialized) { + lookup_tables.init(form_.G_test_[Domain::Type::Elements], form_.G_trial_[Domain::Type::Elements][which_argument]); + } + double* values = new double[lookup_tables.nnz]{}; std::map> element_gradients[Domain::num_types]; From 1169b6e53b5dd4808a43562f6f54b3e5c682b3d6 Mon Sep 17 00:00:00 2001 From: Michael Tupek Date: Mon, 5 Aug 2024 13:18:12 -0700 Subject: [PATCH 2/3] Fix style. --- src/serac/numerics/functional/dof_numbering.hpp | 5 ++--- src/serac/numerics/functional/functional.hpp | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/serac/numerics/functional/dof_numbering.hpp b/src/serac/numerics/functional/dof_numbering.hpp index 87a5b954d8..39c671f617 100644 --- a/src/serac/numerics/functional/dof_numbering.hpp +++ b/src/serac/numerics/functional/dof_numbering.hpp @@ -276,9 +276,9 @@ struct GradientAssemblyLookupTables { } }; }; - + /// dummy default ctor to enable deferred initialization - GradientAssemblyLookupTables() : initialized{false} {}; + GradientAssemblyLookupTables() : initialized{false} {}; /** * @param block_test_dofs object containing information about dofs for the test space @@ -375,7 +375,6 @@ struct GradientAssemblyLookupTables { std::unordered_map nz_LUT; bool initialized; - }; } // namespace serac diff --git a/src/serac/numerics/functional/functional.hpp b/src/serac/numerics/functional/functional.hpp index 50b33bd8ae..9cd91ed7d6 100644 --- a/src/serac/numerics/functional/functional.hpp +++ b/src/serac/numerics/functional/functional.hpp @@ -576,7 +576,8 @@ class Functional { constexpr bool col_ind_is_sorted = true; if (!lookup_tables.initialized) { - lookup_tables.init(form_.G_test_[Domain::Type::Elements], form_.G_trial_[Domain::Type::Elements][which_argument]); + lookup_tables.init(form_.G_test_[Domain::Type::Elements], + form_.G_trial_[Domain::Type::Elements][which_argument]); } double* values = new double[lookup_tables.nnz]{}; From 97fa3ef71520515dd387bfde8ec52bef43e45fd5 Mon Sep 17 00:00:00 2001 From: Michael Tupek Date: Mon, 5 Aug 2024 15:08:08 -0700 Subject: [PATCH 3/3] Fix docs. --- src/serac/numerics/functional/dof_numbering.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/serac/numerics/functional/dof_numbering.hpp b/src/serac/numerics/functional/dof_numbering.hpp index 39c671f617..0c9bec0412 100644 --- a/src/serac/numerics/functional/dof_numbering.hpp +++ b/src/serac/numerics/functional/dof_numbering.hpp @@ -374,6 +374,7 @@ struct GradientAssemblyLookupTables { */ std::unordered_map nz_LUT; + /// @brief specifies if the table has already been initialized or not bool initialized; };