Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 = ::Tpetra::Details::DefaultTypes::scalar_type,
123  class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::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 template <class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
151  class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
153 class CrsWrapper_GraphBuilder :
154  public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
155 public:
156  typedef Map<LocalOrdinal, GlobalOrdinal, Node> map_type;
157 
158  CrsWrapper_GraphBuilder (const Teuchos::RCP<const map_type>& map);
159  virtual ~CrsWrapper_GraphBuilder ();
160 
161  Teuchos::RCP<const map_type> getRowMap () const {
162  return rowmap_;
163  }
164 
165  bool isFillComplete ();
166  void
167  insertGlobalValues (GlobalOrdinal globalRow,
168  const Teuchos::ArrayView<const GlobalOrdinal> &indices,
169  const Teuchos::ArrayView<const Scalar> &values);
170  void
171  sumIntoGlobalValues (GlobalOrdinal globalRow,
172  const Teuchos::ArrayView<const GlobalOrdinal> &indices,
173  const Teuchos::ArrayView<const Scalar> &values);
174 
175  std::map<GlobalOrdinal, std::set<GlobalOrdinal>*>& get_graph ();
176 
177  size_t get_max_row_length () {
178  return max_row_length_;
179  }
180 
181  private:
182  std::map<GlobalOrdinal, std::set<GlobalOrdinal>*> graph_;
183  const Teuchos::RCP<const map_type>& rowmap_;
184  global_size_t max_row_length_;
185 };
186 
187 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
188 void
189 insert_matrix_locations (CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>& graphbuilder,
190  CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C);
191 
192 } // namespace Tpetra
193 #endif // TPETRA_MMHELPERS_DECL_HPP
194 
Teuchos::RCP< const map_type > importColMap
Colmap garnered as a result of the import.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Teuchos::RCP< const map_type > domainMap
Domain map for original matrix.
Teuchos::RCP< const map_type > colMap
Col map for the original version of the matrix.
Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > origMatrix
The original matrix.
int local_ordinal_type
Default value of Scalar template parameter.
size_t global_size_t
Global size_t object.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > importMatrix
The imported matrix.
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type
Default value of Node template parameter.
A parallel distribution of indices over processes.
Teuchos::RCP< const map_type > rowMap
Desired row map for &quot;imported&quot; 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.