// @HEADER // ***************************************************************************** // Tpetra: Templated Linear Algebra Services Package // // Copyright 2008 NTESS and the Tpetra contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef TPETRA_MMHELPERS_DEF_HPP #define TPETRA_MMHELPERS_DEF_HPP #include "TpetraExt_MMHelpers_decl.hpp" #include "Teuchos_VerboseObject.hpp" /*! \file TpetraExt_MMHelpers_def.hpp The implementations for the MatrixMatrix helper classes. */ namespace Tpetra { template CrsMatrixStruct::CrsMatrixStruct() { } template CrsMatrixStruct::~CrsMatrixStruct() { deleteContents(); } template void CrsMatrixStruct:: deleteContents () { importMatrix.reset(); origMatrix = Teuchos::null; } template BlockCrsMatrixStruct::BlockCrsMatrixStruct(const LocalOrdinal blocksize_) : blocksize(blocksize_) { } template BlockCrsMatrixStruct::~BlockCrsMatrixStruct() { deleteContents(); } template void BlockCrsMatrixStruct:: deleteContents () { importMatrix.reset(); origMatrix = Teuchos::null; } template int dumpCrsMatrixStruct (const CrsMatrixStruct& M) { std::cout << "proc " << M.rowMap->Comm().MyPID()<GID(i)<<" " <GID(M.indices[i][j])<<" "< CrsWrapper_CrsMatrix:: CrsWrapper_CrsMatrix (CrsMatrix& crsmatrix) : crsmat_ (crsmatrix) { } template CrsWrapper_CrsMatrix::~CrsWrapper_CrsMatrix() { } template Teuchos::RCP > CrsWrapper_CrsMatrix::getRowMap() const { return crsmat_.getRowMap(); } template bool CrsWrapper_CrsMatrix:: isFillComplete () { return crsmat_.isFillComplete (); } template void CrsWrapper_CrsMatrix:: insertGlobalValues (GlobalOrdinal globalRow, const Teuchos::ArrayView &indices, const Teuchos::ArrayView &values) { crsmat_.insertGlobalValues (globalRow, indices, values); } template void CrsWrapper_CrsMatrix:: sumIntoGlobalValues (GlobalOrdinal globalRow, const Teuchos::ArrayView &indices, const Teuchos::ArrayView &values) { crsmat_.sumIntoGlobalValues (globalRow, indices, values); } template CrsWrapper_GraphBuilder:: CrsWrapper_GraphBuilder (const Teuchos::RCP >& map) : graph_(), rowmap_(map), max_row_length_(0) { Teuchos::ArrayView rows = map->getLocalElementList (); const LocalOrdinal numRows = static_cast (rows.size ()); for (LocalOrdinal i = 0; i < numRows; ++i) { graph_[rows[i]] = new std::set; } } template CrsWrapper_GraphBuilder:: ~CrsWrapper_GraphBuilder () { typename std::map*>::iterator iter = graph_.begin(), iter_end = graph_.end(); for (; iter != iter_end; ++iter) { delete iter->second; } graph_.clear (); } template bool CrsWrapper_GraphBuilder::isFillComplete() { return false; } template void CrsWrapper_GraphBuilder:: insertGlobalValues (GlobalOrdinal globalRow, const Teuchos::ArrayView &indices, const Teuchos::ArrayView &/* values */) { typename std::map*>::iterator iter = graph_.find (globalRow); TEUCHOS_TEST_FOR_EXCEPTION( iter == graph_.end(), std::runtime_error, "Tpetra::CrsWrapper_GraphBuilder::insertGlobalValues could not find row " << globalRow << " in the graph. Super bummer man. Hope you figure it out."); std::set& cols = * (iter->second); for (typename Teuchos::ArrayView::size_type i = 0; i < indices.size (); ++i) { cols.insert (indices[i]); } const global_size_t row_length = static_cast (cols.size ()); if (row_length > max_row_length_) { max_row_length_ = row_length; } } template void CrsWrapper_GraphBuilder:: sumIntoGlobalValues (GlobalOrdinal globalRow, const Teuchos::ArrayView &indices, const Teuchos::ArrayView &values) { insertGlobalValues (globalRow, indices, values); } template std::map*>& CrsWrapper_GraphBuilder::get_graph () { return graph_; } template void insert_matrix_locations (CrsWrapper_GraphBuilder& graphbuilder, CrsMatrix& C) { global_size_t max_row_length = graphbuilder.get_max_row_length(); if (max_row_length < 1) return; Teuchos::Array indices(max_row_length); Teuchos::Array zeros(max_row_length, Teuchos::ScalarTraits::zero()); typedef std::map*> Graph; typedef typename Graph::iterator GraphIter; Graph& graph = graphbuilder.get_graph (); const GraphIter iter_end = graph.end (); for (GraphIter iter = graph.begin (); iter != iter_end; ++iter) { const GlobalOrdinal row = iter->first; const std::set& cols = * (iter->second); // "copy" entries out of set into contiguous array storage const size_t num_entries = std::copy (cols.begin (), cols.end (), indices.begin ()) - indices.begin (); // insert zeros into the result matrix at the appropriate locations C.insertGlobalValues (row, indices (0, num_entries), zeros (0, num_entries)); } } } // namespace Tpetra // // Explicit instantiation macro // // Must be expanded from within the Tpetra namespace! // #define TPETRA_CRSMATRIXSTRUCT_INSTANT(SCALAR,LO,GO,NODE) \ \ template class CrsMatrixStruct< SCALAR , LO , GO , NODE >; #define TPETRA_BLOCKCRSMATRIXSTRUCT_INSTANT(SCALAR,LO,GO,NODE) \ \ template class BlockCrsMatrixStruct< SCALAR , LO , GO , NODE >; #define TPETRA_CRSWRAPPER_INSTANT(SCALAR,LO,GO,NODE) \ \ template class CrsWrapper< SCALAR , LO , GO , NODE >; #define TPETRA_CRSWRAPPER_CRSMATRIX_INSTANT(SCALAR,LO,GO,NODE) \ \ template class CrsWrapper_CrsMatrix< SCALAR , LO , GO , NODE >; #define TPETRA_CRSWRAPPER_GRAPHBUILDER_INSTANT(SCALAR,LO,GO,NODE) \ \ template class CrsWrapper_GraphBuilder< SCALAR , LO , GO , NODE >; #endif // TPETRA_MMHELPERS_DEF_HPP