42 #ifndef TPETRA_MMHELPERS_DEF_HPP
43 #define TPETRA_MMHELPERS_DEF_HPP
46 #include "Teuchos_VerboseObject.hpp"
54 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
55 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::CrsMatrixStruct()
59 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::~CrsMatrixStruct()
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
66 void CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
70 origMatrix = Teuchos::null;
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
74 int dumpCrsMatrixStruct (
const CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& M)
76 std::cout <<
"proc " << M.rowMap->Comm().MyPID()<<std::endl;
77 std::cout <<
"numRows: " << M.numRows<<std::endl;
78 for(LocalOrdinal i=0; i<M.numRows; ++i) {
79 for(LocalOrdinal j=0; j<M.numEntriesPerRow[i]; ++j) {
80 std::cout <<
" "<<M.rowMap->GID(i)<<
" "
81 <<M.colMap->GID(M.indices[i][j])<<
" "<<M.values[i][j]<<std::endl;
88 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
90 CrsWrapper_CrsMatrix (CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& crsmatrix)
95 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::~CrsWrapper_CrsMatrix()
100 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
102 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getRowMap()
const
104 return crsmat_.getRowMap();
107 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
108 bool CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
111 return crsmat_.isFillComplete ();
114 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
116 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
117 insertGlobalValues (GlobalOrdinal globalRow,
118 const Teuchos::ArrayView<const GlobalOrdinal> &indices,
119 const Teuchos::ArrayView<const Scalar> &values)
121 crsmat_.insertGlobalValues (globalRow, indices, values);
124 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126 CrsWrapper_CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
127 sumIntoGlobalValues (GlobalOrdinal globalRow,
128 const Teuchos::ArrayView<const GlobalOrdinal> &indices,
129 const Teuchos::ArrayView<const Scalar> &values)
131 crsmat_.sumIntoGlobalValues (globalRow, indices, values);
136 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
138 CrsWrapper_GraphBuilder (
const Teuchos::RCP<
const Map<LocalOrdinal, GlobalOrdinal, Node> >& map)
143 Teuchos::ArrayView<const GlobalOrdinal> rows = map->getNodeElementList ();
144 const LocalOrdinal numRows =
static_cast<LocalOrdinal
> (rows.size ());
145 for (LocalOrdinal i = 0; i < numRows; ++i) {
146 graph_[rows[i]] =
new std::set<GlobalOrdinal>;
150 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
151 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
152 ~CrsWrapper_GraphBuilder ()
154 typename std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>::iterator
155 iter = graph_.begin(), iter_end = graph_.end();
156 for (; iter != iter_end; ++iter) {
162 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
163 bool CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::isFillComplete()
168 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
170 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
171 insertGlobalValues (GlobalOrdinal globalRow,
172 const Teuchos::ArrayView<const GlobalOrdinal> &indices,
173 const Teuchos::ArrayView<const Scalar> &)
175 typename std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>::iterator
176 iter = graph_.find (globalRow);
178 TEUCHOS_TEST_FOR_EXCEPTION(
179 iter == graph_.end(), std::runtime_error,
180 "Tpetra::CrsWrapper_GraphBuilder::insertGlobalValues could not find row "
181 << globalRow <<
" in the graph. Super bummer man. Hope you figure it out.");
183 std::set<GlobalOrdinal>& cols = * (iter->second);
185 for (
typename Teuchos::ArrayView<const GlobalOrdinal>::size_type i = 0;
186 i < indices.size (); ++i) {
187 cols.insert (indices[i]);
191 if (row_length > max_row_length_) {
192 max_row_length_ = row_length;
196 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
198 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
199 sumIntoGlobalValues (GlobalOrdinal globalRow,
200 const Teuchos::ArrayView<const GlobalOrdinal> &indices,
201 const Teuchos::ArrayView<const Scalar> &values)
203 insertGlobalValues (globalRow, indices, values);
206 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
207 std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>&
208 CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::get_graph ()
213 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
215 insert_matrix_locations (CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>& graphbuilder,
216 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C)
218 global_size_t max_row_length = graphbuilder.get_max_row_length();
219 if (max_row_length < 1)
return;
221 Teuchos::Array<GlobalOrdinal> indices(max_row_length);
222 Teuchos::Array<Scalar> zeros(max_row_length, Teuchos::ScalarTraits<Scalar>::zero());
224 typedef std::map<GlobalOrdinal,std::set<GlobalOrdinal>*> Graph;
225 typedef typename Graph::iterator GraphIter;
226 Graph& graph = graphbuilder.get_graph ();
228 const GraphIter iter_end = graph.end ();
229 for (GraphIter iter = graph.begin (); iter != iter_end; ++iter) {
230 const GlobalOrdinal row = iter->first;
231 const std::set<GlobalOrdinal>& cols = * (iter->second);
233 const size_t num_entries = std::copy (cols.begin (), cols.end (), indices.begin ()) - indices.begin ();
235 C.insertGlobalValues (row, indices (0, num_entries), zeros (0, num_entries));
247 #define TPETRA_CRSMATRIXSTRUCT_INSTANT(SCALAR,LO,GO,NODE) \
249 template class CrsMatrixStruct< SCALAR , LO , GO , NODE >;
251 #define TPETRA_CRSWRAPPER_INSTANT(SCALAR,LO,GO,NODE) \
253 template class CrsWrapper< SCALAR , LO , GO , NODE >;
255 #define TPETRA_CRSWRAPPER_CRSMATRIX_INSTANT(SCALAR,LO,GO,NODE) \
257 template class CrsWrapper_CrsMatrix< SCALAR , LO , GO , NODE >;
259 #define TPETRA_CRSWRAPPER_GRAPHBUILDER_INSTANT(SCALAR,LO,GO,NODE) \
261 template class CrsWrapper_GraphBuilder< SCALAR , LO , GO , NODE >;
263 #endif // TPETRA_MMHELPERS_DEF_HPP
size_t global_size_t
Global size_t object.
Declaration of Tpetra::MMMultiMultiply and nonmember constructors.