Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TpetraExt_MMHelpers_decl.hpp
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_ConfigDefs.hpp"
47 #include "Teuchos_Array.hpp"
48 #include <Kokkos_DefaultNode.hpp>
49 #include <Kokkos_DefaultKernels.hpp>
50 #include <set>
51 #include <map>
52 
53 
59 namespace Tpetra {
60 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61  // forward declaration
62 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
63 class CrsMatrix;
64 
65 template <class LocalOrdinal, class GlobalOrdinal, class Node>
66 class Map;
67 #endif
68 //struct that holds views of the contents of a CrsMatrix. These
69 //contents may be a mixture of local and remote rows of the
70 //actual matrix.
71 template <class Scalar,
72  class LocalOrdinal=int,
73  class GlobalOrdinal=LocalOrdinal,
74  class Node=Kokkos::DefaultNode::DefaultNodeType,
75  class SpMatOps= typename Kokkos::DefaultKernels<Scalar, LocalOrdinal, Node>::SparseOps >
76 class CrsMatrixStruct {
77 public:
78  CrsMatrixStruct();
79 
80  virtual ~CrsMatrixStruct();
81 
82  void deleteContents();
83 
84  //The maximum number of row entries a.k.a. the longest of the indice arrays.
85  typename Array<ArrayView<const LocalOrdinal> >::size_type maxNumRowEntries;
86 
88  size_t numRows;
90  Teuchos::Array<size_t> numEntriesPerRow;
92  Teuchos::Array<Teuchos::ArrayView<const LocalOrdinal> > indices;
94  Teuchos::Array<Teuchos::ArrayView<const Scalar> > values;
96  Teuchos::Array<bool> remote;
98  global_size_t numRemote;
100  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > origRowMap;
102  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > rowMap;
104  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > colMap;
106  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > domainMap;
108  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > importColMap;
110  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps> > importMatrix;
111 };
112 
113 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
114 int dumpCrsMatrixStruct(const CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps >& M);
115 
116 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
117 class CrsWrapper {
118  public:
119  virtual ~CrsWrapper(){}
120 
121  virtual Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const = 0;
122 
123  virtual bool isFillComplete() = 0;
124 
125  virtual void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values) = 0;
126 
127  virtual void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values) = 0;
128 };
129 
130 template <class Scalar,
131  class LocalOrdinal=int,
132  class GlobalOrdinal=LocalOrdinal,
133  class Node=Kokkos::DefaultNode::DefaultNodeType,
134  class SpMatOps= typename Kokkos::DefaultKernels<Scalar, LocalOrdinal, Node>::SparseOps >
135 class CrsWrapper_CrsMatrix : public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>{
136  public:
137  CrsWrapper_CrsMatrix(CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps >& crsmatrix);
138  virtual ~CrsWrapper_CrsMatrix();
139 
140  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const;
141 
142  bool isFillComplete();
143 
144  void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
145  void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
146 
147  private:
148  CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>& crsmat_;
149 };
150 
151 template<class Scalar,
152  class LocalOrdinal=int,
153  class GlobalOrdinal=LocalOrdinal,
154  class Node=Kokkos::DefaultNode::DefaultNodeType>
155 class CrsWrapper_GraphBuilder : public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node>{
156  public:
157  CrsWrapper_GraphBuilder(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map);
158  virtual ~CrsWrapper_GraphBuilder();
159 
160  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {return rowmap_; }
161 
162  bool isFillComplete();
163 
164  void insertGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
165  void sumIntoGlobalValues(GlobalOrdinal globalRow, const Teuchos::ArrayView<const GlobalOrdinal> &indices, const Teuchos::ArrayView<const Scalar> &values);
166 
167  std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>& get_graph();
168 
169  size_t get_max_row_length() { return max_row_length_; }
170 
171  private:
172  std::map<GlobalOrdinal,std::set<GlobalOrdinal>*> graph_;
173  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowmap_;
174  global_size_t max_row_length_;
175 };
176 
177 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
178 void insert_matrix_locations(CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>& graphbuilder,
179  CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>& C);
180 
181 
182 
183 }
184 #endif // TPETRA_MMHELPERS_DECL_HPP
185 
size_t global_size_t
Global size_t object.