Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Tpetra_CrsMatrix_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_CRSMATRIX_DECL_HPP
43 #define TPETRA_CRSMATRIX_DECL_HPP
44 
45 #include <Kokkos_DefaultNode.hpp>
46 #include <Kokkos_DefaultKernels.hpp>
47 
48 #include "Tpetra_ConfigDefs.hpp"
49 #include "Tpetra_RowMatrix_decl.hpp"
50 #include "Tpetra_Exceptions.hpp"
51 #include "Tpetra_DistObject.hpp"
52 #include "Tpetra_CrsGraph.hpp"
53 #include "Tpetra_Vector.hpp"
54 
55 
56 namespace Tpetra {
57 
59 
189  template <class Scalar,
190  class LocalOrdinal = int,
191  class GlobalOrdinal = LocalOrdinal,
192  class Node = Kokkos::DefaultNode::DefaultNodeType,
193  class LocalMatOps = typename Kokkos::DefaultKernels<Scalar,LocalOrdinal,Node>::SparseOps >
194  class CrsMatrix : public RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>,
195  public DistObject<char, LocalOrdinal,GlobalOrdinal,Node> {
196  public:
197  typedef Scalar scalar_type;
198  typedef LocalOrdinal local_ordinal_type;
199  typedef GlobalOrdinal global_ordinal_type;
200  typedef Node node_type;
202  // backwards compatibility defines both of these
203  typedef LocalMatOps mat_vec_type;
204  typedef LocalMatOps mat_solve_type;
205 
206  template <class S2, class LO2, class GO2, class N2, class LMO2>
207  friend class CrsMatrix;
208 
210 
211 
229  CrsMatrix (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
230  size_t maxNumEntriesPerRow,
231  ProfileType pftype = DynamicProfile,
232  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
233 
251  CrsMatrix (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
252  const ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
253  ProfileType pftype = DynamicProfile,
254  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
255 
278  CrsMatrix (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
279  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
280  size_t maxNumEntriesPerRow,
281  ProfileType pftype = DynamicProfile,
282  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
283 
306  CrsMatrix (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
307  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
308  const ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
309  ProfileType pftype = DynamicProfile,
310  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
311 
332  explicit CrsMatrix (const Teuchos::RCP<const CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> >& graph,
333  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
334 
358  CrsMatrix (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
359  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
360  const ArrayRCP<size_t> & rowPointers,
361  const ArrayRCP<LocalOrdinal> & columnIndices,
362  const ArrayRCP<Scalar> & values,
363  const RCP<ParameterList>& params = null);
364 
365 
383  template <class Node2>
384  RCP<CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2,typename Kokkos::DefaultKernels<void,LocalOrdinal,Node2>::SparseOps> >
385  clone(const RCP<Node2> &node2, const RCP<ParameterList> &params = null)
386  {
387  const char tfecfFuncName[] = "clone()";
388  bool fillCompleteClone = true;
389  bool useLocalIndices = hasColMap();
390  ProfileType pftype = StaticProfile;
391  if (params != null) fillCompleteClone = params->get("fillComplete clone",fillCompleteClone);
392  if (params != null) useLocalIndices = params->get("Locally indexed clone",useLocalIndices);
393  if (params != null && params->get("Static profile clone",true) == false) pftype = DynamicProfile;
394 
395  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
396  hasColMap() == false && useLocalIndices == true,
397  std::runtime_error,
398  ": requested clone using local indices, but source graph doesn't have a column map yet."
399  )
400 
403  RCP<const Map2> clonedRowMap = getRowMap()->template clone(node2);
404 
405  RCP<CrsMatrix2> clonedMatrix;
406  ArrayRCP<const size_t> numEntries;
407  size_t numEntriesForAll = 0;
408  if (staticGraph_->indicesAreAllocated() == false) {
409  if (staticGraph_->numAllocPerRow_ != null) numEntries = staticGraph_->numAllocPerRow_;
410  else numEntriesForAll = staticGraph_->numAllocForAllRows_;
411  }
412  else if (staticGraph_->numRowEntries_ != null) numEntries = staticGraph_->numRowEntries_;
413  else if (staticGraph_->nodeNumAllocated_ == 0) numEntriesForAll = 0;
414  else {
415  // left with the case that we have optimized storage. in this case, we have to construct a list of row sizes.
416  TEUCHOS_TEST_FOR_EXCEPTION( getProfileType() != StaticProfile, std::logic_error, "Internal logic error. Please report this to Tpetra team." )
417  const size_t numRows = getNodeNumRows();
418  numEntriesForAll = 0;
419  ArrayRCP<size_t> numEnt;
420  if (numRows) numEnt = arcp<size_t>(numRows);
421  for (size_t i=0; i<numRows; ++i) {
422  numEnt[i] = staticGraph_->rowPtrs_[i+1] - staticGraph_->rowPtrs_[i];
423  }
424  numEntries = numEnt;
425  }
426 
427  RCP<ParameterList> matrixparams = sublist(params,"CrsMatrix");
428  if (useLocalIndices) {
429  RCP<const Map2> clonedColMap = getColMap()->template clone(node2);
430  if (numEntries == null) clonedMatrix = rcp(new CrsMatrix2(clonedRowMap,clonedColMap,numEntriesForAll,pftype,matrixparams));
431  else clonedMatrix = rcp(new CrsMatrix2(clonedRowMap,clonedColMap,numEntries,pftype,matrixparams));
432  }
433  else {
434  if (numEntries == null) clonedMatrix = rcp(new CrsMatrix2(clonedRowMap,numEntriesForAll,pftype,matrixparams));
435  else clonedMatrix = rcp(new CrsMatrix2(clonedRowMap,numEntries,pftype,matrixparams));
436  }
437  // done with these
438  numEntries = null;
439  numEntriesForAll = 0;
440 
441  if (useLocalIndices)
442  {
443  clonedMatrix->allocateValues(LocalIndices,CrsMatrix2::GraphNotYetAllocated);
444  if (this->isLocallyIndexed())
445  {
446  ArrayView<const LocalOrdinal> linds;
447  ArrayView<const Scalar> vals;
448  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex();
449  lrow <= clonedRowMap->getMaxLocalIndex();
450  ++lrow)
451  {
452  this->getLocalRowView(lrow, linds, vals);
453  if (linds.size()) clonedMatrix->insertLocalValues(lrow, linds, vals);
454  }
455  }
456  else // this->isGloballyIndexed()
457  {
458  Array<LocalOrdinal> linds;
459  Array<Scalar> vals;
460  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex();
461  lrow <= clonedRowMap->getMaxLocalIndex();
462  ++lrow)
463  {
464  size_t theNumEntries;
465  linds.resize( this->getNumEntriesInLocalRow(lrow) );
466  vals.resize( linds.size() );
467  this->getLocalRowCopy(clonedRowMap->getGlobalElement(lrow), linds(), vals(), theNumEntries);
468  if (theNumEntries) clonedMatrix->insertLocalValues(lrow, linds(0,theNumEntries), vals(0,theNumEntries) );
469  }
470  }
471  }
472  else /* useGlobalIndices */
473  {
474  clonedMatrix->allocateValues(GlobalIndices,CrsMatrix2::GraphNotYetAllocated);
475  if (this->isGloballyIndexed())
476  {
477  ArrayView<const GlobalOrdinal> ginds;
478  ArrayView<const Scalar> vals;
479  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex();
480  grow <= clonedRowMap->getMaxGlobalIndex();
481  ++grow)
482  {
483  this->getGlobalRowView(grow, ginds, vals);
484  if (ginds.size()) clonedMatrix->insertGlobalValues(grow, ginds, vals);
485  }
486  }
487  else // this->isLocallyIndexed()
488  {
489  Array<GlobalOrdinal> ginds;
490  Array<Scalar> vals;
491  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex();
492  grow <= clonedRowMap->getMaxGlobalIndex();
493  ++grow)
494  {
495  size_t theNumEntries;
496  ginds.resize( this->getNumEntriesInGlobalRow(grow) );
497  vals.resize( ginds.size() );
498  this->getGlobalRowCopy(grow, ginds(), vals(), theNumEntries);
499  if (theNumEntries) clonedMatrix->insertGlobalValues(grow, ginds(0,theNumEntries), vals(0,theNumEntries) );
500  }
501  }
502  }
503 
504  if (fillCompleteClone) {
505  RCP<ParameterList> fillparams = sublist(params,"fillComplete");
506  try {
507  RCP<const Map2> clonedRangeMap;
508  RCP<const Map2> clonedDomainMap;
509  if (getRangeMap() != null && getRangeMap() != clonedRowMap) {
510  clonedRangeMap = getRangeMap()->template clone(node2);
511  }
512  else {
513  clonedRangeMap = clonedRowMap;
514  }
515  if (getDomainMap() != null && getDomainMap() != clonedRowMap) {
516  clonedDomainMap = getDomainMap()->template clone(node2);
517  }
518  else {
519  clonedDomainMap = clonedRowMap;
520  }
521  clonedMatrix->fillComplete(clonedDomainMap, clonedRangeMap, fillparams);
522  }
523  catch (std::exception &e) {
524  const bool caughtExceptionOnClone = true;
525  TEUCHOS_TEST_FOR_EXCEPTION(caughtExceptionOnClone,
526  std::runtime_error,
527  Teuchos::typeName(*this)
528  << "\ncaught the following exception while calling fillComplete() on clone of type\n"
529  << Teuchos::typeName(*clonedMatrix)
530  << "\n:"
531  << e.what()
532  << "\n");
533  }
534  }
535  return clonedMatrix;
536  }
537 
539  virtual ~CrsMatrix();
540 
542 
544 
567  //
613  void
614  insertGlobalValues (const GlobalOrdinal globalRow,
615  const ArrayView<const GlobalOrdinal>& cols,
616  const ArrayView<const Scalar>& vals);
617 
657  void
658  insertLocalValues (const LocalOrdinal localRow,
659  const ArrayView<const LocalOrdinal> &cols,
660  const ArrayView<const Scalar> &vals);
661 
663 
668  void replaceGlobalValues(GlobalOrdinal globalRow,
669  const ArrayView<const GlobalOrdinal> &cols,
670  const ArrayView<const Scalar> &vals);
671 
673 
676  void replaceLocalValues(LocalOrdinal localRow,
677  const ArrayView<const LocalOrdinal> &cols,
678  const ArrayView<const Scalar> &vals);
679 
706  void
707  sumIntoGlobalValues (const GlobalOrdinal globalRow,
708  const ArrayView<const GlobalOrdinal> &cols,
709  const ArrayView<const Scalar> &vals);
710 
719  void
720  sumIntoLocalValues (const LocalOrdinal localRow,
721  const ArrayView<const LocalOrdinal> &cols,
722  const ArrayView<const Scalar> &vals);
723 
725  void setAllToScalar(const Scalar &alpha);
726 
728  void scale(const Scalar &alpha);
729 
731 
738  void setAllValues(const ArrayRCP<size_t> & rowPointers,const ArrayRCP<LocalOrdinal> & columnIndices, const ArrayRCP<Scalar> & values);
739 
741 
743 
772  void globalAssemble();
773 
787  void resumeFill (const RCP<ParameterList>& params = null);
788 
809  void fillComplete(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &domainMap,
810  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &rangeMap,
811  const RCP<ParameterList> &params = null);
812 
825  void fillComplete(const RCP<ParameterList> &params = null);
826 
838  void
839  expertStaticFillComplete (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
840  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
841  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
842  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
843  const RCP<ParameterList> &params=Teuchos::null);
844 
857  void
858  replaceDomainMapAndImporter (const Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& newDomainMap,
859  Teuchos::RCP<const Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> >& newImporter);
860 
874  virtual void
875  removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& newMap);
876 
878 
880 
882  const RCP<const Comm<int> > & getComm() const;
883 
885  RCP<Node> getNode() const;
886 
888  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getRowMap() const;
889 
891  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getColMap() const;
892 
894  RCP<const RowGraph<LocalOrdinal,GlobalOrdinal,Node> > getGraph() const;
895 
897  RCP<const CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> > getCrsGraph() const;
898 
919 
925 
927  size_t getNodeNumRows() const;
928 
930 
932  size_t getNodeNumCols() const;
933 
935  GlobalOrdinal getIndexBase() const;
936 
939 
941  size_t getNodeNumEntries() const;
942 
944 
945  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const;
946 
948 
949  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const;
950 
952 
955 
957 
959  size_t getNodeNumDiags() const;
960 
962 
964  size_t getGlobalMaxNumRowEntries() const;
965 
967 
969  size_t getNodeMaxNumRowEntries() const;
970 
972  bool hasColMap() const;
973 
975 
977  bool isLowerTriangular() const;
978 
980 
982  bool isUpperTriangular() const;
983 
985  bool isLocallyIndexed() const;
986 
988  bool isGloballyIndexed() const;
989 
991  bool isFillComplete() const;
992 
994 
998  bool isFillActive() const;
999 
1001 
1007  bool isStorageOptimized() const;
1008 
1010  ProfileType getProfileType() const;
1011 
1013  bool isStaticGraph() const;
1014 
1016 
1022  typename ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const;
1023 
1024 
1026  virtual bool supportsRowViews() const;
1027 
1029 
1039  void getGlobalRowCopy(GlobalOrdinal GlobalRow,
1040  const ArrayView<GlobalOrdinal> &Indices,
1041  const ArrayView<Scalar> &Values,
1042  size_t &NumEntries
1043  ) const;
1044 
1046 
1058  void getLocalRowCopy(LocalOrdinal LocalRow,
1059  const ArrayView<LocalOrdinal> &Indices,
1060  const ArrayView<Scalar> &Values,
1061  size_t &NumEntries
1062  ) const;
1063 
1065 
1074  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const;
1075 
1077 
1086  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const;
1087 
1089 
1092 
1130  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
1131 
1150  void
1152  const Teuchos::ArrayView<const size_t>& offsets) const;
1153 
1156 
1159 
1161 
1163 
1212  template <class DomainScalar, class RangeScalar>
1213  void
1216  Teuchos::ETransp trans,
1217  RangeScalar alpha,
1218  RangeScalar beta) const;
1219 
1244  template <class DomainScalar, class RangeScalar>
1245  void
1249  const RangeScalar& dampingFactor,
1250  const Kokkos::ESweepDirection direction) const;
1251 
1268  template <class DomainScalar, class RangeScalar>
1269  void
1272  Teuchos::ETransp trans) const;
1273 
1275  template <class T>
1276  RCP<CrsMatrix<T,LocalOrdinal,GlobalOrdinal,Node> > convert() const;
1277 
1279 
1281 
1292  void
1295  Teuchos::ETransp mode = Teuchos::NO_TRANS,
1296  Scalar alpha = ScalarTraits<Scalar>::one(),
1297  Scalar beta = ScalarTraits<Scalar>::zero()) const;
1298 
1300  bool hasTransposeApply() const;
1301 
1305  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getDomainMap() const;
1306 
1310  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getRangeMap() const;
1311 
1313 
1315 
1380  void
1384  const Scalar& dampingFactor,
1385  const ESweepDirection direction,
1386  const int numSweeps) const;
1387 
1416  void
1420  const Scalar& dampingFactor,
1421  const ESweepDirection direction,
1422  const int numSweeps,
1423  const bool zeroInitialGuess) const;
1424 
1435  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1436  add (const Scalar& alpha,
1438  const Scalar& beta,
1439  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
1440  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
1441  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1442 
1444 
1446 
1448  std::string description() const;
1449 
1451  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
1452 
1454 
1456 
1457  virtual bool
1458  checkSizes (const SrcDistObject& source);
1459 
1460  virtual void
1461  copyAndPermute (const SrcDistObject& source,
1462  size_t numSameIDs,
1463  const ArrayView<const LocalOrdinal> &permuteToLIDs,
1464  const ArrayView<const LocalOrdinal> &permuteFromLIDs);
1465 
1466  virtual void
1467  packAndPrepare (const SrcDistObject& source,
1468  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
1469  Teuchos::Array<char>& exports,
1470  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1471  size_t& constantNumPackets,
1472  Distributor& distor);
1473 
1482  virtual void
1483  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
1484  Teuchos::Array<char>& exports,
1485  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1486  size_t& constantNumPackets,
1487  Distributor& distor) const;
1488 
1498  void
1499  unpackAndCombine (const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
1500  const Teuchos::ArrayView<const char> &imports,
1501  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
1502  size_t constantNumPackets,
1503  Distributor &distor,
1504  CombineMode combineMode);
1506 
1507  private:
1508  template<class CrsMatrixType>
1509  friend Teuchos::RCP<CrsMatrixType>
1510  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
1511  const Import<typename CrsMatrixType::local_ordinal_type,
1512  typename CrsMatrixType::global_ordinal_type,
1513  typename CrsMatrixType::node_type>& importer,
1514  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
1515  typename CrsMatrixType::global_ordinal_type,
1516  typename CrsMatrixType::node_type> >& domainMap,
1517  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
1518  typename CrsMatrixType::global_ordinal_type,
1519  typename CrsMatrixType::node_type> >& rangeMap,
1520  const Teuchos::RCP<Teuchos::ParameterList>& params);
1521 
1522  template<class CrsMatrixType>
1523  friend Teuchos::RCP<CrsMatrixType>
1524  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
1525  const Export<typename CrsMatrixType::local_ordinal_type,
1526  typename CrsMatrixType::global_ordinal_type,
1527  typename CrsMatrixType::node_type>& exporter,
1528  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
1529  typename CrsMatrixType::global_ordinal_type,
1530  typename CrsMatrixType::node_type> >& domainMap,
1531  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
1532  typename CrsMatrixType::global_ordinal_type,
1533  typename CrsMatrixType::node_type> >& rangeMap,
1534  const Teuchos::RCP<Teuchos::ParameterList>& params);
1535 
1542  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> >
1543  importAndFillComplete (const Import<LocalOrdinal, GlobalOrdinal, Node>& importer,
1544  const Teuchos::RCP<const map_type>& domainMap,
1545  const Teuchos::RCP<const map_type>& rangeMap,
1546  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1547 
1554  Teuchos::RCP<CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> >
1555  exportAndFillComplete (const Export<LocalOrdinal, GlobalOrdinal, Node>& exporter,
1556  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1557  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1558  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1559 
1560  private:
1561  // We forbid copy construction by declaring this method private
1562  // and not implementing it.
1564 
1565  // We forbid assignment (operator=) by declaring this method
1566  // private and not implementing it.
1569 
1575  void
1576  insertGlobalValuesFiltered (const GlobalOrdinal globalRow,
1577  const ArrayView<const GlobalOrdinal> &indices,
1578  const ArrayView<const Scalar> &values);
1579 
1585  void
1586  insertLocalValuesFiltered (const LocalOrdinal localRow,
1587  const ArrayView<const LocalOrdinal> &indices,
1588  const ArrayView<const Scalar> &values);
1589 
1597  void
1598  combineGlobalValues (const GlobalOrdinal globalRowIndex,
1599  const Teuchos::ArrayView<const GlobalOrdinal> columnIndices,
1600  const Teuchos::ArrayView<const Scalar> values,
1601  const Tpetra::CombineMode combineMode);
1602 
1634  template<class BinaryFunction>
1635  void
1636  transformLocalValues (LocalOrdinal localRow,
1637  const Teuchos::ArrayView<const LocalOrdinal>& indices,
1638  const Teuchos::ArrayView<const Scalar> & values,
1639  BinaryFunction f)
1640  {
1641  typedef LocalOrdinal LO;
1642  typedef GlobalOrdinal GO;
1643  typedef Node NT;
1644  using Teuchos::Array;
1645  using Teuchos::ArrayView;
1646 
1647  TEUCHOS_TEST_FOR_EXCEPTION(
1648  ! isFillActive (),
1649  std::runtime_error,
1650  "Tpetra::CrsMatrix::transformLocalValues: Fill must be active in order "
1651  "to call this method. That is, isFillActive() must return true. If "
1652  "you have already called fillComplete(), you need to call resumeFill() "
1653  "before you can replace values.");
1654  TEUCHOS_TEST_FOR_EXCEPTION(
1655  values.size () != indices.size (),
1656  std::runtime_error,
1657  "Tpetra::CrsMatrix::transformLocalValues: values.size () = "
1658  << values.size () << " != indices.size () = " << indices.size ()
1659  << ".");
1660  TEUCHOS_TEST_FOR_EXCEPTION(
1661  ! this->hasColMap (),
1662  std::runtime_error,
1663  "Tpetra::CrsMatrix::transformLocalValues: We cannot transform local "
1664  "indices without a column map.");
1665  const bool isLocalRow = getRowMap ()->isNodeLocalElement (localRow);
1666  TEUCHOS_TEST_FOR_EXCEPTION(
1667  ! isLocalRow,
1668  std::runtime_error,
1669  "Tpetra::CrsMatrix::transformLocalValues: The specified local row "
1670  << localRow << " does not belong to this process "
1671  << getRowMap ()->getComm ()->getRank () << ".");
1672 
1673  RowInfo rowInfo = staticGraph_->getRowInfo (localRow);
1674  if (indices.size () > 0) {
1675  ArrayView<Scalar> curVals = this->getViewNonConst (rowInfo);
1676  if (isLocallyIndexed ()) {
1677  staticGraph_->template transformLocalValues<Scalar, BinaryFunction> (rowInfo, curVals, indices, values, f);
1678  }
1679  else if (isGloballyIndexed ()) {
1680  // Convert the given local indices to global indices.
1681  const Map<LO, GO, NT>& colMap = * (this->getColMap ());
1682  Array<GO> gindices (indices.size ());
1683  typename ArrayView<const LO>::iterator lindit = indices.begin();
1684  typename Array<GO>::iterator gindit = gindices.begin();
1685  while (lindit != indices.end()) {
1686  // There is no need to filter out indices not in the column
1687  // Map. Those that aren't will be mapped to invalid(),
1688  // which transformGlobalValues() will ignore.
1689  *gindit++ = colMap.getGlobalElement (*lindit++);
1690  }
1691  staticGraph_->template transformGlobalValues<Scalar, BinaryFunction> (rowInfo, curVals, gindices (), values, f);
1692  }
1693  }
1694  }
1695 
1696 
1726  template<class BinaryFunction>
1727  void
1728  transformGlobalValues (GlobalOrdinal globalRow,
1729  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
1730  const Teuchos::ArrayView<const Scalar> & values,
1731  BinaryFunction f)
1732  {
1733  typedef LocalOrdinal LO;
1734  typedef GlobalOrdinal GO;
1735  typedef Node NT;
1736  using Teuchos::Array;
1737  using Teuchos::ArrayView;
1738 
1739  TEUCHOS_TEST_FOR_EXCEPTION(
1740  ! isFillActive (),
1741  std::runtime_error,
1742  "Tpetra::CrsMatrix::transformGlobalValues: Fill must be active in order "
1743  "to call this method. That is, isFillActive() must return true. If "
1744  "you have already called fillComplete(), you need to call resumeFill() "
1745  "before you can replace values.");
1746  TEUCHOS_TEST_FOR_EXCEPTION(
1747  values.size () != indices.size (),
1748  std::runtime_error,
1749  "Tpetra::CrsMatrix::transformGlobalValues: values.size () = "
1750  << values.size () << " != indices.size () = " << indices.size ()
1751  << ".");
1752 
1753  const LO lrow = this->getRowMap()->getLocalElement(globalRow);
1754 
1755  if (lrow == OTL::invalid()) {
1756  // FIXME (mfh 16 May 2013) We're using this exception to do
1757  // sumIntoGlobalValues for nonowned rows, so we might want to
1758  // avoid the overhead of constructing the fancy exception
1759  // message each time if we don't plan to use it.
1760 
1761  // The exception test macro doesn't let you pass an additional
1762  // argument to the exception's constructor, so we don't use it.
1763  std::ostringstream os;
1764  os << "transformGlobalValues: The given global row index "
1765  << globalRow << " is not owned by the calling process (rank "
1766  << this->getRowMap()->getComm()->getRank() << ").";
1767  throw Details::InvalidGlobalRowIndex<GO> (os.str (), globalRow);
1768  }
1769 
1770  RowInfo rowInfo = staticGraph_->getRowInfo (lrow);
1771  if (indices.size () > 0) {
1772  ArrayView<Scalar> curVals = this->getViewNonConst (rowInfo);
1773  if (isLocallyIndexed ()) {
1774  // Convert global indices to local indices.
1775  const Map<LO, GO, NT> &colMap = * (this->getColMap ());
1776  Array<LO> lindices (indices.size ());
1777  typename ArrayView<const GO>::iterator gindit = indices.begin();
1778  typename Array<LO>::iterator lindit = lindices.begin();
1779  while (gindit != indices.end()) {
1780  // There is no need to filter out indices not in the column
1781  // Map. Those that aren't will be mapped to invalid(),
1782  // which transformLocalValues() will ignore.
1783  *lindit++ = colMap.getLocalElement (*gindit++);
1784  }
1785  staticGraph_->template transformLocalValues<Scalar, BinaryFunction> (rowInfo, curVals, lindices (), values, f);
1786  }
1787  else if (isGloballyIndexed ()) {
1788  staticGraph_->template transformGlobalValues<Scalar, BinaryFunction> (rowInfo, curVals, indices, values, f);
1789  }
1790  }
1791  }
1792 
1793  protected:
1794  // useful typedefs
1795  typedef OrdinalTraits<LocalOrdinal> OTL;
1796  typedef ScalarTraits<Scalar> STS;
1797  typedef typename STS::magnitudeType Magnitude;
1798  typedef ScalarTraits<Magnitude> STM;
1799  typedef MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1800  typedef Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> V;
1801  typedef CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> Graph;
1802  typedef typename LocalMatOps::template bind_scalar<Scalar>::other_type sparse_ops_type;
1803  typedef typename sparse_ops_type::template graph<LocalOrdinal,Node>::graph_type local_graph_type;
1804  typedef typename sparse_ops_type::template matrix<Scalar,LocalOrdinal,Node>::matrix_type local_matrix_type;
1805 
1806  typedef Export<LocalOrdinal, GlobalOrdinal, Node> export_type;
1807  typedef Import<LocalOrdinal, GlobalOrdinal, Node> import_type;
1808 
1809  // Enums
1810  enum GraphAllocationStatus {
1811  GraphAlreadyAllocated,
1812  GraphNotYetAllocated
1813  };
1814 
1831  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas);
1832 
1838  void sortEntries();
1839 
1845  void mergeRedundantEntries();
1846 
1854  void clearGlobalConstants();
1855 
1864  void computeGlobalConstants();
1865 
1878  mutable Teuchos::RCP<MV> importMV_;
1879 
1892  mutable Teuchos::RCP<MV> exportMV_;
1893 
1913  Teuchos::RCP<MV>
1914  getColumnMapMultiVector (const MV& X_domainMap,
1915  const bool force = false) const;
1916 
1938  Teuchos::RCP<MV>
1939  getRowMapMultiVector (const MV& Y_rangeMap,
1940  const bool force = false) const;
1941 
1943  void
1944  applyNonTranspose (const MV& X_in,
1945  MV& Y_in,
1946  Scalar alpha,
1947  Scalar beta) const;
1948 
1950  void
1951  applyTranspose (const MV& X_in,
1952  MV& Y_in,
1953  const Teuchos::ETransp mode,
1954  Scalar alpha,
1955  Scalar beta) const;
1956 
1957  // matrix data accessors
1958  ArrayView<const Scalar> getView(RowInfo rowinfo) const;
1959  ArrayView< Scalar> getViewNonConst(RowInfo rowinfo);
1960  // local Kokkos objects
1961 
1967  void fillLocalMatrix(const RCP<ParameterList> &params);
1973  void fillLocalGraphAndMatrix(const RCP<ParameterList> &params);
1974  // debugging
1975  void checkInternalState() const;
1976 
1988 
1989  RCP<const Graph> staticGraph_;
1990  RCP< Graph> myGraph_;
1992 
1997  RCP<sparse_ops_type> lclMatOps_;
2004  RCP<local_matrix_type> lclMatrix_;
2005 
2018 
2019  ArrayRCP<Scalar> values1D_;
2020  ArrayRCP<Array<Scalar> > values2D_;
2022 
2023  // TODO: these could be allocated at resumeFill() and de-allocated at fillComplete() to make for very fast getView()/getViewNonConst()
2024  // ArrayRCP< typedef ArrayRCP<const Scalar>::iterator > rowPtrs_;
2025  // ArrayRCP< typedef ArrayRCP< Scalar>::iterator > rowPtrsNC_;
2026 
2029 
2042  std::map<GlobalOrdinal, Array<std::pair<GlobalOrdinal,Scalar> > > nonlocals_;
2043 
2050  mutable Magnitude frobNorm_;
2051  }; // class CrsMatrix
2052 
2059  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
2060  Teuchos::RCP<CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
2061  createCrsMatrix (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
2062  size_t maxNumEntriesPerRow = 0,
2063  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2064  {
2065  using Teuchos::rcp;
2067  return rcp (new matrix_type (map, maxNumEntriesPerRow, DynamicProfile, params));
2068  }
2069 
2121  template<class CrsMatrixType>
2122  Teuchos::RCP<CrsMatrixType>
2123  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
2124  const Import<typename CrsMatrixType::local_ordinal_type,
2125  typename CrsMatrixType::global_ordinal_type,
2126  typename CrsMatrixType::node_type>& importer,
2127  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
2128  typename CrsMatrixType::global_ordinal_type,
2129  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
2130  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
2131  typename CrsMatrixType::global_ordinal_type,
2132  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
2133  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2134  {
2135  return sourceMatrix->importAndFillComplete (importer, domainMap, rangeMap, params);
2136  }
2137 
2171  template<class CrsMatrixType>
2172  Teuchos::RCP<CrsMatrixType>
2173  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
2174  const Export<typename CrsMatrixType::local_ordinal_type,
2175  typename CrsMatrixType::global_ordinal_type,
2176  typename CrsMatrixType::node_type>& exporter,
2177  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
2178  typename CrsMatrixType::global_ordinal_type,
2179  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
2180  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
2181  typename CrsMatrixType::global_ordinal_type,
2182  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
2183  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2184  {
2185  return sourceMatrix->exportAndFillComplete (exporter, domainMap, rangeMap, params);
2186  }
2187 } // namespace Tpetra
2188 
2199 #endif
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
void localGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const RangeScalar &dampingFactor, const Kokkos::ESweepDirection direction) const
Gauss-Seidel or SOR on .
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row 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.
void sortEntries()
Sort the entries of each row by their column indices.
RCP< Node > getNode() const
Returns the underlying node.
Sparse matrix that presents a compressed sparse row interface.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
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 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 mergeRedundantEntries()
Merge entries in each row with the same column indices.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
virtual void packAndPrepare(const SrcDistObject &source, const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< char > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor)
Perform any packing or preparation required for communication.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
One or more distributed dense vectors.
void insertGlobalValues(const GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using global indices.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
bool fillComplete_
Whether the matrix is fill complete.
RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Returns another CrsMatrix with the same entries, but represented as a different scalar type...
void globalAssemble()
Communicate nonlocal contributions to other processes.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using local IDs.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
void fillLocalMatrix(const RCP< ParameterList > &params)
Fill data into the local matrix.
void setAllValues(const ArrayRCP< size_t > &rowPointers, const ArrayRCP< LocalOrdinal > &columnIndices, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
void gaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
&quot;Hybrid&quot; Jacobi + (Gauss-Seidel or SOR) on .
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
Remove processes owning zero rows from the Maps and their communicator.
RCP< sparse_ops_type > lclMatOps_
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > 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.
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.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Compute a sparse matrix-MultiVector multiply.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
The domain Map of this operator.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getRangeMap() const
The range Map of this operator.
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix. ...
bool isUpperTriangular() const
Indicates whether the matrix is upper triangular.
void fillLocalGraphAndMatrix(const RCP< ParameterList > &params)
Fill data into the local graph and matrix.
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
Special case of apply() for mode == Teuchos::NO_TRANS.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
RCP< local_matrix_type > lclMatrix_
ESweepDirection
Sweep direction for Gauss-Seidel or Successive Over-Relaxation (SOR).
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &params=Teuchos::null)
Perform a fillComplete on a matrix that already has data.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using global IDs.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null)
Signal that data entry is complete, specifying domain and range maps.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
std::map< GlobalOrdinal, Array< std::pair< GlobalOrdinal, Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Tpetra::Combine Mode enumerable type.
void localSolve(const MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, Teuchos::ETransp trans) const
Solves a linear system when the underlying matrix is triangular.
std::string description() const
A simple one-line description of this object.
bool isFillActive() const
Returns true if the matrix is in edit mode.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
Abstract base class for objects that can be the source of an Import or Export operation.
virtual bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
void gaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of gaussSeidel(), with fewer requirements on X.
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 clearGlobalConstants()
Clear matrix properties that require collectives.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
ProfileType getProfileType() const
Returns true if the matrix was allocated with static data structures.
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.
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
virtual ~CrsMatrix()
Destructor.
Magnitude frobNorm_
Cached Frobenius norm of the (global) matrix.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getColMap() const
Returns the Map that describes the column distribution in this matrix.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Describes a parallel distribution of objects over processes.
bool isLowerTriangular() const
Indicates whether the matrix is lower triangular.
A read-only, row-oriented interface to a sparse matrix.
void computeGlobalConstants()
Compute matrix properties that require collectives.
A distributed dense vector.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Tpetra::Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replace the current domain Map and Import with the given objects.
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 resumeFill(const RCP< ParameterList > &params=null)
Resume operations that may change the values or structure of the matrix.
bool hasColMap() const
Indicates whether the matrix has a well-defined column map.
bool hasTransposeApply() const
Whether apply() allows applying the transpose or conjugate transpose.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply() and gaussSeidel().
void localMultiply(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp trans, RangeScalar alpha, RangeScalar beta) const
Compute a sparse matrix-MultiVector product local to each process.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
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.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
Base class for distributed Tpetra objects that support data redistribution.
bool isStorageOptimized() const
Returns true if storage has been optimized.
void 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.
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas)
Allocate values (and optionally indices) using the Node.
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
Implementation of SrcDistObjectWithPack.
virtual bool checkSizes(const SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
const RCP< const Comm< int > > & getComm() const
Returns the communicator.
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node2, typename Kokkos::DefaultKernels< void, LocalOrdinal, Node2 >::SparseOps > > clone(const RCP< Node2 > &node2, const RCP< ParameterList > &params=null)
Create a cloned CrsMatrix for a different node type.
RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.