Tpetra parallel linear algebra  Version of the Day
TpetraExt_MMHelpers_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 
43 #ifndef TPETRA_MMHELPERS_DECL_HPP
44 #define TPETRA_MMHELPERS_DECL_HPP
45 
46 #include <Tpetra_CrsMatrix.hpp>
47 #include <Teuchos_Array.hpp>
48 #include <map>
49 #include <set>
50 
56 
57 namespace Tpetra {
58 
64 template <class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
66  class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
69 public:
72 
73  CrsMatrixStruct ();
74 
75  virtual ~CrsMatrixStruct ();
76 
77  void deleteContents ();
78 
80  Teuchos::RCP<const map_type> origRowMap;
82  Teuchos::RCP<const map_type> rowMap;
84  Teuchos::RCP<const map_type> colMap;
86  Teuchos::RCP<const map_type> domainMap;
88  Teuchos::RCP<const map_type> importColMap;
90  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > importMatrix;
92  Teuchos::RCP<const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > origMatrix;
93 
94 };
95 
96 
97 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
98 int
100 
101 
102 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
103 class CrsWrapper {
104 public:
106 
107  virtual ~CrsWrapper () {}
108  virtual Teuchos::RCP<const map_type> getRowMap () const = 0;
109  virtual bool isFillComplete () = 0;
110 
111  virtual void
112  insertGlobalValues (GlobalOrdinal globalRow,
113  const Teuchos::ArrayView<const GlobalOrdinal> &indices,
114  const Teuchos::ArrayView<const Scalar> &values) = 0;
115  virtual void
116  sumIntoGlobalValues (GlobalOrdinal globalRow,
117  const Teuchos::ArrayView<const GlobalOrdinal> &indices,
118  const Teuchos::ArrayView<const Scalar> &values) = 0;
119 };
120 
121 template <class Scalar = CrsMatrix<>::scalar_type,
122  class LocalOrdinal = typename CrsMatrix<Scalar>::local_ordinal_type,
123  class GlobalOrdinal = typename CrsMatrix<Scalar, LocalOrdinal>::global_ordinal_type,
125 class CrsWrapper_CrsMatrix :
126  public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
127 public:
128  typedef Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
129  typedef CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> crs_matrix_type;
130 
131  CrsWrapper_CrsMatrix (crs_matrix_type& crsmatrix);
132  virtual ~CrsWrapper_CrsMatrix ();
133  Teuchos::RCP<const map_type> getRowMap () const;
134 
135  bool isFillComplete ();
136 
137  void
138  insertGlobalValues (GlobalOrdinal globalRow,
139  const Teuchos::ArrayView<const GlobalOrdinal> &indices,
140  const Teuchos::ArrayView<const Scalar> &values);
141  void
142  sumIntoGlobalValues (GlobalOrdinal globalRow,
143  const Teuchos::ArrayView<const GlobalOrdinal> &indices,
144  const Teuchos::ArrayView<const Scalar> &values);
145 private:
146  crs_matrix_type& crsmat_;
147 };
148 
149 
150 template <class Scalar = CrsMatrix<>::scalar_type,
151  class LocalOrdinal = typename CrsMatrix<Scalar>::local_ordinal_type,
152  class GlobalOrdinal =
154  class Node =
156 class CrsWrapper_GraphBuilder :
157  public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
158 public:
159  typedef Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
160 
161  CrsWrapper_GraphBuilder (const Teuchos::RCP<const map_type>& map);
162  virtual ~CrsWrapper_GraphBuilder ();
163 
164  Teuchos::RCP<const map_type> getRowMap () const {
165  return rowmap_;
166  }
167 
168  bool isFillComplete ();
169  void
170  insertGlobalValues (GlobalOrdinal globalRow,
171  const Teuchos::ArrayView<const GlobalOrdinal> &indices,
172  const Teuchos::ArrayView<const Scalar> &values);
173  void
174  sumIntoGlobalValues (GlobalOrdinal globalRow,
175  const Teuchos::ArrayView<const GlobalOrdinal> &indices,
176  const Teuchos::ArrayView<const Scalar> &values);
177 
178  std::map<GlobalOrdinal, std::set<GlobalOrdinal>*>& get_graph ();
179 
180  size_t get_max_row_length () {
181  return max_row_length_;
182  }
183 
184  private:
185  std::map<GlobalOrdinal, std::set<GlobalOrdinal>*> graph_;
186  const Teuchos::RCP<const map_type>& rowmap_;
187  global_size_t max_row_length_;
188 };
189 
190 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
191 void
192 insert_matrix_locations (CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>& graphbuilder,
193  CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C);
194 
195 } // namespace Tpetra
196 #endif // TPETRA_MMHELPERS_DECL_HPP
197 
Teuchos::RCP< const map_type > importColMap
Colmap garnered as a result of the import.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
LocalOrdinal local_ordinal_type
This class&#39; second template parameter; the type of local indices.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
Teuchos::RCP< const map_type > domainMap
Domain map for original matrix.
GlobalOrdinal global_ordinal_type
This class&#39; third template parameter; the type of global indices.
Teuchos::RCP< const map_type > colMap
Col map for the original version of the matrix.
Node node_type
This class&#39; fourth template parameter; the Kokkos device type.
Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > origMatrix
The original matrix.
int local_ordinal_type
Default value of LocalOrdinal template parameter.
size_t global_size_t
Global size_t object.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > importMatrix
The imported matrix.
double scalar_type
Default value of Scalar template parameter.
Describes a parallel distribution of objects over processes.
Teuchos::RCP< const map_type > rowMap
Desired row map for "imported" version of the matrix.
Struct that holds views of the contents of a CrsMatrix.
Teuchos::RCP< const map_type > origRowMap
Original row map of matrix.