From 9920fce742da62a9e0f2094132f4fa81eeec3bf0 Mon Sep 17 00:00:00 2001 From: Tim Fuller Date: Tue, 13 Apr 2021 14:29:39 -0600 Subject: [PATCH] Adding begin/endAssembly to Tpetra::FEMultiVector --- .../core/src/Tpetra_FEMultiVector_decl.hpp | 17 +++++++ .../core/src/Tpetra_FEMultiVector_def.hpp | 47 +++++++++++++++++++ .../FEMultiVector/FEMultiVector_UnitTests.cpp | 14 +++--- .../core/test/FEMultiVector/Fix3101.cpp | 6 +-- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/packages/tpetra/core/src/Tpetra_FEMultiVector_decl.hpp b/packages/tpetra/core/src/Tpetra_FEMultiVector_decl.hpp index 42562f29d4ac..5f20a19745a4 100644 --- a/packages/tpetra/core/src/Tpetra_FEMultiVector_decl.hpp +++ b/packages/tpetra/core/src/Tpetra_FEMultiVector_decl.hpp @@ -165,6 +165,15 @@ namespace Tpetra { //! Declare the end of a phase of owned+shared modifications. void endFill (); + //! Declare the beginning of a phase of owned+shared modifications. + void beginAssembly (); + + //! Declare the end of a phase of owned+shared modifications. + void endAssembly (); + + void beginModify (); + void endModify (); + /// \brief Declare the end of a phase of owned+shared /// modifications; same as endFill(). void globalAssemble (); @@ -199,6 +208,14 @@ namespace Tpetra { FE_ACTIVE_OWNED }; + enum class FillState + { + open, // matrix is "open". Values can freely summed in to and replaced + modify, // matrix is open for modification. *local* values can be replaced + closed + }; + Teuchos::RCP fillState_; + //! Whichever MultiVector is not currently active. Teuchos::RCP inactiveMultiVector_; diff --git a/packages/tpetra/core/src/Tpetra_FEMultiVector_def.hpp b/packages/tpetra/core/src/Tpetra_FEMultiVector_def.hpp index d5cedf0be527..2cc71a402310 100644 --- a/packages/tpetra/core/src/Tpetra_FEMultiVector_def.hpp +++ b/packages/tpetra/core/src/Tpetra_FEMultiVector_def.hpp @@ -96,6 +96,7 @@ FEMultiVector (const Teuchos::RCP& map, inactiveMultiVector_ = Teuchos::rcp (new base_type (importer_->getSourceMap (), dv)); } + fillState_ = Teuchos::rcp(new FillState(FillState::closed)); } template @@ -128,6 +129,52 @@ endFill () } } +template +void FEMultiVector::beginAssembly() { + const char tfecfFuncName[] = "FEMultiVector::beginAssembly: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::closed, + std::runtime_error, + "Cannot beginAssembly, matrix is not in a closed state" + ); + *fillState_ = FillState::open; + this->beginFill(); +} + +template +void FEMultiVector::endAssembly() { + const char tfecfFuncName[] = "FEMultiVector::endAssembly: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::open, + std::runtime_error, + "Cannot endAssembly, matrix is not open to fill." + ); + *fillState_ = FillState::closed; + this->endFill(); +} + +template +void FEMultiVector::beginModify() { + const char tfecfFuncName[] = "FEMultiVector::beginModify: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::closed, + std::runtime_error, + "Cannot beginModify, matrix is not in a closed state" + ); + *fillState_ = FillState::modify; +} + +template +void FEMultiVector::endModify() { + const char tfecfFuncName[] = "FEMultiVector::endModify: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::modify, + std::runtime_error, + "Cannot endModify, matrix is not open to modify." + ); + *fillState_ = FillState::closed; +} + template void FEMultiVector:: diff --git a/packages/tpetra/core/test/FEMultiVector/FEMultiVector_UnitTests.cpp b/packages/tpetra/core/test/FEMultiVector/FEMultiVector_UnitTests.cpp index 4255c3d4e181..f1e6ead3d6b8 100644 --- a/packages/tpetra/core/test/FEMultiVector/FEMultiVector_UnitTests.cpp +++ b/packages/tpetra/core/test/FEMultiVector/FEMultiVector_UnitTests.cpp @@ -159,11 +159,11 @@ namespace { Vdomain.doExport(Vcolumn,*importer,Tpetra::ADD); - Vfe.beginFill(); + Vfe.beginAssembly(); Vfe.putScalar(ZERO); for(size_t i=0; igetGlobalElement(i); - Vfe.endFill(); + Vfe.endAssembly(); vector_check(Ndomain,Vfe,Vdomain); // 2) Test column -> domain (with off-proc addition) @@ -172,9 +172,9 @@ namespace { Vdomain.doExport(Vcolumn,*importer,Tpetra::ADD); Vfe.putScalar(ZERO); - Vfe.beginFill(); + Vfe.beginAssembly(); Vfe.putScalar(ONE); - Vfe.endFill(); + Vfe.endAssembly(); vector_check(Ncolumn,Vfe,Vdomain); } catch (std::exception& e) { err << "Proc " << myRank << ": " << e.what () << std::endl; @@ -219,10 +219,10 @@ namespace { Tpetra::FEMultiVector v2(map,importer,1); Tpetra::FEMultiVector v3(map,importer,1); - // Just check to make sure beginFill() / endFill() compile - Tpetra::beginFill(v1,v2,v3); + // Just check to make sure beginAssembly() / endAssembly() compile + Tpetra::beginAssembly(v1,v2,v3); - Tpetra::endFill(v1,v2,v3); + Tpetra::endAssembly(v1,v2,v3); } #define UNIT_TEST_GROUP( SC, LO, GO, NO ) \ diff --git a/packages/tpetra/core/test/FEMultiVector/Fix3101.cpp b/packages/tpetra/core/test/FEMultiVector/Fix3101.cpp index ec7a1a1e65b6..20d6749793c5 100644 --- a/packages/tpetra/core/test/FEMultiVector/Fix3101.cpp +++ b/packages/tpetra/core/test/FEMultiVector/Fix3101.cpp @@ -113,13 +113,13 @@ int FEMultiVectorTest::intTest() // Add contributions to owned vertices and copies of off-processor vertices try { - femv->beginFill(); + femv->beginAssembly(); for (lno_t i = 0; i < nLocalOwned + nLocalCopy; i++) { gno_t gid = mapWithCopies->getGlobalElement(i); femv->replaceGlobalValue(gid, 0, gid); femv->replaceGlobalValue(gid, 1, me); } - femv->endFill(); + femv->endAssembly(); } catch (std::exception &e) { std::cout << "FAIL: Exception thrown in Fill: " << e.what() << std::endl; @@ -140,7 +140,7 @@ int FEMultiVectorTest::intTest() printFEMV("After doOwnedToOwnedPlusShared "); - // Check results: after ADD in endFill, + // Check results: after ADD in endAssembly, // - overlapping entries of vec 0 should be 2 * gid // nonoverlapping entries of vec 0 should be gid // - overlapping entries of vec 1 should be me + (np + me-1) % np;