Tpetra parallel linear algebra  Version of the Day
Tpetra_CrsMatrix_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 #ifndef TPETRA_CRSMATRIX_DECL_HPP
43 #define TPETRA_CRSMATRIX_DECL_HPP
44 
52 
53 #include "Tpetra_ConfigDefs.hpp"
54 #include "Tpetra_RowMatrix_decl.hpp"
55 #include "Tpetra_Exceptions.hpp"
56 #include "Tpetra_DistObject.hpp"
57 #include "Tpetra_CrsGraph.hpp"
58 #include "Tpetra_Vector.hpp"
59 
60 #include "KokkosCompat_ClassicNodeAPI_Wrapper.hpp"
61 // localMultiply is templated on DomainScalar and RangeScalar, so we
62 // have to include this header file here, rather than in the _def
63 // header file, so that we can get KokkosSparse::spmv.
64 #include "Kokkos_Sparse.hpp"
65 // localGaussSeidel and reorderedLocalGaussSeidel are templated on
66 // DomainScalar and RangeScalar, so we have to include this header
67 // file here, rather than in the _def header file, so that we can get
68 // the interfaces to the corresponding local computational kernels.
69 #include "Kokkos_Sparse_impl_sor.hpp"
70 
71 namespace Tpetra {
185  template <class Scalar = Details::DefaultTypes::scalar_type,
186  class LocalOrdinal = Details::DefaultTypes::local_ordinal_type,
187  class GlobalOrdinal = Details::DefaultTypes::global_ordinal_type,
189  const bool classic = Node::classic>
190  class CrsMatrix :
191  public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
192  public DistObject<char, LocalOrdinal, GlobalOrdinal, Node, classic>
193  {
194  public:
196 
197 
200  typedef Scalar scalar_type;
210  typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
212  typedef LocalOrdinal local_ordinal_type;
214  typedef GlobalOrdinal global_ordinal_type;
216  typedef Node node_type;
217 
219  typedef typename Node::device_type device_type;
221  typedef typename device_type::execution_space execution_space;
222 
228  typedef typename Kokkos::Details::ArithTraits<impl_scalar_type>::mag_type mag_type;
229 
232 
235 
238 
241 
244 
247  typedef Kokkos::CrsMatrix<impl_scalar_type, LocalOrdinal, execution_space, void,
248  typename local_graph_type::size_type> local_matrix_type;
249 
251  typedef typename local_matrix_type::row_map_type t_RowPtrs TPETRA_DEPRECATED;
253  typedef typename local_matrix_type::row_map_type::non_const_type t_RowPtrsNC TPETRA_DEPRECATED;
255  typedef typename local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED;
257  typedef typename local_matrix_type::values_type t_ValuesType TPETRA_DEPRECATED;
258 
260  typedef local_matrix_type k_local_matrix_type TPETRA_DEPRECATED;
261 
263 
265 
283  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
284  size_t maxNumEntriesPerRow,
285  ProfileType pftype = DynamicProfile,
286  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
287 
305  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
306  const Teuchos::ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
307  ProfileType pftype = DynamicProfile,
308  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
309 
332  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
333  const Teuchos::RCP<const map_type>& colMap,
334  size_t maxNumEntriesPerRow,
335  ProfileType pftype = DynamicProfile,
336  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
337 
360  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
361  const Teuchos::RCP<const map_type>& colMap,
362  const Teuchos::ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
363  ProfileType pftype = DynamicProfile,
364  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
365 
390  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
391  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
392 
416  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
417  const Teuchos::RCP<const map_type>& colMap,
418  const typename local_matrix_type::row_map_type& rowPointers,
419  const typename local_graph_type::entries_type::non_const_type& columnIndices,
420  const typename local_matrix_type::values_type& values,
421  const Teuchos::RCP<Teuchos::ParameterList>& params = null);
422 
446  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
447  const Teuchos::RCP<const map_type>& colMap,
448  const Teuchos::ArrayRCP<size_t>& rowPointers,
449  const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
450  const Teuchos::ArrayRCP<Scalar>& values,
451  const Teuchos::RCP<ParameterList>& params = null);
452 
473  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
474  const Teuchos::RCP<const map_type>& colMap,
475  const local_matrix_type& lclMatrix,
476  const Teuchos::RCP<Teuchos::ParameterList>& params = null);
477 
478  // This friend declaration makes the clone() method work.
479  template <class S2, class LO2, class GO2, class N2, const bool isClassic>
480  friend class CrsMatrix;
481 
506  template <class Node2>
507  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node2, Node2::classic> >
508  clone (const Teuchos::RCP<Node2>& node2,
509  const Teuchos::RCP<Teuchos::ParameterList>& params = null) const
510  {
511  using Teuchos::ArrayRCP;
512  using Teuchos::null;
513  using Teuchos::ParameterList;
514  using Teuchos::RCP;
515  using Teuchos::rcp;
516  using Teuchos::sublist;
519  const char tfecfFuncName[] = "clone";
520 
521  // Get parameter values. Set them initially to their default values.
522  bool fillCompleteClone = true;
523  bool useLocalIndices = this->hasColMap ();
524  ProfileType pftype = StaticProfile;
525  if (! params.is_null ()) {
526  fillCompleteClone = params->get ("fillComplete clone", fillCompleteClone);
527  useLocalIndices = params->get ("Locally indexed clone", useLocalIndices);
528 
529  bool staticProfileClone = true;
530  staticProfileClone = params->get ("Static profile clone", staticProfileClone);
531  pftype = staticProfileClone ? StaticProfile : DynamicProfile;
532  }
533 
534  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
535  ! this->hasColMap () && useLocalIndices, std::runtime_error,
536  ": You requested that the returned clone have local indices, but the "
537  "the source matrix does not have a column Map yet.");
538 
539  RCP<const Map2> clonedRowMap = this->getRowMap ()->template clone<Node2> (node2);
540 
541  // Get an upper bound on the number of entries per row.
542  RCP<CrsMatrix2> clonedMatrix;
543  ArrayRCP<const size_t> numEntriesPerRow;
544  size_t numEntriesForAll = 0;
545  bool boundSameForAllLocalRows = false;
546  staticGraph_->getNumEntriesPerLocalRowUpperBound (numEntriesPerRow,
547  numEntriesForAll,
548  boundSameForAllLocalRows);
549  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
550  numEntriesForAll != 0 &&
551  static_cast<size_t> (numEntriesPerRow.size ()) != 0,
552  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
553  "nonzero numEntriesForAll = " << numEntriesForAll << " , as well as a "
554  "numEntriesPerRow array of nonzero length " << numEntriesPerRow.size ()
555  << ". This should never happen. Please report this bug to the Tpetra "
556  "developers.");
557  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
558  numEntriesForAll != 0 && ! boundSameForAllLocalRows,
559  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
560  "nonzero numEntriesForAll = " << numEntriesForAll << " , but claims "
561  "(via its third output value) that the upper bound is not the same for "
562  "all rows. This should never happen. Please report this bug to the "
563  "Tpetra developers.");
564  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
565  numEntriesPerRow.size () != 0 && boundSameForAllLocalRows,
566  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
567  "numEntriesPerRow array of nonzero length " << numEntriesPerRow.size ()
568  << ", but claims (via its third output value) that the upper bound is "
569  "not the same for all rows. This should never happen. Please report "
570  "this bug to the Tpetra developers.");
571 
572  RCP<ParameterList> matParams =
573  params.is_null () ? null : sublist (params,"CrsMatrix");
574  if (useLocalIndices) {
575  RCP<const Map2> clonedColMap =
576  this->getColMap ()->template clone<Node2> (node2);
577  if (numEntriesPerRow.is_null ()) {
578  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, clonedColMap,
579  numEntriesForAll, pftype,
580  matParams));
581  }
582  else {
583  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, clonedColMap,
584  numEntriesPerRow, pftype,
585  matParams));
586  }
587  }
588  else {
589  if (numEntriesPerRow.is_null ()) {
590  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, numEntriesForAll,
591  pftype, matParams));
592  }
593  else {
594  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, numEntriesPerRow,
595  pftype, matParams));
596  }
597  }
598  // done with these
599  numEntriesPerRow = Teuchos::null;
600  numEntriesForAll = 0;
601 
602  if (useLocalIndices) {
603  clonedMatrix->allocateValues (LocalIndices,
604  CrsMatrix2::GraphNotYetAllocated);
605  if (this->isLocallyIndexed ()) {
606  ArrayView<const LocalOrdinal> linds;
607  ArrayView<const Scalar> vals;
608  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
609  lrow <= clonedRowMap->getMaxLocalIndex ();
610  ++lrow) {
611  this->getLocalRowView (lrow, linds, vals);
612  if (linds.size ()) {
613  clonedMatrix->insertLocalValues (lrow, linds, vals);
614  }
615  }
616  }
617  else { // this->isGloballyIndexed()
618  Array<LocalOrdinal> linds;
619  Array<Scalar> vals;
620  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
621  lrow <= clonedRowMap->getMaxLocalIndex ();
622  ++lrow) {
623  size_t theNumEntries = this->getNumEntriesInLocalRow (lrow);
624  if (theNumEntries > static_cast<size_t> (linds.size ())) {
625  linds.resize (theNumEntries);
626  }
627  if (theNumEntries > static_cast<size_t> (vals.size ())) {
628  vals.resize (theNumEntries);
629  }
630  this->getLocalRowCopy (clonedRowMap->getGlobalElement (lrow),
631  linds (), vals (), theNumEntries);
632  if (theNumEntries != 0) {
633  clonedMatrix->insertLocalValues (lrow, linds (0, theNumEntries),
634  vals (0, theNumEntries));
635  }
636  }
637  }
638  }
639  else { // useGlobalIndices
640  clonedMatrix->allocateValues (GlobalIndices,
641  CrsMatrix2::GraphNotYetAllocated);
642  if (this->isGloballyIndexed ()) {
643  ArrayView<const GlobalOrdinal> ginds;
644  ArrayView<const Scalar> vals;
645  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
646  grow <= clonedRowMap->getMaxGlobalIndex ();
647  ++grow) {
648  this->getGlobalRowView (grow, ginds, vals);
649  if (ginds.size () > 0) {
650  clonedMatrix->insertGlobalValues (grow, ginds, vals);
651  }
652  }
653  }
654  else { // this->isLocallyIndexed()
655  Array<GlobalOrdinal> ginds;
656  Array<Scalar> vals;
657  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
658  grow <= clonedRowMap->getMaxGlobalIndex ();
659  ++grow) {
660  size_t theNumEntries = this->getNumEntriesInGlobalRow (grow);
661  if (theNumEntries > static_cast<size_t> (ginds.size ())) {
662  ginds.resize (theNumEntries);
663  }
664  if (theNumEntries > static_cast<size_t> (vals.size ())) {
665  vals.resize (theNumEntries);
666  }
667  this->getGlobalRowCopy (grow, ginds (), vals (), theNumEntries);
668  if (theNumEntries != 0) {
669  clonedMatrix->insertGlobalValues (grow, ginds (0, theNumEntries),
670  vals (0, theNumEntries));
671  }
672  }
673  }
674  }
675 
676  if (fillCompleteClone) {
677  RCP<const Map2> clonedRangeMap;
678  RCP<const Map2> clonedDomainMap;
679  try {
680  if (! this->getRangeMap ().is_null () &&
681  this->getRangeMap () != clonedRowMap) {
682  clonedRangeMap = this->getRangeMap ()->template clone<Node2> (node2);
683  }
684  else {
685  clonedRangeMap = clonedRowMap;
686  }
687  if (! this->getDomainMap ().is_null () &&
688  this->getDomainMap () != clonedRowMap) {
689  clonedDomainMap = this->getDomainMap ()->template clone<Node2> (node2);
690  }
691  else {
692  clonedDomainMap = clonedRowMap;
693  }
694  }
695  catch (std::exception &e) {
696  const bool caughtExceptionOnClone = true;
697  TEUCHOS_TEST_FOR_EXCEPTION
698  (caughtExceptionOnClone, std::runtime_error,
699  Teuchos::typeName (*this) << "::clone: Caught the following "
700  "exception while cloning range and domain Maps on a clone of "
701  "type " << Teuchos::typeName (*clonedMatrix) << ": " << e.what ());
702  }
703 
704  RCP<ParameterList> fillparams =
705  params.is_null () ? Teuchos::null : sublist (params, "fillComplete");
706  try {
707  clonedMatrix->fillComplete (clonedDomainMap, clonedRangeMap,
708  fillparams);
709  }
710  catch (std::exception &e) {
711  const bool caughtExceptionOnClone = true;
712  TEUCHOS_TEST_FOR_EXCEPTION(
713  caughtExceptionOnClone, std::runtime_error,
714  Teuchos::typeName (*this) << "::clone: Caught the following "
715  "exception while calling fillComplete() on a clone of type "
716  << Teuchos::typeName (*clonedMatrix) << ": " << e.what ());
717  }
718  }
719  return clonedMatrix;
720  }
721 
723  virtual ~CrsMatrix ();
724 
726 
728 
751  //
797  void
798  insertGlobalValues (const GlobalOrdinal globalRow,
799  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
800  const Teuchos::ArrayView<const Scalar>& vals);
801 
841  void
842  insertLocalValues (const LocalOrdinal localRow,
843  const ArrayView<const LocalOrdinal> &cols,
844  const ArrayView<const Scalar> &vals);
845 
880  LocalOrdinal
881  replaceGlobalValues (GlobalOrdinal globalRow,
882  const ArrayView<const GlobalOrdinal>& cols,
883  const ArrayView<const Scalar>& vals);
884 
915  LocalOrdinal
916  replaceLocalValues (const LocalOrdinal localRow,
917  const ArrayView<const LocalOrdinal>& cols,
918  const ArrayView<const Scalar>& vals);
919 
952  LocalOrdinal
953  sumIntoGlobalValues (const GlobalOrdinal globalRow,
954  const ArrayView<const GlobalOrdinal> &cols,
955  const ArrayView<const Scalar> &vals);
956 
971  LocalOrdinal
972  sumIntoLocalValues (const LocalOrdinal localRow,
973  const ArrayView<const LocalOrdinal>& cols,
974  const ArrayView<const Scalar>& vals);
975 
977  void setAllToScalar (const Scalar &alpha);
978 
980  void scale (const Scalar &alpha);
981 
983 
990  void
991  setAllValues (const typename local_matrix_type::row_map_type& rowPointers,
992  const typename local_graph_type::entries_type::non_const_type& columnIndices,
993  const typename local_matrix_type::values_type& values);
994 
996 
1007  void
1008  setAllValues (const Teuchos::ArrayRCP<size_t>& rowPointers,
1009  const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
1010  const Teuchos::ArrayRCP<Scalar>& values);
1011 
1012  void
1013  getAllValues (Teuchos::ArrayRCP<const size_t>& rowPointers,
1014  Teuchos::ArrayRCP<const LocalOrdinal>& columnIndices,
1015  Teuchos::ArrayRCP<const Scalar>& values) const;
1016 
1018 
1020 
1049  void globalAssemble();
1050 
1064  void resumeFill (const RCP<ParameterList>& params = null);
1065 
1099  void
1100  fillComplete (const RCP<const map_type>& domainMap,
1101  const RCP<const map_type>& rangeMap,
1102  const RCP<ParameterList>& params = null);
1103 
1116  void fillComplete (const RCP<ParameterList>& params = null);
1117 
1129  void
1130  expertStaticFillComplete (const RCP<const map_type>& domainMap,
1131  const RCP<const map_type>& rangeMap,
1132  const RCP<const import_type>& importer = Teuchos::null,
1133  const RCP<const export_type>& exporter = Teuchos::null,
1134  const RCP<ParameterList>& params = Teuchos::null);
1135 
1145  void
1146  replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
1147 
1229  void
1230  reindexColumns (crs_graph_type* const graph,
1231  const Teuchos::RCP<const map_type>& newColMap,
1232  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1233  const bool sortEachRow = true);
1234 
1247  void
1248  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
1249  Teuchos::RCP<const import_type>& newImporter);
1250 
1264  virtual void
1265  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
1266 
1268 
1270 
1272  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
1273 
1275  Teuchos::RCP<node_type> getNode () const;
1276 
1278  Teuchos::RCP<const map_type> getRowMap () const;
1279 
1281  Teuchos::RCP<const map_type> getColMap () const;
1282 
1284  Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> > getGraph () const;
1285 
1287  Teuchos::RCP<const crs_graph_type> getCrsGraph () const;
1288 
1290  local_matrix_type getLocalMatrix () const {return lclMatrix_; }
1291 
1312 
1319 
1326  size_t getNodeNumRows() const;
1327 
1331  size_t getNodeNumCols() const;
1332 
1334  GlobalOrdinal getIndexBase() const;
1335 
1338 
1340  size_t getNodeNumEntries() const;
1341 
1343 
1344  size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const;
1345 
1347 
1348  size_t getNumEntriesInLocalRow (LocalOrdinal localRow) const;
1349 
1351 
1354 
1356 
1358  size_t getNodeNumDiags() const;
1359 
1361 
1363  size_t getGlobalMaxNumRowEntries() const;
1364 
1366 
1368  size_t getNodeMaxNumRowEntries() const;
1369 
1371  bool hasColMap() const;
1372 
1374 
1376  bool isLowerTriangular() const;
1377 
1379 
1381  bool isUpperTriangular() const;
1382 
1402  bool isLocallyIndexed() const;
1403 
1423  bool isGloballyIndexed() const;
1424 
1447  bool isFillComplete() const;
1448 
1471  bool isFillActive() const;
1472 
1474 
1480  bool isStorageOptimized () const;
1481 
1483  ProfileType getProfileType () const;
1484 
1486  bool isStaticGraph () const;
1487 
1499  mag_type getFrobeniusNorm () const;
1500 
1503  virtual bool supportsRowViews () const;
1504 
1553  void
1554  getGlobalRowCopy (GlobalOrdinal GlobalRow,
1555  const Teuchos::ArrayView<GlobalOrdinal>& Indices,
1556  const Teuchos::ArrayView<Scalar>& Values,
1557  size_t& NumEntries) const;
1558 
1576  void
1577  getLocalRowCopy (LocalOrdinal localRow,
1578  const Teuchos::ArrayView<LocalOrdinal>& colInds,
1579  const Teuchos::ArrayView<Scalar>& vals,
1580  size_t& numEntries) const;
1581 
1595  void
1596  getGlobalRowView (GlobalOrdinal GlobalRow,
1597  Teuchos::ArrayView<const GlobalOrdinal>& indices,
1598  Teuchos::ArrayView<const Scalar>& values) const;
1599 
1613  void
1614  getLocalRowView (LocalOrdinal LocalRow,
1615  Teuchos::ArrayView<const LocalOrdinal>& indices,
1616  Teuchos::ArrayView<const Scalar>& values) const;
1617 
1624 
1662  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
1663 
1682  void
1684  const Teuchos::ArrayView<const size_t>& offsets) const;
1685 
1686 
1687 
1689  void
1691 
1693  void
1695 
1697 
1699 
1748  template <class DomainScalar, class RangeScalar>
1749  void
1752  Teuchos::ETransp mode,
1753  RangeScalar alpha,
1754  RangeScalar beta) const
1755  {
1756  using Teuchos::NO_TRANS;
1757  // Just like Scalar and impl_scalar_type may differ in CrsMatrix,
1758  // RangeScalar and its corresponding impl_scalar_type may differ in
1759  // MultiVector.
1760  typedef typename MultiVector<RangeScalar, LocalOrdinal, GlobalOrdinal,
1761  Node, classic>::impl_scalar_type range_impl_scalar_type;
1762 #ifdef HAVE_TPETRA_DEBUG
1763  const char tfecfFuncName[] = "localMultiply: ";
1764 #endif // HAVE_TPETRA_DEBUG
1765 
1766  const range_impl_scalar_type theAlpha = static_cast<range_impl_scalar_type> (alpha);
1767  const range_impl_scalar_type theBeta = static_cast<range_impl_scalar_type> (beta);
1768  const bool conjugate = (mode == Teuchos::CONJ_TRANS);
1769  const bool transpose = (mode != Teuchos::NO_TRANS);
1770 
1771 #ifdef HAVE_TPETRA_DEBUG
1772  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
1773  (X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
1774  "X.getNumVectors() = " << X.getNumVectors () << " != Y.getNumVectors() = "
1775  << Y.getNumVectors () << ".");
1776  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
1777  (! transpose && X.getLocalLength () != getColMap ()->getNodeNumElements (),
1778  std::runtime_error, "NO_TRANS case: X has the wrong number of local rows. "
1779  "X.getLocalLength() = " << X.getLocalLength () << " != getColMap()->"
1780  "getNodeNumElements() = " << getColMap ()->getNodeNumElements () << ".");
1781  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
1782  (! transpose && Y.getLocalLength () != getRowMap ()->getNodeNumElements (),
1783  std::runtime_error, "NO_TRANS case: Y has the wrong number of local rows. "
1784  "Y.getLocalLength() = " << Y.getLocalLength () << " != getRowMap()->"
1785  "getNodeNumElements() = " << getRowMap ()->getNodeNumElements () << ".");
1786  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
1787  (transpose && X.getLocalLength () != getRowMap ()->getNodeNumElements (),
1788  std::runtime_error, "TRANS or CONJ_TRANS case: X has the wrong number of "
1789  "local rows. X.getLocalLength() = " << X.getLocalLength () << " != "
1790  "getRowMap()->getNodeNumElements() = "
1791  << getRowMap ()->getNodeNumElements () << ".");
1792  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
1793  (transpose && Y.getLocalLength () != getColMap ()->getNodeNumElements (),
1794  std::runtime_error, "TRANS or CONJ_TRANS case: X has the wrong number of "
1795  "local rows. Y.getLocalLength() = " << Y.getLocalLength () << " != "
1796  "getColMap()->getNodeNumElements() = "
1797  << getColMap ()->getNodeNumElements () << ".");
1798  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
1799  (! isFillComplete (), std::runtime_error, "The matrix is not fill "
1800  "complete. You must call fillComplete() (possibly with domain and range "
1801  "Map arguments) without an intervening resumeFill() call before you may "
1802  "call this method.");
1803  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
1804  (! X.isConstantStride () || ! Y.isConstantStride (), std::runtime_error,
1805  "X and Y must be constant stride.");
1806  // If the two pointers are NULL, then they don't alias one
1807  // another, even though they are equal.
1808  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1809  X.getDualView ().d_view.ptr_on_device () == Y.getDualView ().d_view.ptr_on_device () &&
1810  X.getDualView ().d_view.ptr_on_device () != NULL,
1811  std::runtime_error, "X and Y may not alias one another.");
1812 #endif // HAVE_TPETRA_DEBUG
1813 
1814  // Y = alpha*op(M) + beta*Y
1815  if (transpose) {
1816  KokkosSparse::spmv (conjugate ? KokkosSparse::ConjugateTranspose : KokkosSparse::Transpose,
1817  theAlpha,
1818  lclMatrix_,
1819  X.template getLocalView<device_type> (),
1820  theBeta,
1821  Y.template getLocalView<device_type> ());
1822  }
1823  else {
1824  KokkosSparse::spmv (KokkosSparse::NoTranspose,
1825  theAlpha,
1826  lclMatrix_,
1827  X.template getLocalView<device_type> (),
1828  theBeta,
1829  Y.template getLocalView<device_type> ());
1830  }
1831  }
1832 
1857  template <class DomainScalar, class RangeScalar>
1858  void
1862  const RangeScalar& dampingFactor,
1863  const KokkosClassic::ESweepDirection direction) const
1864  {
1865  typedef LocalOrdinal LO;
1866  typedef GlobalOrdinal GO;
1870  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
1871  typedef typename Graph::local_graph_type k_local_graph_type;
1872  typedef typename k_local_graph_type::size_type offset_type;
1873  const char prefix[] = "Tpetra::CrsMatrix::localGaussSeidel: ";
1874 
1875  TEUCHOS_TEST_FOR_EXCEPTION
1876  (! this->isFillComplete (), std::runtime_error,
1877  prefix << "The matrix is not fill complete.");
1878  const size_t lclNumRows = this->getNodeNumRows ();
1879  const size_t numVecs = B.getNumVectors ();
1880  TEUCHOS_TEST_FOR_EXCEPTION
1881  (X.getNumVectors () != numVecs, std::invalid_argument,
1882  prefix << "B.getNumVectors() = " << numVecs << " != "
1883  "X.getNumVectors() = " << X.getNumVectors () << ".");
1884  TEUCHOS_TEST_FOR_EXCEPTION
1885  (B.getLocalLength () != lclNumRows, std::invalid_argument,
1886  prefix << "B.getLocalLength() = " << B.getLocalLength ()
1887  << " != this->getNodeNumRows() = " << lclNumRows << ".");
1888 
1889  typename DMV::dual_view_type::t_host B_lcl = B.template getLocalView<HMDT> ();
1890  typename RMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
1891  typename MMV::dual_view_type::t_host D_lcl = D.template getLocalView<HMDT> ();
1892 
1893  offset_type B_stride[8], X_stride[8], D_stride[8];
1894  B_lcl.stride (B_stride);
1895  X_lcl.stride (X_stride);
1896  D_lcl.stride (D_stride);
1897 
1898  local_matrix_type lclMatrix = this->getLocalMatrix ();
1899  k_local_graph_type lclGraph = lclMatrix.graph;
1900  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
1901  typename local_matrix_type::index_type ind = lclGraph.entries;
1902  typename local_matrix_type::values_type val = lclMatrix.values;
1903  const offset_type* const ptrRaw = ptr.ptr_on_device ();
1904  const LO* const indRaw = ind.ptr_on_device ();
1905  const impl_scalar_type* const valRaw = val.ptr_on_device ();
1906 
1907  const std::string dir ((direction == KokkosClassic::Forward) ? "F" : "B");
1908  KokkosSparse::Impl::Sequential::gaussSeidel (static_cast<LO> (lclNumRows),
1909  static_cast<LO> (numVecs),
1910  ptrRaw, indRaw, valRaw,
1911  B_lcl.ptr_on_device (), B_stride[1],
1912  X_lcl.ptr_on_device (), X_stride[1],
1913  D_lcl.ptr_on_device (),
1914  static_cast<impl_scalar_type> (dampingFactor),
1915  dir.c_str ());
1916  }
1917 
1944  template <class DomainScalar, class RangeScalar>
1945  void
1949  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
1950  const RangeScalar& dampingFactor,
1951  const KokkosClassic::ESweepDirection direction) const
1952  {
1953  typedef LocalOrdinal LO;
1954  typedef GlobalOrdinal GO;
1958  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
1959  typedef typename Graph::local_graph_type k_local_graph_type;
1960  typedef typename k_local_graph_type::size_type offset_type;
1961  const char prefix[] = "Tpetra::CrsMatrix::reorderedLocalGaussSeidel: ";
1962 
1963  TEUCHOS_TEST_FOR_EXCEPTION
1964  (! this->isFillComplete (), std::runtime_error,
1965  prefix << "The matrix is not fill complete.");
1966  const size_t lclNumRows = this->getNodeNumRows ();
1967  const size_t numVecs = B.getNumVectors ();
1968  TEUCHOS_TEST_FOR_EXCEPTION
1969  (X.getNumVectors () != numVecs, std::invalid_argument,
1970  prefix << "B.getNumVectors() = " << numVecs << " != "
1971  "X.getNumVectors() = " << X.getNumVectors () << ".");
1972  TEUCHOS_TEST_FOR_EXCEPTION
1973  (B.getLocalLength () != lclNumRows, std::invalid_argument,
1974  prefix << "B.getLocalLength() = " << B.getLocalLength ()
1975  << " != this->getNodeNumRows() = " << lclNumRows << ".");
1976  TEUCHOS_TEST_FOR_EXCEPTION
1977  (static_cast<size_t> (rowIndices.size ()) < lclNumRows,
1978  std::invalid_argument, prefix << "rowIndices.size() = "
1979  << rowIndices.size () << " < this->getNodeNumRows() = "
1980  << lclNumRows << ".");
1981 
1982  typename DMV::dual_view_type::t_host B_lcl = B.template getLocalView<HMDT> ();
1983  typename RMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
1984  typename MMV::dual_view_type::t_host D_lcl = D.template getLocalView<HMDT> ();
1985 
1986  offset_type B_stride[8], X_stride[8], D_stride[8];
1987  B_lcl.stride (B_stride);
1988  X_lcl.stride (X_stride);
1989  D_lcl.stride (D_stride);
1990 
1991  local_matrix_type lclMatrix = this->getLocalMatrix ();
1992  typename Graph::local_graph_type lclGraph = lclMatrix.graph;
1993  typename local_matrix_type::index_type ind = lclGraph.entries;
1994  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
1995  typename local_matrix_type::values_type val = lclMatrix.values;
1996  const offset_type* const ptrRaw = ptr.ptr_on_device ();
1997  const LO* const indRaw = ind.ptr_on_device ();
1998  const impl_scalar_type* const valRaw = val.ptr_on_device ();
1999 
2000  const std::string dir = (direction == KokkosClassic::Forward) ? "F" : "B";
2001  KokkosSparse::Impl::Sequential::reorderedGaussSeidel (static_cast<LO> (lclNumRows),
2002  static_cast<LO> (numVecs),
2003  ptrRaw, indRaw, valRaw,
2004  B_lcl.ptr_on_device (),
2005  B_stride[1],
2006  X_lcl.ptr_on_device (),
2007  X_stride[1],
2008  D_lcl.ptr_on_device (),
2009  rowIndices.getRawPtr (),
2010  static_cast<LO> (lclNumRows),
2011  static_cast<impl_scalar_type> (dampingFactor),
2012  dir.c_str ());
2013  }
2014 
2033  template <class DomainScalar, class RangeScalar>
2034  void
2037  Teuchos::ETransp mode) const
2038  {
2039  using Teuchos::CONJ_TRANS;
2040  using Teuchos::NO_TRANS;
2041  using Teuchos::TRANS;
2042  typedef LocalOrdinal LO;
2043  typedef GlobalOrdinal GO;
2046  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2047 
2048  const char tfecfFuncName[] = "localSolve: ";
2049 
2050  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2051  (! isFillComplete (), std::runtime_error,
2052  "The matrix is not fill complete.");
2053  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2054  (! X.isConstantStride () || ! Y.isConstantStride (), std::invalid_argument,
2055  "X and Y must be constant stride.");
2056  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2057  (! isUpperTriangular () && ! isLowerTriangular (), std::runtime_error,
2058  "The matrix is neither upper triangular or lower triangular. "
2059  "You may only call this method if the matrix is triangular. "
2060  "Remember that this is a local (per MPI process) property, and that "
2061  "Tpetra only knows how to do a local (per process) triangular solve.");
2062  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2063  (STS::isComplex && mode == TRANS, std::logic_error, "This method does "
2064  "not currently support non-conjugated transposed solve (mode == "
2065  "Teuchos::TRANS) for complex scalar types.");
2066 
2067  // FIXME (mfh 27 Aug 2014) Tpetra has always made the odd decision
2068  // that if _some_ diagonal entries are missing locally, then it
2069  // assumes that the matrix has an implicitly stored unit diagonal.
2070  // Whether the matrix has an implicit unit diagonal or not should
2071  // be up to the user to decide. What if the graph has no diagonal
2072  // entries, and the user wants it that way? The only reason this
2073  // matters, though, is for the triangular solve, and in that case,
2074  // missing diagonal entries will cause trouble anyway. However,
2075  // it would make sense to warn the user if they ask for a
2076  // triangular solve with an incomplete diagonal. Furthermore,
2077  // this code should only assume an implicitly stored unit diagonal
2078  // if the matrix has _no_ explicitly stored diagonal entries.
2079 
2080  const std::string uplo = isUpperTriangular () ? "U" :
2081  (isLowerTriangular () ? "L" : "N");
2082  const std::string trans = (mode == Teuchos::CONJ_TRANS) ? "C" :
2083  (mode == Teuchos::TRANS ? "T" : "N");
2084  const std::string diag =
2085  (getNodeNumDiags () < getNodeNumRows ()) ? "U" : "N";
2086 
2087  local_matrix_type A_lcl = this->getLocalMatrix ();
2088 
2089  // FIXME (mfh 23 Apr 2015) We currently only have a host,
2090  // sequential kernel for local sparse triangular solve.
2091 
2092  Y.getDualView ().template sync<HMDT> (); // Y is read-only
2093  X.getDualView ().template sync<HMDT> ();
2094  X.getDualView ().template modify<HMDT> (); // we will write to X
2095 
2096  if (X.isConstantStride () && Y.isConstantStride ()) {
2097  typename DMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
2098  typename RMV::dual_view_type::t_host Y_lcl = Y.template getLocalView<HMDT> ();
2099  KokkosSparse::trsv (uplo.c_str (), trans.c_str (), diag.c_str (), A_lcl, Y_lcl, X_lcl);
2100  }
2101  else {
2102  const size_t numVecs = std::min (X.getNumVectors (), Y.getNumVectors ());
2103  for (size_t j = 0; j < numVecs; ++j) {
2104  auto X_j = X.getVector (j);
2105  auto Y_j = X.getVector (j);
2106  auto X_lcl = X_j->template getLocalView<HMDT> ();
2107  auto Y_lcl = Y_j->template getLocalView<HMDT> ();
2108  KokkosSparse::trsv (uplo.c_str (), trans.c_str (), diag.c_str (), A_lcl, Y_lcl, X_lcl);
2109  }
2110  }
2111  }
2112 
2115  template <class T>
2116  Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node, classic> >
2117  convert () const;
2118 
2120 
2122 
2133  void
2136  Teuchos::ETransp mode = Teuchos::NO_TRANS,
2137  Scalar alpha = ScalarTraits<Scalar>::one(),
2138  Scalar beta = ScalarTraits<Scalar>::zero()) const;
2139 
2141  bool hasTransposeApply () const;
2142 
2149  Teuchos::RCP<const map_type> getDomainMap () const;
2150 
2157  Teuchos::RCP<const map_type> getRangeMap () const;
2158 
2160 
2162 
2227  void
2231  const Scalar& dampingFactor,
2232  const ESweepDirection direction,
2233  const int numSweeps) const;
2234 
2301  void
2305  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2306  const Scalar& dampingFactor,
2307  const ESweepDirection direction,
2308  const int numSweeps) const;
2309 
2338  void
2342  const Scalar& dampingFactor,
2343  const ESweepDirection direction,
2344  const int numSweeps,
2345  const bool zeroInitialGuess) const;
2346 
2376  void
2380  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2381  const Scalar& dampingFactor,
2382  const ESweepDirection direction,
2383  const int numSweeps,
2384  const bool zeroInitialGuess) const;
2385 
2396  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
2397  add (const Scalar& alpha,
2399  const Scalar& beta,
2400  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
2401  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
2402  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
2403 
2405 
2407 
2409  std::string description () const;
2410 
2412  void
2413  describe (Teuchos::FancyOStream &out,
2414  const Teuchos::EVerbosityLevel verbLevel =
2415  Teuchos::Describable::verbLevel_default) const;
2416 
2418 
2420 
2421  virtual bool
2422  checkSizes (const SrcDistObject& source);
2423 
2424  virtual void
2425  copyAndPermute (const SrcDistObject& source,
2426  size_t numSameIDs,
2427  const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
2428  const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs);
2429 
2430  virtual void
2431  packAndPrepare (const SrcDistObject& source,
2432  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
2433  Teuchos::Array<char>& exports,
2434  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
2435  size_t& constantNumPackets,
2436  Distributor& distor);
2437 
2438  private:
2441  void
2442  unpackAndCombineImpl (const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
2443  const Teuchos::ArrayView<const char> &imports,
2444  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
2445  size_t constantNumPackets,
2446  Distributor& distor,
2447  CombineMode combineMode);
2448 
2449  public:
2459  void
2460  unpackAndCombine (const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
2461  const Teuchos::ArrayView<const char> &imports,
2462  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
2463  size_t constantNumPackets,
2464  Distributor& distor,
2465  CombineMode combineMode);
2467 
2469 
2587  virtual void
2588  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
2589  Teuchos::Array<char>& exports,
2590  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
2591  size_t& constantNumPackets,
2592  Distributor& distor) const;
2593 
2594  private:
2612  bool
2613  packRow (char* const numEntOut,
2614  char* const valOut,
2615  char* const indOut,
2616  const size_t numEnt,
2617  const LocalOrdinal lclRow) const;
2618 
2641  bool
2642  unpackRow (Scalar* const valInTmp,
2643  GlobalOrdinal* const indInTmp,
2644  const size_t tmpNumEnt,
2645  const char* const valIn,
2646  const char* const indIn,
2647  const size_t numEnt,
2648  const LocalOrdinal lclRow,
2649  const Tpetra::CombineMode combineMode);
2650 
2656  void
2657  allocatePackSpace (Teuchos::Array<char>& exports,
2658  size_t& totalNumEntries,
2659  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs) const;
2661 
2662  public:
2664  typename local_matrix_type::values_type getLocalValuesView () const {
2665  return k_values1D_;
2666  }
2667 
2668  private:
2669  // Friend declaration for nonmember function.
2670  template<class CrsMatrixType>
2671  friend Teuchos::RCP<CrsMatrixType>
2672  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
2673  const Import<typename CrsMatrixType::local_ordinal_type,
2674  typename CrsMatrixType::global_ordinal_type,
2675  typename CrsMatrixType::node_type>& importer,
2676  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
2677  typename CrsMatrixType::global_ordinal_type,
2678  typename CrsMatrixType::node_type> >& domainMap,
2679  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
2680  typename CrsMatrixType::global_ordinal_type,
2681  typename CrsMatrixType::node_type> >& rangeMap,
2682  const Teuchos::RCP<Teuchos::ParameterList>& params);
2683 
2684  // Friend declaration for nonmember function.
2685  template<class CrsMatrixType>
2686  friend Teuchos::RCP<CrsMatrixType>
2687  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
2688  const Export<typename CrsMatrixType::local_ordinal_type,
2689  typename CrsMatrixType::global_ordinal_type,
2690  typename CrsMatrixType::node_type>& exporter,
2691  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
2692  typename CrsMatrixType::global_ordinal_type,
2693  typename CrsMatrixType::node_type> >& domainMap,
2694  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
2695  typename CrsMatrixType::global_ordinal_type,
2696  typename CrsMatrixType::node_type> >& rangeMap,
2697  const Teuchos::RCP<Teuchos::ParameterList>& params);
2698 
2699  public:
2715  void
2717  const import_type& importer,
2718  const Teuchos::RCP<const map_type>& domainMap,
2719  const Teuchos::RCP<const map_type>& rangeMap,
2720  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
2721 
2737  void
2739  const export_type& exporter,
2740  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
2741  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
2742  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
2743 
2744 
2745 
2746  private:
2767  void
2768  transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >& destMatrix,
2769  const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
2770  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
2771  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
2772  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
2773  // We forbid copy construction by declaring this method private
2774  // and not implementing it.
2776 
2777  // We forbid assignment (operator=) by declaring this method
2778  // private and not implementing it.
2781 
2791  void
2792  insertGlobalValuesFiltered (const GlobalOrdinal globalRow,
2793  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
2794  const Teuchos::ArrayView<const Scalar>& values);
2795 
2805  void
2806  insertLocalValuesFiltered (const LocalOrdinal localRow,
2807  const Teuchos::ArrayView<const LocalOrdinal>& indices,
2808  const Teuchos::ArrayView<const Scalar>& values);
2809 
2821  void
2822  combineGlobalValues (const GlobalOrdinal globalRowIndex,
2823  const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
2824  const Teuchos::ArrayView<const Scalar>& values,
2825  const Tpetra::CombineMode combineMode);
2826 
2860  template<class BinaryFunction>
2861  LocalOrdinal
2862  transformGlobalValues (GlobalOrdinal globalRow,
2863  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
2864  const Teuchos::ArrayView<const Scalar>& values,
2865  BinaryFunction f)
2866  {
2867  using Teuchos::Array;
2868  using Teuchos::ArrayView;
2869  typedef LocalOrdinal LO;
2870  typedef GlobalOrdinal GO;
2871  typedef impl_scalar_type ST;
2872  typedef typename ArrayView<const GO>::size_type size_type;
2873 
2874  if (! isFillActive ()) {
2875  // Fill must be active in order to call this method.
2876  return Teuchos::OrdinalTraits<LO>::invalid ();
2877  }
2878  else if (values.size () != indices.size ()) {
2879  // The sizes of values and indices must match.
2880  return Teuchos::OrdinalTraits<LO>::invalid ();
2881  }
2882 
2883  const LO lrow = this->getRowMap ()->getLocalElement (globalRow);
2884  if (lrow == Teuchos::OrdinalTraits<LO>::invalid ()) {
2885  // We don't own the row, so we're not allowed to modify its values.
2886  return Teuchos::OrdinalTraits<LO>::invalid ();
2887  }
2888 
2889  if (staticGraph_.is_null ()) {
2890  return Teuchos::OrdinalTraits<LO>::invalid ();
2891  }
2892  const crs_graph_type& graph = *staticGraph_;
2893  RowInfo rowInfo = graph.getRowInfo (lrow);
2894  if (indices.size () == 0) {
2895  return static_cast<LO> (0);
2896  }
2897  else {
2898  ArrayView<const ST> valsIn =
2899  Teuchos::av_reinterpret_cast<const ST> (values);
2900  ArrayView<ST> curVals = this->getViewNonConst (rowInfo);
2901  if (isLocallyIndexed ()) {
2902  // Convert the given global indices to local indices.
2903  //
2904  // FIXME (mfh 08 Jul 2014) Why can't we ask the graph to do
2905  // that? It could do the conversions in place, so that we
2906  // wouldn't need temporary storage.
2907  const map_type& colMap = * (this->getColMap ());
2908  const size_type numInds = indices.size ();
2909  Array<LO> lclInds (numInds);
2910  for (size_type k = 0; k < numInds; ++k) {
2911  // There is no need to filter out indices not in the
2912  // column Map. Those that aren't will be mapped to
2913  // invalid(), which the graph's transformGlobalValues()
2914  // will filter out (but not count in its return value).
2915  lclInds[k] = colMap.getLocalElement (indices[k]);
2916  }
2917  return graph.template transformLocalValues<ST, BinaryFunction> (rowInfo,
2918  curVals,
2919  lclInds (),
2920  valsIn, f);
2921  }
2922  else if (isGloballyIndexed ()) {
2923  return graph.template transformGlobalValues<ST, BinaryFunction> (rowInfo,
2924  curVals,
2925  indices,
2926  valsIn, f);
2927  }
2928  else {
2929  // If the graph is neither locally nor globally indexed on
2930  // the calling process, that means that the calling process
2931  // can't possibly have any entries in the owned row. Thus,
2932  // there are no entries to transform, so we return zero.
2933  return static_cast<LO> (0);
2934  }
2935  }
2936  }
2937 
2938  private:
2945  void
2946  insertNonownedGlobalValues (const GlobalOrdinal globalRow,
2947  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
2948  const Teuchos::ArrayView<const Scalar>& values);
2949 
2952 
2953  protected:
2954  // useful typedefs
2955  typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
2956  typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
2957  typedef Kokkos::Details::ArithTraits<mag_type> STM;
2960  typedef crs_graph_type Graph;
2961 
2962  // Enums
2963  enum GraphAllocationStatus {
2964  GraphAlreadyAllocated,
2965  GraphNotYetAllocated
2966  };
2967 
2984  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas);
2985 
2991  void sortEntries();
2992 
2998  void mergeRedundantEntries();
2999 
3007  void clearGlobalConstants();
3008 
3017  void computeGlobalConstants();
3018 
3031  mutable Teuchos::RCP<MV> importMV_;
3032 
3045  mutable Teuchos::RCP<MV> exportMV_;
3046 
3066  Teuchos::RCP<MV>
3067  getColumnMapMultiVector (const MV& X_domainMap,
3068  const bool force = false) const;
3069 
3091  Teuchos::RCP<MV>
3092  getRowMapMultiVector (const MV& Y_rangeMap,
3093  const bool force = false) const;
3094 
3096  void
3097  applyNonTranspose (const MV& X_in,
3098  MV& Y_in,
3099  Scalar alpha,
3100  Scalar beta) const;
3101 
3103  void
3104  applyTranspose (const MV& X_in,
3105  MV& Y_in,
3106  const Teuchos::ETransp mode,
3107  Scalar alpha,
3108  Scalar beta) const;
3109 
3110  // matrix data accessors
3111 
3119  Teuchos::ArrayView<const impl_scalar_type> getView (RowInfo rowinfo) const;
3120 
3128  Teuchos::ArrayView<impl_scalar_type> getViewNonConst (RowInfo rowinfo);
3129 
3135  void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
3136 
3142  void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
3143 
3145  void checkInternalState () const;
3146 
3158 
3159  Teuchos::RCP<const Graph> staticGraph_;
3160  Teuchos::RCP< Graph> myGraph_;
3162 
3164  local_matrix_type lclMatrix_;
3165 
3178 
3179  typename local_matrix_type::values_type k_values1D_;
3180  Teuchos::ArrayRCP<Teuchos::Array<impl_scalar_type> > values2D_;
3182 
3193 
3196 
3224  std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
3225  Teuchos::Array<Scalar> > > nonlocals_;
3226 
3232  mutable mag_type frobNorm_;
3233 
3234  public:
3235  // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
3236  // public inner class of CrsMatrix? It looks like it doesn't
3237  // depend on any implementation details of CrsMatrix at all. It
3238  // should really be declared and defined outside of CrsMatrix.
3239  template<class ViewType, class OffsetViewType>
3240  struct pack_functor {
3241  typedef typename ViewType::execution_space execution_space;
3242  ViewType src_;
3243  ViewType dst_;
3244  OffsetViewType src_offset_;
3245  OffsetViewType dst_offset_;
3246  typedef typename OffsetViewType::non_const_value_type scalar_index_type;
3247 
3248  pack_functor (ViewType dst, ViewType src,
3249  OffsetViewType dst_offset, OffsetViewType src_offset) :
3250  src_ (src),
3251  dst_ (dst),
3252  src_offset_ (src_offset),
3253  dst_offset_ (dst_offset)
3254  {}
3255 
3256  KOKKOS_INLINE_FUNCTION
3257  void operator () (const LocalOrdinal row) const {
3258  scalar_index_type srcPos = src_offset_(row);
3259  const scalar_index_type dstEnd = dst_offset_(row+1);
3260  scalar_index_type dstPos = dst_offset_(row);
3261  for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
3262  dst_(dstPos) = src_(srcPos);
3263  }
3264  }
3265  };
3266  }; // class CrsMatrix
3267 
3268 
3277  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic = Node::classic>
3278  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
3280  size_t maxNumEntriesPerRow = 0,
3281  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
3282  {
3284  return Teuchos::rcp (new matrix_type (map, maxNumEntriesPerRow,
3285  DynamicProfile, params));
3286  }
3287 
3339  template<class CrsMatrixType>
3340  Teuchos::RCP<CrsMatrixType>
3341  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3342  const Import<typename CrsMatrixType::local_ordinal_type,
3343  typename CrsMatrixType::global_ordinal_type,
3344  typename CrsMatrixType::node_type>& importer,
3345  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3346  typename CrsMatrixType::global_ordinal_type,
3347  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
3348  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3349  typename CrsMatrixType::global_ordinal_type,
3350  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
3351  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
3352  {
3353  Teuchos::RCP<CrsMatrixType> destMatrix;
3354  sourceMatrix->importAndFillComplete (destMatrix,importer, domainMap, rangeMap, params);
3355  return destMatrix;
3356  }
3357 
3391  template<class CrsMatrixType>
3392  Teuchos::RCP<CrsMatrixType>
3393  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3394  const Export<typename CrsMatrixType::local_ordinal_type,
3395  typename CrsMatrixType::global_ordinal_type,
3396  typename CrsMatrixType::node_type>& exporter,
3397  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3398  typename CrsMatrixType::global_ordinal_type,
3399  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
3400  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3401  typename CrsMatrixType::global_ordinal_type,
3402  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
3403  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
3404  {
3405  Teuchos::RCP<CrsMatrixType> destMatrix;
3406  sourceMatrix->exportAndFillComplete (destMatrix,exporter, domainMap, rangeMap, params);
3407  return destMatrix;
3408  }
3409 } // namespace Tpetra
3410 
3418 #endif // TPETRA_CRSMATRIX_DECL_HPP
size_t getLocalLength() const
Local number of rows on the calling process.
LocalOrdinal sumIntoLocalValues(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Sum into one or more sparse matrix entries, using local indices.
Kokkos::CrsMatrix< impl_scalar_type, LocalOrdinal, execution_space, void, typename local_graph_type::size_type > local_matrix_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
std::string description() const
A one-line description of this object.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
void reindexColumns(crs_graph_type *const graph, const Teuchos::RCP< const map_type > &newColMap, const Teuchos::RCP< const import_type > &newImport=Teuchos::null, const bool sortEachRow=true)
Reindex the column indices in place, and replace the column Map. Optionally, replace the Import objec...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Teuchos::RCP< node_type > getNode() const
The Kokkos Node instance.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Teuchos::ArrayView< const impl_scalar_type > getView(RowInfo rowinfo) const
Constant view of all entries (including extra space) in the given row.
void getLocalRowCopy(LocalOrdinal localRow, const Teuchos::ArrayView< LocalOrdinal > &colInds, const Teuchos::ArrayView< Scalar > &vals, size_t &numEntries) const
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
LocalOrdinal local_ordinal_type
This class&#39; second template parameter; the type of local indices.
void checkInternalState() const
Check that this object&#39;s state is sane; throw if it&#39;s not.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix&#39;s graph, as a CrsGraph.
void sortEntries()
Sort the entries of each row by their column indices.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
This matrix&#39;s graph, as a RowGraph.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
virtual void copyAndPermute(const SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteToLIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
void gaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
"Hybrid" Jacobi + (Gauss-Seidel or SOR) on .
Teuchos::RCP< const map_type > getRowMap() const
The Map that describes the row distribution in this matrix.
LocalOrdinal sumIntoGlobalValues(const GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Sum into one or more sparse matrix entries, using global indices.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &x)
Details::EStorageStatus storageStatus_
Status of the matrix&#39;s storage, when not in a fill-complete state.
void getGlobalRowView(GlobalOrdinal GlobalRow, Teuchos::ArrayView< const GlobalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const
Get a constant, nonpersisting view of a row of this matrix, using global row and column indices...
Teuchos::RCP< const map_type > getColMap() const
The Map that describes the column distribution in this matrix.
One or more distributed dense vectors.
GlobalOrdinal global_ordinal_type
This class&#39; third template parameter; the type of global indices.
void mergeRedundantEntries()
Merge entries in each row with the same column indices.
bool isLocallyIndexed() const
Whether the matrix is locally indexed on the calling process.
virtual bool supportsRowViews() const
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
bool isUpperTriangular() const
Indicates whether the matrix is upper triangular.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the matrix&#39;s column Map with the given Map.
virtual bool checkSizes(const SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
void setAllValues(const typename local_matrix_type::row_map_type &rowPointers, const typename local_graph_type::entries_type::non_const_type &columnIndices, const typename local_matrix_type::values_type &values)
Sets the 1D pointer arrays of the graph.
size_t getNodeNumRows() const
The number of matrix rows owned by the calling process.
Node node_type
This class&#39; fourth template parameter; the Kokkos device type.
bool fillComplete_
Whether the matrix is fill complete.
Node::device_type device_type
The Kokkos device type.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
GlobalOrdinal getIndexBase() const
The index base for global indices for this matrix.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const Teuchos::ArrayView< GlobalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization suitable for this CrsMatrix specialization.
int local_ordinal_type
Default value of LocalOrdinal template parameter.
local_matrix_type::row_map_type t_RowPtrs TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type::row_map_type instead.
Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > getVector(const size_t j) const
Return a Vector which is a const view of column j.
local_matrix_type::values_type getLocalValuesView() const
Get the Kokkos local values.
Teuchos::RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node, classic > > convert() const
Return another CrsMatrix with the same entries, but converted to a different Scalar type T...
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes owning zero rows from the Maps and their communicator.
void insertLocalValues(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using local indices.
void getLocalRowView(LocalOrdinal LocalRow, Teuchos::ArrayView< const LocalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices...
device_type::execution_space execution_space
The Kokkos execution space.
mag_type frobNorm_
Cached Frobenius norm of the (global) matrix.
void localGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const RangeScalar &dampingFactor, const KokkosClassic::ESweepDirection direction) const
Gauss-Seidel or SOR on .
void insertGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using global indices.
void fillLocalMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local matrix.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &importer, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
size_t global_size_t
Global size_t object.
Kokkos::StaticCrsGraph< LocalOrdinal, Kokkos::LayoutLeft, execution_space > local_graph_type
The type of the part of the sparse graph on each MPI process.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &diag) const
Get a copy of the diagonal entries of the matrix.
void localMultiply(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &Y, Teuchos::ETransp mode, RangeScalar alpha, RangeScalar beta) const
Compute a sparse matrix-MultiVector product local to each process.
dual_view_type getDualView() const
Get the Kokkos::DualView which implements local storage.
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
bool isLowerTriangular() const
Indicates whether the matrix is lower triangular.
local_matrix_type::values_type t_ValuesType TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type::values_type instead.
ESweepDirection
Sweep direction for Gauss-Seidel or Successive Over-Relaxation (SOR).
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas)
Allocate values (and optionally indices) using the Node.
LocalOrdinal replaceLocalValues(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace one or more entries&#39; values, using local indices.
Teuchos::RCP< const map_type > getDomainMap() const
The domain Map of this matrix.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
local_matrix_type::row_map_type::non_const_type t_RowPtrsNC TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type::row_map_type::non_const_type instead.
bool isFillComplete() const
Whether the matrix is fill complete.
void scale(const Scalar &alpha)
Scale the matrix&#39;s values: this := alpha*this.
void resumeFill(const RCP< ParameterList > &params=null)
Resume operations that may change the values or structure of the matrix.
void unpackAndCombine(const Teuchos::ArrayView< const LocalOrdinal > &importLIDs, const Teuchos::ArrayView< const char > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode combineMode)
Unpack the imported column indices and values, and combine into matrix.
Sets up and executes a communication plan for a Tpetra DistObject.
void reorderedGaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
Reordered "Hybrid" Jacobi + (Gauss-Seidel or SOR) on .
CombineMode
Rule for combining data in an Import or Export.
bool isStorageOptimized() const
Returns true if storage has been optimized.
void exportAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > &destMatrix, const export_type &exporter, const Teuchos::RCP< const map_type > &domainMap=Teuchos::null, const Teuchos::RCP< const map_type > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Export from this to the given destination matrix, and make the result fill complete.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
local_matrix_type getLocalMatrix() const
The local sparse matrix.
ProfileType getProfileType() const
Returns true if the matrix was allocated with static data structures.
virtual ~CrsMatrix()
Destructor.
Abstract base class for objects that can be the source of an Import or Export operation.
crs_graph_type::local_graph_type local_graph_type
The part of the sparse matrix&#39;s graph on each MPI process.
double scalar_type
Default value of Scalar template parameter.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
void reorderedLocalGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const RangeScalar &dampingFactor, const KokkosClassic::ESweepDirection direction) const
Reordered Gauss-Seidel or SOR on .
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
void replaceDomainMapAndImporter(const Teuchos::RCP< const map_type > &newDomainMap, Teuchos::RCP< const import_type > &newImporter)
Replace the current domain Map and Import with the given objects.
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
bool hasTransposeApply() const
Whether apply() allows applying the transpose or conjugate transpose.
void computeGlobalConstants()
Compute matrix properties that require collectives.
bool isFillActive() const
Whether the matrix is not fill complete.
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
void localSolve(const MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &Y, MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, Teuchos::ETransp mode) const
Solves a linear system when the underlying matrix is locally triangular.
global_size_t getGlobalNumCols() const
The number of global columns in the matrix.
bool hasColMap() const
Indicates whether the matrix has a well-defined column map.
mag_type getFrobeniusNorm() const
Compute and return the Frobenius norm of the matrix.
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
LocalOrdinal replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace one or more entries&#39; values, using global indices.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node2, Node2::classic > > clone(const Teuchos::RCP< Node2 > &node2, const Teuchos::RCP< Teuchos::ParameterList > &params=null) const
Create a deep copy of this CrsMatrix, where the copy may have a different Node type.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
Scalar scalar_type
This class&#39; first template parameter; the type of each entry in the matrix.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &x)
local_matrix_type k_local_matrix_type TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type instead.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply() and gaussSeidel().
local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED
DEPRECATED; use local_graph_type::entries_type::non_const_type instead.
Describes a parallel distribution of objects over processes.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
global_size_t getGlobalNumEntries() const
The global number of entries in this matrix.
A read-only, row-oriented interface to a sparse matrix.
std::map< GlobalOrdinal, std::pair< Teuchos::Array< GlobalOrdinal >, Teuchos::Array< Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
A distributed dense vector.
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.
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
void expertStaticFillComplete(const RCP< const map_type > &domainMap, const RCP< const map_type > &rangeMap, const RCP< const import_type > &importer=Teuchos::null, const RCP< const export_type > &exporter=Teuchos::null, const RCP< ParameterList > &params=Teuchos::null)
Perform a fillComplete on a matrix that already has data.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
size_t getNumVectors() const
Number of columns in the multivector.
CrsGraph< LocalOrdinal, GlobalOrdinal, Node, classic > crs_graph_type
The CrsGraph specialization suitable for this CrsMatrix specialization.
void globalAssemble()
Communicate nonlocal contributions to other processes.
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
void gaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of gaussSeidel(), with fewer requirements on X.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
Special case of apply() for mode == Teuchos::NO_TRANS.
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > createCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Non-member function to create an empty CrsMatrix given a row map and a non-zero profile.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The Map specialization suitable for this CrsMatrix specialization.
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Compute a sparse matrix-MultiVector multiply.
size_t getNodeNumCols() const
The number of columns connected to the locally owned rows of this matrix.
Teuchos::ArrayView< impl_scalar_type > getViewNonConst(RowInfo rowinfo)
Nonconst view of all entries (including extra space) in the given row.
void reorderedGaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of reorderedGaussSeidel(), with fewer requirements on X.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
Base class for distributed Tpetra objects that support data redistribution.
size_t getNodeNumEntries() const
The local number of entries in this matrix.
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, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params) const
Implementation of RowMatrix::add: return alpha*A + beta*this.
void clearGlobalConstants()
Clear matrix properties that require collectives.
bool isGloballyIndexed() const
Whether the matrix is globally indexed on the calling process.
EStorageStatus
Status of the graph&#39;s or matrix&#39;s storage, when not in a fill-complete state.
void applyTranspose(const MV &X_in, MV &Y_in, const Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
Special case of apply() for mode != Teuchos::NO_TRANS.
void fillComplete(const RCP< const map_type > &domainMap, const RCP< const map_type > &rangeMap, const RCP< ParameterList > &params=null)
Signal that data entry is complete, specifying domain and range maps.
local_matrix_type lclMatrix_
The local sparse matrix.
void importAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > &destMatrix, const import_type &importer, const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Import from this to the given destination matrix, and make the result fill complete.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local graph and matrix.
Teuchos::RCP< const map_type > getRangeMap() const
The range Map of this matrix.
RowInfo getRowInfo(const size_t myRow) const
Get information about the locally owned row with local index myRow.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.