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 "Tpetra_ConfigDefs.hpp"
46 #include "Tpetra_RowMatrix_fwd.hpp"
47 #include "Tpetra_Vector_fwd.hpp"
48 #include "Tpetra_Operator.hpp"
49 #include "Tpetra_RowGraph_fwd.hpp"
50 #include "Tpetra_Packable.hpp"
51 #include "Tpetra_SrcDistObject.hpp"
52 #include "Teuchos_Describable.hpp"
53 #include "Kokkos_ArithTraits.hpp"
54 
55 namespace Tpetra {
81  template <class Scalar,
82  class LocalOrdinal,
83  class GlobalOrdinal,
84  class Node>
85  class RowMatrix :
86  virtual public Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
87  virtual public SrcDistObject,
88  public Packable<char, LocalOrdinal> {
89  public:
91 
92 
94  typedef Scalar scalar_type;
96  typedef LocalOrdinal local_ordinal_type;
98  typedef GlobalOrdinal global_ordinal_type;
100  typedef Node node_type;
101 
111  using impl_scalar_type = typename Kokkos::ArithTraits<Scalar>::val_type;
117  using mag_type = typename Kokkos::ArithTraits<Scalar>::mag_type;
118 
119  typedef typename
120  Kokkos::View<impl_scalar_type*, typename Node::device_type>::const_type
121  values_device_view_type;
122  typedef typename values_device_view_type::HostMirror::const_type
123  values_host_view_type;
124  typedef typename values_device_view_type::HostMirror
125  nonconst_values_host_view_type;
126 
127  typedef typename
128  Kokkos::View<LocalOrdinal *, typename Node::device_type>::const_type
129  local_inds_device_view_type;
130  typedef typename local_inds_device_view_type::HostMirror::const_type
131  local_inds_host_view_type;
132  typedef typename local_inds_device_view_type::HostMirror
133  nonconst_local_inds_host_view_type;
134 
135  typedef typename
136  Kokkos::View<GlobalOrdinal *, typename Node::device_type>::const_type
137  global_inds_device_view_type;
138  typedef typename global_inds_device_view_type::HostMirror::const_type
139  global_inds_host_view_type;
140  typedef typename global_inds_device_view_type::HostMirror
141  nonconst_global_inds_host_view_type;
142 
143 
144  typedef typename
145  Kokkos::View<const size_t*, typename Node::device_type>::const_type
146  row_ptrs_device_view_type;
147  typedef typename row_ptrs_device_view_type::HostMirror::const_type
148  row_ptrs_host_view_type;
149 
150 
151 
153 
155 
157  virtual ~RowMatrix();
158 
160 
162 
164  virtual Teuchos::RCP<const Teuchos::Comm<int> > getComm() const = 0;
165 
166 
168  virtual Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > getRowMap() const = 0;
169 
171  virtual Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > getColMap() const = 0;
172 
174  virtual Teuchos::RCP<const RowGraph<LocalOrdinal,GlobalOrdinal,Node> > getGraph() const = 0;
175 
177  virtual global_size_t getGlobalNumRows() const = 0;
178 
180  virtual global_size_t getGlobalNumCols() const = 0;
181 
183  virtual size_t getNodeNumRows() const = 0;
184 
190  virtual size_t getNodeNumCols() const = 0;
191 
193  virtual GlobalOrdinal getIndexBase() const = 0;
194 
196  virtual global_size_t getGlobalNumEntries() const = 0;
197 
199  virtual size_t getNodeNumEntries() const = 0;
200 
210  virtual size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const = 0;
211 
221  virtual size_t getNumEntriesInLocalRow (LocalOrdinal localRow) const = 0;
222 
231  virtual size_t getGlobalMaxNumRowEntries () const = 0;
232 
241  virtual size_t getNodeMaxNumRowEntries () const = 0;
242 
244  virtual bool hasColMap () const = 0;
245 
255  virtual bool isLocallyIndexed() const = 0;
256 
266  virtual bool isGloballyIndexed() const = 0;
267 
269  virtual bool isFillComplete() const = 0;
270 
272  virtual bool supportsRowViews() const = 0;
273 
274 
276 
278 
299  virtual void
300  getGlobalRowCopy (GlobalOrdinal GlobalRow,
301  nonconst_global_inds_host_view_type &Indices,
302  nonconst_values_host_view_type &Values,
303  size_t& NumEntries) const = 0;
304 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
305  virtual void
306  getGlobalRowCopy (GlobalOrdinal GlobalRow,
307  const Teuchos::ArrayView<GlobalOrdinal> &Indices,
308  const Teuchos::ArrayView<Scalar> &Values,
309  size_t &NumEntries) const = 0;
310 #endif
311  virtual void
332  getLocalRowCopy (LocalOrdinal LocalRow,
333  nonconst_local_inds_host_view_type &Indices,
334  nonconst_values_host_view_type &Values,
335  size_t& NumEntries) const = 0;
336 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
337  virtual void
338  getLocalRowCopy (LocalOrdinal LocalRow,
339  const Teuchos::ArrayView<LocalOrdinal> &Indices,
340  const Teuchos::ArrayView<Scalar> &Values,
341  size_t &NumEntries) const = 0;
342 #endif
343  virtual void
368  getGlobalRowView (GlobalOrdinal GlobalRow,
369  global_inds_host_view_type &indices,
370  values_host_view_type &values) const = 0;
371 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
372  virtual void
373  getGlobalRowView (GlobalOrdinal GlobalRow,
374  Teuchos::ArrayView<const GlobalOrdinal> &indices,
375  Teuchos::ArrayView<const Scalar> &values) const = 0;
376 #endif
377 
402  virtual void
403  getLocalRowView (LocalOrdinal LocalRow,
404  local_inds_host_view_type & indices,
405  values_host_view_type & values) const = 0;
406 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
407  virtual void
408  getLocalRowView (LocalOrdinal LocalRow,
409  Teuchos::ArrayView<const LocalOrdinal>& indices,
410  Teuchos::ArrayView<const Scalar>& values) const = 0;
411 
438  virtual LocalOrdinal
439  getLocalRowViewRaw (const LocalOrdinal lclRow,
440  LocalOrdinal& numEnt,
441  const LocalOrdinal*& lclColInds,
442  const Scalar*& vals) const;
443 #endif // TPETRA_ENABLE_DEPRECATED_CODE
444 
457 
459 
461 
467 
473 
482  virtual mag_type getFrobeniusNorm() const = 0;
483 
535  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
536  add (const Scalar& alpha,
538  const Scalar& beta,
539  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
540  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
541  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
543 
545  private:
546  bool
547  packRow (char* const numEntOut,
548  char* const valOut,
549  char* const indOut,
550  const size_t numEnt,
551  const LocalOrdinal lclRow) const;
552 
553  // TODO (mfh 25 Jan 2015) Could just make this "protected" and let
554  // CrsMatrix use it, since it's exactly the same there.
555  void
556  allocatePackSpace (Teuchos::Array<char>& exports,
557  size_t& totalNumEntries,
558  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs) const;
559 
564  void
565  packImpl (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
566  Teuchos::Array<char>& exports,
567  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
568  size_t& constantNumPackets) const;
569 
570 
571  public:
580  virtual void
581  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
582  Teuchos::Array<char>& exports,
583  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
584  size_t& constantNumPackets) const;
586  }; // class RowMatrix
587 } // namespace Tpetra
588 
589 #endif // TPETRA_ROWMATRIX_DECL_HPP
590 
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.
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
Maximum number of entries in any row of the matrix, on this process.
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.
Node node_type
The Kokkos Node type.
virtual size_t getNodeNumRows() const =0
The number of rows owned by the calling process.
virtual void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)=0
Scale the matrix on the right with the given Vector.
virtual size_t getNodeNumCols() const =0
The number of columns needed to apply the forward operator on this node.
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.
Forward declaration of Tpetra::RowMatrix.
virtual size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const =0
The current number of entries on the calling process in the specified local row.
virtual void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)=0
Scale the matrix on the left with the given Vector.
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 ~RowMatrix()
Destructor (virtual for memory safety of derived classes).
Forward declaration of Tpetra::RowGraph.
typename Kokkos::ArithTraits< SC >::val_type impl_scalar_type
The type used internally in place of Scalar.
size_t global_size_t
Global size_t object.
virtual size_t getGlobalMaxNumRowEntries() const =0
Maximum number of entries in any row of the matrix, over all processes.
Abstract interface for operators (e.g., matrices and preconditioners).
virtual void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const =0
Get a copy of the given global row&#39;s entries.
typename Kokkos::ArithTraits< SC >::mag_type mag_type
Type of a norm result.
virtual void pack(const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< char > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets) const
Pack this object&#39;s data for an Import or Export.
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. ...
Abstract base class for objects that can be the source of an Import or Export operation.
Forward declaration of Tpetra::Vector.
virtual void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const =0
Get a copy of the diagonal entries, distributed by the row Map.
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.
Scalar scalar_type
The type of the entries in the sparse matrix.
A parallel distribution of indices 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 void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const =0
Get a constant, nonpersisting, globally indexed view of the given row of the matrix.
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.
virtual void getLocalRowCopy(LocalOrdinal LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const =0
Get a copy of the given local row&#39;s entries.
Declaration of Tpetra::Packable.
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 void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const =0
Get a constant, nonpersisting, locally indexed view of the given row of the matrix.
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 global_size_t getGlobalNumRows() const =0
The global number of rows of this matrix.
virtual mag_type getFrobeniusNorm() const =0
The Frobenius norm of the matrix.