Tpetra parallel linear algebra  Version of the Day
Tpetra_RowMatrix_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 #ifndef TPETRA_ROWMATRIX_DECL_HPP
43 #define TPETRA_ROWMATRIX_DECL_HPP
44 
45 #include <Teuchos_Describable.hpp>
46 #include <Kokkos_DefaultNode.hpp>
47 
48 #include "Tpetra_ConfigDefs.hpp"
49 #include "Tpetra_Vector_decl.hpp"
50 #include "Tpetra_Operator.hpp"
51 #include "Tpetra_RowGraph.hpp"
52 #include "Tpetra_Packable.hpp"
53 #include "Tpetra_SrcDistObject.hpp"
54 
55 namespace Tpetra {
56  //
57  // Forward declarations. The "doxygen" bit simply tells Doxygen
58  // (our automatic documentation generation system) to skip forward
59  // declarations.
60  //
61 #ifndef DOXYGEN_SHOULD_SKIP_THIS
62  template<class LocalOrdinal, class GlobalOrdinal, class Node>
63  class Map;
64 #endif // DOXYGEN_SHOULD_SKIP_THIS
65 
91  template <class Scalar = Details::DefaultTypes::scalar_type,
92  class LocalOrdinal = Details::DefaultTypes::local_ordinal_type,
93  class GlobalOrdinal = Details::DefaultTypes::global_ordinal_type,
95  class RowMatrix :
96  virtual public Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
97  virtual public SrcDistObject,
98  public Packable<char, LocalOrdinal> {
99  public:
101 
102 
104  typedef Scalar scalar_type;
106  typedef LocalOrdinal local_ordinal_type;
108  typedef GlobalOrdinal global_ordinal_type;
110  typedef Node node_type;
111 
118 
120 
122 
124  virtual ~RowMatrix();
125 
127 
129 
131  virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const = 0;
132 
134  virtual Teuchos::RCP<Node> getNode() const = 0;
135 
137  virtual Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > getRowMap() const = 0;
138 
140  virtual Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > getColMap() const = 0;
141 
143  virtual Teuchos::RCP<const RowGraph<LocalOrdinal,GlobalOrdinal,Node> > getGraph() const = 0;
144 
146  virtual global_size_t getGlobalNumRows() const = 0;
147 
149  virtual global_size_t getGlobalNumCols() const = 0;
150 
152  virtual size_t getNodeNumRows() const = 0;
153 
159  virtual size_t getNodeNumCols() const = 0;
160 
162  virtual GlobalOrdinal getIndexBase() const = 0;
163 
165  virtual global_size_t getGlobalNumEntries() const = 0;
166 
168  virtual size_t getNodeNumEntries() const = 0;
169 
179  virtual size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const = 0;
180 
190  virtual size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const = 0;
191 
193  virtual global_size_t getGlobalNumDiags() const = 0;
194 
196  virtual size_t getNodeNumDiags() const = 0;
197 
199  virtual size_t getGlobalMaxNumRowEntries() const = 0;
200 
202  virtual size_t getNodeMaxNumRowEntries() const = 0;
203 
205  virtual bool hasColMap() const = 0;
206 
208  virtual bool isLowerTriangular() const = 0;
209 
211  virtual bool isUpperTriangular() const = 0;
212 
222  virtual bool isLocallyIndexed() const = 0;
223 
233  virtual bool isGloballyIndexed() const = 0;
234 
236  virtual bool isFillComplete() const = 0;
237 
239  virtual bool supportsRowViews() const = 0;
240 
242 
244 
265  virtual void
266  getGlobalRowCopy (GlobalOrdinal GlobalRow,
267  const Teuchos::ArrayView<GlobalOrdinal> &Indices,
268  const Teuchos::ArrayView<Scalar> &Values,
269  size_t &NumEntries) const = 0;
270 
291  virtual void
292  getLocalRowCopy (LocalOrdinal LocalRow,
293  const Teuchos::ArrayView<LocalOrdinal> &Indices,
294  const Teuchos::ArrayView<Scalar> &Values,
295  size_t &NumEntries) const = 0;
296 
321  virtual void
322  getGlobalRowView (GlobalOrdinal GlobalRow,
323  ArrayView<const GlobalOrdinal> &indices,
324  ArrayView<const Scalar> &values) const = 0;
325 
350  virtual void
351  getLocalRowView (LocalOrdinal LocalRow,
352  ArrayView<const LocalOrdinal> &indices,
353  ArrayView<const Scalar> &values) const = 0;
354 
367 
369 
371 
378 
385 
394  virtual mag_type getFrobeniusNorm() const = 0;
395 
447  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
448  add (const Scalar& alpha,
450  const Scalar& beta,
451  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
452  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
453  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
455 
457  private:
458  bool
459  packRow (char* const numEntOut,
460  char* const valOut,
461  char* const indOut,
462  const size_t numEnt,
463  const LocalOrdinal lclRow) const;
464 
465  // TODO (mfh 25 Jan 2015) Could just make this "protected" and let
466  // CrsMatrix use it, since it's exactly the same there.
467  void
468  allocatePackSpace (Teuchos::Array<char>& exports,
469  size_t& totalNumEntries,
470  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs) const;
471 
476  void
477  packImpl (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
478  Teuchos::Array<char>& exports,
479  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
480  size_t& constantNumPackets,
481  Distributor& distor) const;
482 
483 
484  public:
493  virtual void
494  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
495  Teuchos::Array<char>& exports,
496  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
497  size_t& constantNumPackets,
498  Distributor& distor) const;
500  }; // class RowMatrix
501 } // namespace Tpetra
502 
503 #endif // TPETRA_ROWMATRIX_DECL_HPP
504 
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const =0
The communicator over which this matrix is distributed.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const =0
The Map that describes the distribution of columns over processes.
virtual void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const =0
Get a constant, nonpersisting, locally indexed view of the given row of the matrix.
virtual global_size_t getGlobalNumDiags() const =0
The number of global diagonal entries, based on global row/column index comparisons.
virtual void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const =0
Get a constant, nonpersisting, globally indexed view of the given row of the matrix.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
virtual bool isLocallyIndexed() const =0
Whether matrix indices are locally indexed.
virtual size_t getNodeMaxNumRowEntries() const =0
The maximum number of entries across all rows/columns on this node.
virtual global_size_t getGlobalNumCols() const =0
The global number of columns of this matrix.
virtual GlobalOrdinal getIndexBase() const =0
The index base for global indices in this matrix.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
Node node_type
The Kokkos Node type.
virtual size_t getNodeNumRows() const =0
The number of rows owned by the calling process.
virtual size_t getNodeNumCols() const =0
The number of columns needed to apply the forward operator on this node.
virtual void getLocalRowCopy(LocalOrdinal LocalRow, const Teuchos::ArrayView< LocalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const =0
Get a copy of the given local row&#39;s entries.
virtual bool isLowerTriangular() const =0
Whether this matrix is lower triangular.
Declaration of the Tpetra::Vector class.
virtual size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const =0
The current number of entries on the calling process in the specified local row.
Abstract base class for sources of an Import or Export.
virtual Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const =0
The RowGraph associated with this matrix.
LocalOrdinal local_ordinal_type
The type of local indices.
virtual void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, Node::classic > &diag) const =0
Get a copy of the diagonal entries, distributed by the row Map.
int local_ordinal_type
Default value of LocalOrdinal template parameter.
virtual ~RowMatrix()
Destructor (virtual for memory safety of derived classes).
virtual bool isUpperTriangular() const =0
Whether this matrix is upper triangular.
size_t global_size_t
Global size_t object.
virtual void getGlobalRowCopy(GlobalOrdinal GlobalRow, const Teuchos::ArrayView< GlobalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const =0
Get a copy of the given global row&#39;s entries.
virtual size_t getGlobalMaxNumRowEntries() const =0
The maximum number of entries across all rows/columns on all nodes.
Abstract interface for operators (e.g., matrices and preconditioners).
GlobalOrdinal global_ordinal_type
The type of global indices.
virtual size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const =0
The current number of entries on the calling process in the specified global row. ...
Sets up and executes a communication plan for a Tpetra DistObject.
virtual void pack(const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< char > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor) const
Pack this object&#39;s data for an Import or Export.
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::mag_type mag_type
Type of a norm result.
virtual void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, Node::classic > &x)=0
Scale the RowMatrix on the right with the given Vector x.
Abstract base class for objects that can be the source of an Import or Export operation.
double scalar_type
Default value of Scalar template parameter.
virtual Teuchos::RCP< Node > getNode() const =0
The Kokkos Node instance.
virtual bool isFillComplete() const =0
Whether fillComplete() has been called.
virtual global_size_t getGlobalNumEntries() const =0
The global number of stored (structurally nonzero) entries.
virtual Teuchos::RCP< RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > add(const Scalar &alpha, const RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Return a new RowMatrix which is the result of beta*this + alpha*A.
Scalar scalar_type
The type of the entries in the sparse matrix.
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
Describes a parallel distribution of objects over processes.
virtual bool supportsRowViews() const =0
Whether this object implements getLocalRowView() and getGlobalRowView().
A read-only, row-oriented interface to a sparse matrix.
A distributed dense vector.
virtual size_t getNodeNumEntries() const =0
The local number of stored (structurally nonzero) entries.
virtual bool isGloballyIndexed() const =0
Whether matrix indices are globally indexed.
Abstract base class for sources of an Import or Export, that also know how to pack themselves...
Abstract base class for objects that can be the source of an Import or Export operation, and that also know how to pack their data to send to the target object.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const =0
The Map that describes the distribution of rows over processes.
virtual bool hasColMap() const =0
Whether this matrix has a well-defined column map.
virtual size_t getNodeNumDiags() const =0
The number of local diagonal entries, based on global row/column index comparisons.
virtual global_size_t getGlobalNumRows() const =0
The global number of rows of this matrix.
virtual void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, Node::classic > &x)=0
Scale the RowMatrix on the left with the given Vector x.
virtual mag_type getFrobeniusNorm() const =0
The Frobenius norm of the matrix.