10 #ifndef TPETRA_MMHELPERS_DEF_HPP
11 #define TPETRA_MMHELPERS_DEF_HPP
14 #include "Teuchos_VerboseObject.hpp"
22 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
23 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::CrsMatrixStruct()
27 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
28 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::~CrsMatrixStruct()
33 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
34 void CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
38 origMatrix = Teuchos::null;
41 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
42 BlockCrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::BlockCrsMatrixStruct(
const LocalOrdinal blocksize_)
43 : blocksize(blocksize_)
47 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
48 BlockCrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::~BlockCrsMatrixStruct()
53 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
54 void BlockCrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
58 origMatrix = Teuchos::null;
61 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
62 int dumpCrsMatrixStruct (
const CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& M)
64 std::cout <<
"proc " << M.rowMap->Comm().MyPID()<<std::endl;
65 std::cout <<
"numRows: " << M.numRows<<std::endl;
66 for(LocalOrdinal i=0; i<M.numRows; ++i) {
67 for(LocalOrdinal j=0; j<M.numEntriesPerRow[i]; ++j) {
68 std::cout <<
" "<<M.rowMap->GID(i)<<
" "
69 <<M.colMap->GID(M.indices[i][j])<<
" "<<M.values[i][j]<<std::endl;
76 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
78 CrsWrapper_CrsMatrix (CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& crsmatrix)
83 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::~CrsWrapper_CrsMatrix()
88 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
90 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getRowMap()
const
92 return crsmat_.getRowMap();
95 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 bool CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
99 return crsmat_.isFillComplete ();
102 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
104 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
105 insertGlobalValues (GlobalOrdinal globalRow,
106 const Teuchos::ArrayView<const GlobalOrdinal> &indices,
107 const Teuchos::ArrayView<const Scalar> &values)
109 crsmat_.insertGlobalValues (globalRow, indices, values);
112 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
114 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
115 sumIntoGlobalValues (GlobalOrdinal globalRow,
116 const Teuchos::ArrayView<const GlobalOrdinal> &indices,
117 const Teuchos::ArrayView<const Scalar> &values)
119 crsmat_.sumIntoGlobalValues (globalRow, indices, values);
124 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
125 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
126 CrsWrapper_GraphBuilder (
const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& map)
131 Teuchos::ArrayView<const GlobalOrdinal> rows = map->getLocalElementList ();
132 const LocalOrdinal numRows =
static_cast<LocalOrdinal
> (rows.size ());
133 for (LocalOrdinal i = 0; i < numRows; ++i) {
134 graph_[rows[i]] =
new std::set<GlobalOrdinal>;
138 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
140 ~CrsWrapper_GraphBuilder ()
142 typename std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>::iterator
143 iter = graph_.begin(), iter_end = graph_.end();
144 for (; iter != iter_end; ++iter) {
150 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
151 bool CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::isFillComplete()
156 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
159 insertGlobalValues (GlobalOrdinal globalRow,
160 const Teuchos::ArrayView<const GlobalOrdinal> &indices,
161 const Teuchos::ArrayView<const Scalar> &)
163 typename std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>::iterator
164 iter = graph_.find (globalRow);
166 TEUCHOS_TEST_FOR_EXCEPTION(
167 iter == graph_.end(), std::runtime_error,
168 "Tpetra::CrsWrapper_GraphBuilder::insertGlobalValues could not find row "
169 << globalRow <<
" in the graph. Super bummer man. Hope you figure it out.");
171 std::set<GlobalOrdinal>& cols = * (iter->second);
173 for (
typename Teuchos::ArrayView<const GlobalOrdinal>::size_type i = 0;
174 i < indices.size (); ++i) {
175 cols.insert (indices[i]);
179 if (row_length > max_row_length_) {
180 max_row_length_ = row_length;
184 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
186 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
187 sumIntoGlobalValues (GlobalOrdinal globalRow,
188 const Teuchos::ArrayView<const GlobalOrdinal> &indices,
189 const Teuchos::ArrayView<const Scalar> &values)
191 insertGlobalValues (globalRow, indices, values);
194 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
195 std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>&
196 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::get_graph ()
201 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
203 insert_matrix_locations (CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>& graphbuilder,
204 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C)
206 global_size_t max_row_length = graphbuilder.get_max_row_length();
207 if (max_row_length < 1)
return;
209 Teuchos::Array<GlobalOrdinal> indices(max_row_length);
210 Teuchos::Array<Scalar> zeros(max_row_length, Teuchos::ScalarTraits<Scalar>::zero());
212 typedef std::map<GlobalOrdinal,std::set<GlobalOrdinal>*> Graph;
213 typedef typename Graph::iterator GraphIter;
214 Graph& graph = graphbuilder.get_graph ();
216 const GraphIter iter_end = graph.end ();
217 for (GraphIter iter = graph.begin (); iter != iter_end; ++iter) {
218 const GlobalOrdinal row = iter->first;
219 const std::set<GlobalOrdinal>& cols = * (iter->second);
221 const size_t num_entries = std::copy (cols.begin (), cols.end (), indices.begin ()) - indices.begin ();
223 C.insertGlobalValues (row, indices (0, num_entries), zeros (0, num_entries));
235 #define TPETRA_CRSMATRIXSTRUCT_INSTANT(SCALAR,LO,GO,NODE) \
237 template class CrsMatrixStruct< SCALAR , LO , GO , NODE >;
239 #define TPETRA_BLOCKCRSMATRIXSTRUCT_INSTANT(SCALAR,LO,GO,NODE) \
241 template class BlockCrsMatrixStruct< SCALAR , LO , GO , NODE >;
243 #define TPETRA_CRSWRAPPER_INSTANT(SCALAR,LO,GO,NODE) \
245 template class CrsWrapper< SCALAR , LO , GO , NODE >;
247 #define TPETRA_CRSWRAPPER_CRSMATRIX_INSTANT(SCALAR,LO,GO,NODE) \
249 template class CrsWrapper_CrsMatrix< SCALAR , LO , GO , NODE >;
251 #define TPETRA_CRSWRAPPER_GRAPHBUILDER_INSTANT(SCALAR,LO,GO,NODE) \
253 template class CrsWrapper_GraphBuilder< SCALAR , LO , GO , NODE >;
255 #endif // TPETRA_MMHELPERS_DEF_HPP
size_t global_size_t
Global size_t object.
Declaration of Tpetra::MMMultiMultiply and nonmember constructors.