From 7df33069e0b42e8c46492f0383465b6a9422208a Mon Sep 17 00:00:00 2001 From: Tim Fuller Date: Wed, 24 Mar 2021 07:20:16 -0600 Subject: [PATCH] update FECrsMatrix to add begin/endAssembly and begin/endModify --- .../tpetra/core/src/Tpetra_CrsMatrix_decl.hpp | 24 ++- .../core/src/Tpetra_FECrsMatrix_decl.hpp | 75 +++++++ .../core/src/Tpetra_FECrsMatrix_def.hpp | 159 ++++++++++++++- .../FECrsMatrix/FECrsMatrix_UnitTests.cpp | 188 ++++++++++++------ 4 files changed, 377 insertions(+), 69 deletions(-) diff --git a/packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp b/packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp index 7b7c51e03e79..983aaff25956 100644 --- a/packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp +++ b/packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp @@ -842,13 +842,14 @@ namespace Tpetra { MultiVector & R); // This friend declaration allows for batching of apply calls - template - friend void batchedApply(const MatrixArray &Matrices, + template + friend void batchedApply(const MatrixArray &Matrices, const typename std::remove_pointer::type & X, MultiVectorArray &Y, typename std::remove_pointer::type::scalar_type alpha, typename std::remove_pointer::type::scalar_type beta, Teuchos::RCP params); + public: //@} //! @name Methods for inserting, modifying, or removing entries @@ -1013,7 +1014,7 @@ namespace Tpetra { const Scalar vals[], const LocalOrdinal cols[]); - private: + protected: /// \brief Implementation detail of replaceGlobalValues. /// /// \param rowVals [in/out] On input: Values of the row of the @@ -1024,7 +1025,7 @@ namespace Tpetra { /// \param inds [in] Global column indices of that row to modify. /// \param newVals [in] For each k, replace the value in rowVals /// corresponding to local column index inds[k] with newVals[k]. - LocalOrdinal + virtual LocalOrdinal replaceGlobalValuesImpl (impl_scalar_type rowVals[], const crs_graph_type& graph, const RowInfo& rowInfo, @@ -1102,7 +1103,7 @@ namespace Tpetra { const Scalar vals[], const GlobalOrdinal cols[]) const; - private: + protected: /// \brief Implementation detail of replaceLocalValues. /// /// \param rowVals [in/out] On input: Values of the row of the @@ -1113,7 +1114,7 @@ namespace Tpetra { /// \param inds [in] Local column indices of that row to modify. /// \param newVals [in] For each k, replace the value in rowVals /// corresponding to local column index inds[k] with newVals[k]. - LocalOrdinal + virtual LocalOrdinal replaceLocalValuesImpl (impl_scalar_type rowVals[], const crs_graph_type& graph, const RowInfo& rowInfo, @@ -1229,7 +1230,8 @@ namespace Tpetra { /// error other than one or more invalid column indices, this /// method returns /// Teuchos::OrdinalTraits::invalid(). - LocalOrdinal + protected: + virtual LocalOrdinal sumIntoGlobalValuesImpl (impl_scalar_type rowVals[], const crs_graph_type& graph, const RowInfo& rowInfo, @@ -1310,7 +1312,7 @@ namespace Tpetra { const GlobalOrdinal cols[], const bool atomic = useAtomicUpdatesByDefault); - private: + protected: /// \brief Implementation detail of sumIntoLocalValues. /// /// \param rowVals [in/out] On input: Values of the row of the @@ -1323,7 +1325,7 @@ namespace Tpetra { /// corresponding to local column index inds[k] by newVals[k]. /// \param atomic [in] Whether to use atomic updates (+=) when /// incrementing values. - LocalOrdinal + virtual LocalOrdinal sumIntoLocalValuesImpl (impl_scalar_type rowVals[], const crs_graph_type& graph, const RowInfo& rowInfo, @@ -3469,13 +3471,15 @@ namespace Tpetra { /// are in the column Map on the calling process. That is, the /// entries of gblColInds (and their corresponding vals entries) /// are "prefiltered," if we needed to filter them. - void + protected: + virtual void insertGlobalValuesImpl (crs_graph_type& graph, RowInfo& rowInfo, const GlobalOrdinal gblColInds[], const impl_scalar_type vals[], const size_t numInputEnt); + private: /// \brief Like insertGlobalValues(), but with column filtering. /// /// "Column filtering" means that if the matrix has a column Map, diff --git a/packages/tpetra/core/src/Tpetra_FECrsMatrix_decl.hpp b/packages/tpetra/core/src/Tpetra_FECrsMatrix_decl.hpp index 44509dd15d7c..91c6e154b082 100644 --- a/packages/tpetra/core/src/Tpetra_FECrsMatrix_decl.hpp +++ b/packages/tpetra/core/src/Tpetra_FECrsMatrix_decl.hpp @@ -224,6 +224,73 @@ class FECrsMatrix : //! Activates the owned+shared mode for assembly void beginFill(); + //! Migrates data to the owned mode + void endAssembly(); + + //! Activates the owned+shared mode for assembly + void beginAssembly(); + + //! Closes modification phase + void endModify(); + + //! Activates the owned mode for modifying local values + void beginModify(); + + private: + + /// \brief Whether sumIntoLocalValues and sumIntoGlobalValues + /// should use atomic updates by default. + /// + /// \warning This is an implementation detail. + static const bool useAtomicUpdatesByDefault = +#ifdef KOKKOS_ENABLE_SERIAL + ! std::is_same::value; +#else + true; +#endif // KOKKOS_ENABLE_SERIAL + + //! Overloads of modification methods + LocalOrdinal + replaceGlobalValuesImpl (impl_scalar_type rowVals[], + const crs_graph_type& graph, + const RowInfo& rowInfo, + const GlobalOrdinal inds[], + const impl_scalar_type newVals[], + const LocalOrdinal numElts) const; + + LocalOrdinal + replaceLocalValuesImpl (impl_scalar_type rowVals[], + const crs_graph_type& graph, + const RowInfo& rowInfo, + const LocalOrdinal inds[], + const impl_scalar_type newVals[], + const LocalOrdinal numElts) const; + + LocalOrdinal + sumIntoGlobalValuesImpl (impl_scalar_type rowVals[], + const crs_graph_type& graph, + const RowInfo& rowInfo, + const GlobalOrdinal inds[], + const impl_scalar_type newVals[], + const LocalOrdinal numElts, + const bool atomic = useAtomicUpdatesByDefault) const; + + LocalOrdinal + sumIntoLocalValuesImpl (impl_scalar_type rowVals[], + const crs_graph_type& graph, + const RowInfo& rowInfo, + const LocalOrdinal inds[], + const impl_scalar_type newVals[], + const LocalOrdinal numElts, + const bool atomic = useAtomicUpdatesByDefault) const; + + void + insertGlobalValuesImpl (crs_graph_type& graph, + RowInfo& rowInfo, + const GlobalOrdinal gblColInds[], + const impl_scalar_type vals[], + const size_t numInputEnt); + protected: /// \brief Migrate data from the owned+shared to the owned matrix /// Since this is non-unique -> unique, we need a combine mode. @@ -254,6 +321,14 @@ class FECrsMatrix : // This is in RCP to make shallow copies of the FECrsMatrix work correctly Teuchos::RCP activeCrsMatrix_; + 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_; + }; // end class FECrsMatrix diff --git a/packages/tpetra/core/src/Tpetra_FECrsMatrix_def.hpp b/packages/tpetra/core/src/Tpetra_FECrsMatrix_def.hpp index c2c138b29e39..8b6963e41474 100644 --- a/packages/tpetra/core/src/Tpetra_FECrsMatrix_def.hpp +++ b/packages/tpetra/core/src/Tpetra_FECrsMatrix_def.hpp @@ -49,7 +49,7 @@ namespace Tpetra { template FECrsMatrix:: FECrsMatrix(const Teuchos::RCP& graph, - const Teuchos::RCP& params) : + const Teuchos::RCP& params) : // We want the OWNED_PLUS_SHARED graph here // NOTE: The casts below are terrible, but necesssary crs_matrix_type( graph->inactiveCrsGraph_.is_null() ? Teuchos::rcp_const_cast(Teuchos::rcp_dynamic_cast(graph)) : graph->inactiveCrsGraph_,params), @@ -76,13 +76,15 @@ FECrsMatrix(const Teuchos::RCP& graph, // Make an "inactive" matrix, if we need to if(!graph->inactiveCrsGraph_.is_null() ) { - // We are *requiring* memory aliasing here, so we'll grab the first chunk of the Owned+Shared matrix's values array to make the + // We are *requiring* memory aliasing here, so we'll grab the first chunk of the Owned+Shared matrix's values array to make the // guy for the Owned matrix. values_type myvals = this->getLocalMatrix().values; size_t numOwnedVals = graph->getLocalGraph().entries.extent(0); // OwnedVals inactiveCrsMatrix_ = Teuchos::rcp(new crs_matrix_type(graph,Kokkos::subview(myvals,Kokkos::pair(0,numOwnedVals)))); } + + fillState_ = Teuchos::rcp(new FillState(FillState::closed)); } @@ -111,7 +113,7 @@ void FECrsMatrix::switchActiveCrsMatr *activeCrsMatrix_ = FE_ACTIVE_OWNED_PLUS_SHARED; if(inactiveCrsMatrix_.is_null()) return; - + this->swap(*inactiveCrsMatrix_); }//end switchActiveCrsMatrix @@ -138,8 +140,159 @@ void FECrsMatrix::beginFill() { this->resumeFill(); } +template +void FECrsMatrix::beginAssembly() { + const char tfecfFuncName[] = "FECrsMatrix::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 FECrsMatrix::endAssembly() { + const char tfecfFuncName[] = "FECrsMatrix::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 FECrsMatrix::beginModify() { + const char tfecfFuncName[] = "FECrsMatrix::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; + this->resumeFill(); +} + +template +void FECrsMatrix::endModify() { + const char tfecfFuncName[] = "FECrsMatrix::endModify: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::modify, + std::runtime_error, + "Cannot endModify, matrix is not open to modify." + ); + *fillState_ = FillState::closed; + this->fillComplete(); +} + +template +LocalOrdinal +FECrsMatrix::replaceGlobalValuesImpl( + impl_scalar_type rowVals[], + const crs_graph_type& graph, + const RowInfo& rowInfo, + const GlobalOrdinal inds[], + const impl_scalar_type newVals[], + const LocalOrdinal numElts) const +{ + const char tfecfFuncName[] = "FECrsMatrix::replaceGlobalValues: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::open, + std::runtime_error, + "Cannot replace global values, matrix is not open to fill." + ); + return CrsMatrix::replaceGlobalValuesImpl( + rowVals, graph, rowInfo, inds, newVals, numElts + ); +} + +template +LocalOrdinal +FECrsMatrix::replaceLocalValuesImpl( + impl_scalar_type rowVals[], + const crs_graph_type& graph, + const RowInfo& rowInfo, + const LocalOrdinal inds[], + const impl_scalar_type newVals[], + const LocalOrdinal numElts) const +{ + const char tfecfFuncName[] = "FECrsMatrix::replaceLocalValues: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::open && *fillState_ != FillState::modify, + std::runtime_error, + "Cannot replace local values, matrix is not open to fill/modify." + ); + return CrsMatrix::replaceLocalValuesImpl( + rowVals, graph, rowInfo, inds, newVals, numElts + ); +} + +template +LocalOrdinal +FECrsMatrix::sumIntoGlobalValuesImpl( + impl_scalar_type rowVals[], + const crs_graph_type& graph, + const RowInfo& rowInfo, + const GlobalOrdinal inds[], + const impl_scalar_type newVals[], + const LocalOrdinal numElts, + const bool atomic) const +{ + const char tfecfFuncName[] = "FECrsMatrix::sumIntoGlobalValues: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::open, + std::runtime_error, + "Cannot sum in to global values, matrix is not open to fill." + ); + return CrsMatrix::sumIntoGlobalValuesImpl( + rowVals, graph, rowInfo, inds, newVals, numElts, atomic + ); +} +template +LocalOrdinal +FECrsMatrix::sumIntoLocalValuesImpl( + impl_scalar_type rowVals[], + const crs_graph_type& graph, + const RowInfo& rowInfo, + const LocalOrdinal inds[], + const impl_scalar_type newVals[], + const LocalOrdinal numElts, + const bool atomic) const +{ + const char tfecfFuncName[] = "FECrsMatrix::sumIntoLocalValues: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::open, + std::runtime_error, + "Cannot sum in to local values, matrix is not open to fill." + ); + return CrsMatrix::sumIntoLocalValuesImpl( + rowVals, graph, rowInfo, inds, newVals, numElts, atomic + ); +} +template +void +FECrsMatrix::insertGlobalValuesImpl( + crs_graph_type& graph, + RowInfo& rowInfo, + const GlobalOrdinal gblColInds[], + const impl_scalar_type vals[], + const size_t numInputEnt) +{ + const char tfecfFuncName[] = "FECrsMatrix::insertGlobalValues: "; + TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( + *fillState_ != FillState::open, + std::runtime_error, + "Cannot sum in to local values, matrix is not open to fill." + ); + return CrsMatrix::insertGlobalValuesImpl( + graph, rowInfo, gblColInds, vals, numInputEnt + ); +} } // end namespace Tpetra diff --git a/packages/tpetra/core/test/FECrsMatrix/FECrsMatrix_UnitTests.cpp b/packages/tpetra/core/test/FECrsMatrix/FECrsMatrix_UnitTests.cpp index de50cfe6a031..05b3f8965a86 100644 --- a/packages/tpetra/core/test/FECrsMatrix/FECrsMatrix_UnitTests.cpp +++ b/packages/tpetra/core/test/FECrsMatrix/FECrsMatrix_UnitTests.cpp @@ -72,7 +72,7 @@ typedef std::complex scd; template bool compare_final_matrix_structure_impl(Teuchos::FancyOStream &out,Tpetra::CrsMatrix & g1, Tpetra::CrsMatrix & g2, TOLERANCE tol) { using std::endl; - + if (!g1.isFillComplete() || !g2.isFillComplete()) {out<<"Compare: FillComplete failed"<isSameAs(*g2.getRangeMap())) {out<<"Compare: RangeMap failed"<isSameAs(*g2.getRowMap())) {out<<"Compare: RowMap failed"<(Kokkos::Compat::getArrayView(values1_h)); - auto values2_av = Teuchos::av_reinterpret_cast(Kokkos::Compat::getArrayView(values2_h)); + auto values2_av = Teuchos::av_reinterpret_cast(Kokkos::Compat::getArrayView(values2_h)); TEST_COMPARE_FLOATING_ARRAYS(values1_av,values2_av,tol); if (!success) {out<<"Compare: values match failed"< struct compare { - static bool compare_final_matrix_structure(Teuchos::FancyOStream &out,Tpetra::CrsMatrix & g1, Tpetra::CrsMatrix & g2){ + static bool compare_final_matrix_structure(Teuchos::FancyOStream &out,Tpetra::CrsMatrix & g1, Tpetra::CrsMatrix & g2){ typedef typename Teuchos::ScalarTraits::magnitudeType Mag; double errorTolSlack = 1.0e+2; const Mag tol = errorTolSlack * Teuchos::ScalarTraits::eps(); @@ -150,7 +150,7 @@ class GraphPack { out << "["<getNodeNumElements(); i++) out << uniqueMap->getGlobalElement(i) << " "; - out<getNodeNumElements(); i++) @@ -225,7 +225,7 @@ std::vector > generate_fem1d_element_values() { } template -Kokkos::View generate_fem1d_element_values_kokkos() { +Kokkos::View generate_fem1d_element_values_kokkos() { Kokkos::View mat ("fem1d_element_values"); auto mat_h = Kokkos::create_mirror_view(mat); @@ -253,15 +253,15 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D, LO, GO, Scalar, Node // get a comm RCP > comm = getDefaultComm(); - + // Generate a mesh size_t numLocal = 10; GraphPack pack; generate_fem1d_graph(numLocal,comm,pack); - - // Make the graph + + // Make the graph // FIXME: We should be able to get away with 3 for StaticProfile here, but we need 4 since duplicates are - // not being handled correctly. + // not being handled correctly. RCP graph = rcp(new FEG(pack.uniqueMap,pack.overlapMap,4)); graph->beginFill(); @@ -282,23 +282,98 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D, LO, GO, Scalar, Node std::vector > localValues = generate_fem1d_element_values(); // Make the matrix two ways - FEMAT mat1(graph); // Here we use graph as a FECrsGraph + FEMAT fe_matrix(graph); // Here we use graph as a FECrsGraph CMAT mat2(graph); // Here we use graph as a CrsGraph in OWNED mode - mat1.beginFill(); + fe_matrix.beginAssembly(); for(size_t i=0; i<(size_t)pack.element2node.size(); i++) { for(size_t j=0; j::compare_final_matrix_structure(out,mat1,mat2); + success = compare::compare_final_matrix_structure(out,fe_matrix,mat2); + TPETRA_GLOBAL_SUCCESS_CHECK(out,comm,success) +} + +TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_2, LO, GO, Scalar, Node ) +{ + using FEMAT = typename Tpetra::FECrsMatrix; + using CMAT = typename Tpetra::CrsMatrix; + using FEG = typename Tpetra::FECrsGraph; + + // get a comm + RCP > comm = getDefaultComm(); + + // Generate a mesh + size_t numLocal = 10; + GraphPack pack; + generate_fem1d_graph(numLocal,comm,pack); + + // Make the graph + // FIXME: We should be able to get away with 3 for StaticProfile here, but we need 4 since duplicates are + // not being handled correctly. + RCP graph = rcp(new FEG(pack.uniqueMap, pack.overlapMap, 4)); + + graph->beginFill(); + for(size_t i=0; i<(size_t)pack.element2node.size(); i++) { + for(size_t j=0; jinsertGlobalIndices(gid_j,1,&gid_k); + } + } + } + graph->endFill(); + + + // Generate the "local stiffness matrix" + std::vector > localValues = generate_fem1d_element_values(); + + // Make the matrix two ways + FEMAT fe_matrix(graph); // Here we use graph as a FECrsGraph + CMAT mat2(graph); // Here we use graph as a CrsGraph in OWNED mode + + fe_matrix.beginAssembly(); + for(size_t i=0; i<(size_t)pack.element2node.size(); i++) { + for(size_t j=0; j::compare_final_matrix_structure(out,fe_matrix,mat2); + + // Insert Dirichlet boundary conditions + fe_matrix.beginModify(); + LO local_row = 0; + if (fe_matrix.getRowMap()->isNodeLocalElement(local_row)) + { + auto num_entries = fe_matrix.getNodeNumEntries(); + Teuchos::Array cols(num_entries); + Scalar zero = Teuchos::ScalarTraits::zero(); + Scalar one = Teuchos::ScalarTraits::one(); + Teuchos::Array vals(num_entries, zero); + fe_matrix.getLocalRowCopy(local_row, cols(), vals(), num_entries); + std::fill(vals.begin(), vals.end(), zero); + vals[0] = one; + fe_matrix.replaceLocalValues(local_row, cols(), vals()); + } + fe_matrix.endModify(); TPETRA_GLOBAL_SUCCESS_CHECK(out,comm,success) } @@ -314,15 +389,15 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_Kokkos, LO, GO, Scala // get a comm RCP > comm = getDefaultComm(); - + // Generate a mesh size_t numLocal = 10; GraphPack pack; generate_fem1d_graph(numLocal,comm,pack); - // Make the graph + // Make the graph // FIXME: We should be able to get away with 3 for StaticProfile here, but we need 4 since duplicates are - // not being handled correctly. + // not being handled correctly. RCP graph = rcp(new FEG(pack.uniqueMap,pack.overlapMap,4)); graph->beginFill(); @@ -343,17 +418,17 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_Kokkos, LO, GO, Scala auto kokkosValues = generate_fem1d_element_values_kokkos(); // Make the matrix two ways - FEMAT mat1(graph); // Here we use graph as a FECrsGraph + FEMAT fe_matrix(graph); // Here we use graph as a FECrsGraph CMAT mat2(graph); // Here we use graph as a CrsGraph in OWNED mode - mat1.beginFill(); + fe_matrix.beginAssembly(); auto k_e2n = pack.k_element2node; - auto localMat = mat1.getLocalMatrix(); + auto localMat = fe_matrix.getLocalMatrix(); auto localMap = pack.overlapMap->getLocalMap(); //get local map too Kokkos::parallel_for("assemble_1d", - range_type (0,k_e2n.extent(0)), + range_type (0,k_e2n.extent(0)), KOKKOS_LAMBDA(const size_t i) { size_t extent = k_e2n.extent(1); for(size_t j=0; j < extent; j++) { @@ -365,8 +440,8 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_Kokkos, LO, GO, Scala } } }); - mat1.endFill(); - + fe_matrix.endAssembly(); + for(size_t i=0; i<(size_t)pack.element2node.size(); i++) { for(size_t j=0; j::compare_final_matrix_structure(out,mat1,mat2); + success = compare::compare_final_matrix_structure(out,fe_matrix,mat2); TPETRA_GLOBAL_SUCCESS_CHECK(out,comm,success) } @@ -391,13 +466,13 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_LocalIndex, LO, GO, S // get a comm RCP > comm = getDefaultComm(); - + // Generate a mesh size_t numLocal = 10; GraphPack pack; generate_fem1d_graph(numLocal,comm,pack); - - // Make the graph + + // Make the graph RCP graph = rcp(new FEG(pack.uniqueMap,pack.overlapMap,pack.overlapMap,3)); graph->beginFill(); @@ -420,9 +495,9 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_LocalIndex, LO, GO, S std::vector > localValues = generate_fem1d_element_values(); // Make the matrix two ways - FEMAT mat1(graph); // Here we use graph as a FECrsGraph + FEMAT fe_matrix(graph); // Here we use graph as a FECrsGraph CMAT mat2(graph); // Here we use graph as a CrsGraph in OWNED mode - mat1.beginFill(); + fe_matrix.beginAssembly(); for(size_t i=0; i<(size_t)pack.element2node.size(); i++) { for(size_t j=0; jgetLocalElement(gid_k); - mat1.sumIntoLocalValues(lid_j,1,&localValues[j][k],&lid_k); + fe_matrix.sumIntoLocalValues(lid_j,1,&localValues[j][k],&lid_k); mat2.sumIntoGlobalValues(gid_j,1,&localValues[j][k],&gid_k); } } } - mat1.endFill(); + fe_matrix.endAssembly(); mat2.fillComplete(); - success = compare::compare_final_matrix_structure(out,mat1,mat2); + success = compare::compare_final_matrix_structure(out,fe_matrix,mat2); TPETRA_GLOBAL_SUCCESS_CHECK(out,comm,success) } @@ -454,13 +529,13 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_LocalIndex_Kokkos, LO // get a comm RCP > comm = getDefaultComm(); - + // Generate a mesh size_t numLocal = 10; GraphPack pack; generate_fem1d_graph(numLocal,comm,pack); - - // Make the graph + + // Make the graph RCP graph = rcp(new FEG(pack.uniqueMap,pack.overlapMap,pack.overlapMap,3)); graph->beginFill(); @@ -483,14 +558,14 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_LocalIndex_Kokkos, LO auto kokkosValues = generate_fem1d_element_values_kokkos(); // Make the matrix two ways - FEMAT mat1(graph); // Here we use graph as a FECrsGraph + FEMAT fe_matrix(graph); // Here we use graph as a FECrsGraph CMAT mat2(graph); // Here we use graph as a CrsGraph in OWNED mode - mat1.beginFill(); + fe_matrix.beginAssembly(); auto k_e2n = pack.k_element2node; - auto localMat = mat1.getLocalMatrix(); + auto localMat = fe_matrix.getLocalMatrix(); auto localMap = pack.overlapMap->getLocalMap(); - Kokkos::parallel_for("assemble_1d_local_index", + Kokkos::parallel_for("assemble_1d_local_index", range_type (0, k_e2n.extent(0)), KOKKOS_LAMBDA(const size_t i) { for(size_t j=0; j::compare_final_matrix_structure(out,mat1,mat2); + success = compare::compare_final_matrix_structure(out,fe_matrix,mat2); TPETRA_GLOBAL_SUCCESS_CHECK(out,comm,success) } @@ -534,13 +609,13 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_LocalIndex_Kokkos_Mul // get a comm RCP > comm = getDefaultComm(); - + // Generate a mesh size_t numLocal = 10; GraphPack pack; generate_fem1d_graph(numLocal,comm,pack); - - // Make the graph + + // Make the graph RCP graph = rcp(new FEG(pack.uniqueMap,pack.overlapMap,pack.overlapMap,3)); graph->beginFill(); @@ -563,20 +638,20 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_LocalIndex_Kokkos_Mul auto kokkosValues = generate_fem1d_element_values_kokkos(); // Make the matrix two ways - FEMAT mat1(graph); // Here we use graph as a FECrsGraph + FEMAT fe_matrix(graph); // Here we use graph as a FECrsGraph CMAT mat2(graph); // Here we use graph as a CrsGraph in OWNED mode const int number_of_fills = 3; for(int nof=0; nofgetLocalMap(); - - Kokkos::parallel_for("assemble_1d_local_index", + + Kokkos::parallel_for("assemble_1d_local_index", range_type (0, k_e2n.extent(0)), KOKKOS_LAMBDA(const size_t i) { for(size_t j=0; j::compare_final_matrix_structure(out,mat1,mat2); + success = compare::compare_final_matrix_structure(out,fe_matrix,mat2); TPETRA_GLOBAL_SUCCESS_CHECK(out,comm,success) } @@ -614,9 +689,10 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL( FECrsMatrix, Assemble1D_LocalIndex_Kokkos_Mul #define UNIT_TEST_GROUP( SCALAR, LO, GO, NODE ) \ TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT( FECrsMatrix, Assemble1D_Kokkos, LO, GO, SCALAR, NODE ) \ TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT( FECrsMatrix, Assemble1D, LO, GO, SCALAR, NODE ) \ + TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT( FECrsMatrix, Assemble1D_2, LO, GO, SCALAR, NODE ) \ TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT( FECrsMatrix, Assemble1D_LocalIndex, LO, GO, SCALAR, NODE ) \ TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT( FECrsMatrix, Assemble1D_LocalIndex_Kokkos, LO, GO, SCALAR, NODE ) \ - TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT( FECrsMatrix, Assemble1D_LocalIndex_Kokkos_Multiple, LO, GO, SCALAR, NODE ) + TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT( FECrsMatrix, Assemble1D_LocalIndex_Kokkos_Multiple, LO, GO, SCALAR, NODE ) TPETRA_ETI_MANGLING_TYPEDEFS()