Tpetra Matrix/Vector Services  Version of the Day
Tpetra_CrsGraph_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_CRSGRAPH_DECL_HPP
43 #define TPETRA_CRSGRAPH_DECL_HPP
44 
46 #include <Teuchos_Describable.hpp>
47 #include <Teuchos_ParameterListAcceptorDefaultBase.hpp>
48 
49 #include <Kokkos_DefaultNode.hpp>
50 #include <Kokkos_DefaultKernels.hpp>
51 
52 #include "Tpetra_ConfigDefs.hpp"
53 #include "Tpetra_RowGraph.hpp"
54 #include "Tpetra_DistObject.hpp"
55 #include "Tpetra_Exceptions.hpp"
56 
57 
58 namespace Tpetra {
59 
60 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61  // forward declaration
62  template <class S, class LO, class GO, class N, class SpMatOps>
63  class CrsMatrix;
64 #endif
65 
74  struct RowInfo {
75  size_t localRow;
76  size_t allocSize;
77  size_t numEntries;
78  size_t offset1D;
79  };
80 
81  enum ELocalGlobal {
82  LocalIndices,
83  GlobalIndices
84  };
85 
163  template <class LocalOrdinal,
164  class GlobalOrdinal = LocalOrdinal,
165  class Node = Kokkos::DefaultNode::DefaultNodeType,
166  class LocalMatOps = typename Kokkos::DefaultKernels<void,LocalOrdinal,Node>::SparseOps >
167  class CrsGraph :
168  public RowGraph<LocalOrdinal,GlobalOrdinal,Node>,
169  public DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>,
171  {
172  template <class S, class LO, class GO, class N, class SpMatOps>
173  friend class CrsMatrix;
174  template <class LO2, class GO2, class N2, class SpMatOps2>
175  friend class CrsGraph;
176 
177  public:
178  typedef LocalOrdinal local_ordinal_type;
179  typedef GlobalOrdinal global_ordinal_type;
180  typedef Node node_type;
182 
184 
185 
203  CrsGraph (const RCP<const map_type>& rowMap,
204  size_t maxNumEntriesPerRow,
205  ProfileType pftype = DynamicProfile,
206  const RCP<ParameterList>& params = null);
207 
225  CrsGraph (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
226  const ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
227  ProfileType pftype = DynamicProfile,
228  const RCP<ParameterList>& params = null);
229 
249  CrsGraph (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
250  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
251  size_t maxNumEntriesPerRow,
252  ProfileType pftype = DynamicProfile,
253  const RCP<ParameterList>& params = null);
254 
274  CrsGraph (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
275  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
276  const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc,
277  ProfileType pftype = DynamicProfile,
278  const RCP<ParameterList>& params = null);
279 
299  CrsGraph (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
300  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
301  const ArrayRCP<size_t> & rowPointers,
302  const ArrayRCP<LocalOrdinal> & columnIndices,
303  const RCP<ParameterList>& params = null);
304 
305 
333  template<class Node2>
334  RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node2,
335  typename Kokkos::DefaultKernels<void, LocalOrdinal, Node2>::SparseOps> >
336  clone (const Teuchos::RCP<Node2> &node2,
337  const Teuchos::RCP<Teuchos::ParameterList> &params = null) const
338  {
339  using Teuchos::arcp;
340  using Teuchos::ArrayRCP;
341  using Teuchos::RCP;
343  using std::endl;
344  typedef CrsGraph<LocalOrdinal, GlobalOrdinal, Node2,
345  typename Kokkos::DefaultKernels<void,LocalOrdinal,Node2>::SparseOps> CrsGraph2;
347  const char tfecfFuncName[] = "clone()";
348 
349  bool fillCompleteClone = true;
350  bool useLocalIndices = hasColMap();
351  ProfileType pftype = StaticProfile;
352  if (! params.is_null ()) {
353  fillCompleteClone = params->get ("fillComplete clone", fillCompleteClone);
354  useLocalIndices = params->get ("Locally indexed clone", useLocalIndices);
355  if (params->get ("Static profile clone",true) == false) {
356  pftype = DynamicProfile;
357  }
358  }
359 
361  hasColMap() == false && useLocalIndices == true,
362  std::runtime_error,
363  ": You asked clone() to use local indices (by setting the \"Locally "
364  "indexed clone\" parameter to true), but the source graph does not "
365  "yet have a column Map, so this is impossible.");
366 
367  RCP<const Map2> clonedRowMap = rowMap_->template clone<Node2> (node2);
368  RCP<CrsGraph2> clonedGraph;
369  ArrayRCP<const size_t> numEntries;
370  size_t numEntriesForAll = 0;
371  if (indicesAreAllocated() == false) {
372  if (numAllocPerRow_ != null) {
373  numEntries = numAllocPerRow_;
374  }
375  else {
376  numEntriesForAll = numAllocForAllRows_;
377  }
378  }
379  else if (numRowEntries_ != null) {
380  numEntries = numRowEntries_;
381  }
382  else if (nodeNumAllocated_ == 0) {
383  numEntriesForAll = 0;
384  }
385  else {
386  // left with the case that we have optimized storage. in this case, we have to construct a list of row sizes.
388  getProfileType() != StaticProfile, std::logic_error,
389  "Internal logic error. Please report this to Tpetra team.");
390  const size_t numRows = getNodeNumRows();
391  numEntriesForAll = 0;
392  ArrayRCP<size_t> numEnt;
393  if (numRows) {
394  numEnt = arcp<size_t> (numRows);
395  }
396  for (size_t i=0; i<numRows; ++i) {
397  numEnt[i] = rowPtrs_[i+1] - rowPtrs_[i];
398  }
399  numEntries = numEnt;
400  }
401 
402  RCP<ParameterList> graphparams = sublist(params,"CrsGraph");
403  if (useLocalIndices) {
404  RCP<const Map2> clonedColMap = colMap_->template clone<Node2>(node2);
405  if (numEntries == null) {
406  clonedGraph = rcp (new CrsGraph2 (clonedRowMap, clonedColMap, numEntriesForAll, pftype, graphparams));
407  }
408  else {
409  clonedGraph = rcp (new CrsGraph2 (clonedRowMap, clonedColMap, numEntries, pftype, graphparams));
410  }
411  }
412  else {
413  if (numEntries.is_null ()) {
414  clonedGraph = rcp (new CrsGraph2 (clonedRowMap, numEntriesForAll, pftype, graphparams));
415  }
416  else {
417  clonedGraph = rcp (new CrsGraph2 (clonedRowMap, numEntries, pftype, graphparams));
418  }
419  }
420  // done with these
421  numEntries = null;
422  numEntriesForAll = 0;
423 
424  if (useLocalIndices) {
425  clonedGraph->allocateIndices(LocalIndices);
426  if (this->isLocallyIndexed ()) {
428  for (LocalOrdinal lrow = rowMap_->getMinLocalIndex ();
429  lrow <= rowMap_->getMaxLocalIndex ();
430  ++lrow) {
431  this->getLocalRowView (lrow, linds);
432  if (linds.size ()) {
433  clonedGraph->insertLocalIndices (lrow, linds);
434  }
435  }
436  }
437  else { // this->isGloballyIndexed()
438  Array<LocalOrdinal> linds;
439  for (LocalOrdinal lrow = rowMap_->getMinLocalIndex();
440  lrow <= rowMap_->getMaxLocalIndex();
441  ++lrow) {
442  size_t theNumEntries;
443  linds.resize (this->getNumEntriesInLocalRow (lrow));
444  this->getLocalRowCopy (rowMap_->getGlobalElement (lrow), linds (), theNumEntries);
445  if (theNumEntries) {
446  clonedGraph->insertLocalIndices (lrow, linds (0, theNumEntries));
447  }
448  }
449  }
450  }
451  else { /* useGlobalIndices */
452  clonedGraph->allocateIndices (GlobalIndices);
453  if (this->isGloballyIndexed ()) {
455  for (GlobalOrdinal grow = rowMap_->getMinGlobalIndex();
456  grow <= rowMap_->getMaxGlobalIndex();
457  ++grow) {
458  this->getGlobalRowView (grow, ginds);
459  if (ginds.size ()) {
460  clonedGraph->insertGlobalIndices (grow, ginds);
461  }
462  }
463  }
464  else { // this->isLocallyIndexed()
465  Array<GlobalOrdinal> ginds;
466  for (GlobalOrdinal grow = rowMap_->getMinGlobalIndex();
467  grow <= rowMap_->getMaxGlobalIndex();
468  ++grow) {
469  size_t theNumEntries;
470  ginds.resize (this->getNumEntriesInGlobalRow (grow));
471  this->getGlobalRowCopy (grow, ginds (), theNumEntries);
472  if (theNumEntries) {
473  clonedGraph->insertGlobalIndices (grow, ginds (0,theNumEntries));
474  }
475  }
476  }
477  }
478 
479  if (fillCompleteClone) {
480  RCP<ParameterList> fillparams = sublist (params, "fillComplete");
481  try {
482  RCP<const Map2> clonedRangeMap;
483  RCP<const Map2> clonedDomainMap;
484  if (rangeMap_ != null && rangeMap_ != rowMap_) {
485  clonedRangeMap = rangeMap_->template clone<Node2>(node2);
486  }
487  else {
488  clonedRangeMap = clonedRowMap;
489  }
490  if (domainMap_ != null && domainMap_ != rowMap_) {
491  clonedDomainMap = domainMap_->template clone<Node2>(node2);
492  }
493  else {
494  clonedDomainMap = clonedRowMap;
495  }
496  clonedGraph->fillComplete (clonedDomainMap, clonedRangeMap, fillparams);
497  }
498  catch (std::exception &e) {
499  const bool caughtExceptionOnClone = true;
501  caughtExceptionOnClone, std::runtime_error,
502  ": Caught the following exception while calling fillComplete() on "
503  "clone of type" << endl << Teuchos::typeName (*clonedGraph)
504  << endl << ":" << endl << e.what() << endl);
505  }
506  }
507  return clonedGraph;
508  }
509 
511  virtual ~CrsGraph();
512 
514 
516 
518  void setParameterList (const RCP<ParameterList>& params);
519 
521  RCP<const ParameterList> getValidParameters () const;
522 
524 
526 
548  void
549  insertGlobalIndices (GlobalOrdinal globalRow,
550  const ArrayView<const GlobalOrdinal>& indices);
551 
553 
567  void
568  insertLocalIndices (const LocalOrdinal localRow,
569  const ArrayView<const LocalOrdinal> &indices);
570 
572 
581  void removeLocalIndices (LocalOrdinal localRow);
582 
584 
591 
597  void globalAssemble ();
598 
607  void resumeFill (const RCP<ParameterList> &params = null);
608 
626  void
627  fillComplete (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &domainMap,
628  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &rangeMap,
629  const RCP<ParameterList> &params = null);
630 
637  void fillComplete (const RCP<ParameterList> &params = null);
638 
649  void
650  expertStaticFillComplete (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
651  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
652  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
653  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
654  const RCP<ParameterList> &params=Teuchos::null);
656 
658 
660  const RCP<const Comm<int> > & getComm() const;
661 
663  RCP<Node> getNode() const;
664 
666  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getRowMap() const;
667 
669  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getColMap() const;
670 
672  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getDomainMap() const;
673 
675  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getRangeMap() const;
676 
679 
682 
684 
686  global_size_t getGlobalNumRows() const;
687 
689 
692  global_size_t getGlobalNumCols() const;
693 
695  size_t getNodeNumRows() const;
696 
698 
700  size_t getNodeNumCols() const;
701 
703  GlobalOrdinal getIndexBase() const;
704 
706 
708  global_size_t getGlobalNumEntries() const;
709 
711  size_t getNodeNumEntries() const;
712 
714 
715  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const;
716 
718 
719  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const;
720 
722 
729  size_t getNodeAllocationSize() const;
730 
732 
733  size_t getNumAllocatedEntriesInGlobalRow(GlobalOrdinal globalRow) const;
734 
736 
737  size_t getNumAllocatedEntriesInLocalRow(LocalOrdinal localRow) const;
738 
740 
742  global_size_t getGlobalNumDiags() const;
743 
745 
747  size_t getNodeNumDiags() const;
748 
761  size_t getGlobalMaxNumRowEntries() const;
762 
764 
766  size_t getNodeMaxNumRowEntries() const;
767 
782  bool hasColMap() const;
783 
791  bool isLowerTriangular() const;
792 
800  bool isUpperTriangular() const;
801 
803  bool isLocallyIndexed() const;
804 
806  bool isGloballyIndexed() const;
807 
809  bool isFillComplete() const;
810 
812  bool isFillActive() const;
813 
815 
818  bool isSorted() const;
819 
821 
827  bool isStorageOptimized() const;
828 
830  ProfileType getProfileType() const;
831 
833 
842  void getGlobalRowCopy(GlobalOrdinal GlobalRow,
843  const ArrayView<GlobalOrdinal> &Indices,
844  size_t &NumIndices
845  ) const;
846 
848 
859  void getLocalRowCopy(LocalOrdinal LocalRow,
860  const ArrayView<LocalOrdinal> &indices,
861  size_t &NumIndices
862  ) const;
863 
865 
873  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &Indices) const;
874 
876 
884  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices) const;
885 
887 
889 
891  std::string description() const;
892 
895 
897 
899 
900  virtual bool
901  checkSizes (const SrcDistObject& source);
902 
903  virtual void
904  copyAndPermute (const SrcDistObject& source,
905  size_t numSameIDs,
906  const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
907  const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs);
908 
909  virtual void
910  packAndPrepare (const SrcDistObject& source,
911  const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
913  const Teuchos::ArrayView<size_t> & numPacketsPerLID,
914  size_t& constantNumPackets,
915  Distributor &distor);
916 
917  virtual void
918  unpackAndCombine (const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
920  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
921  size_t constantNumPackets,
922  Distributor &distor,
923  CombineMode CM);
925 
927 
936  void
937  setAllIndices (const ArrayRCP<size_t> & rowPointers,
938  const ArrayRCP<LocalOrdinal> & columnIndices);
939 
941 
944  ArrayRCP<const size_t> getNodeRowPtrs() const;
945 
947 
949  ArrayRCP<const LocalOrdinal> getNodePackedIndices() const;
950 
963  void
964  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
966 
994  virtual void
997 
998  private:
999  // We forbid copy construction by declaring this method private
1000  // and not implementing it.
1002 
1003  // We forbid assignment (operator=) by declaring this method
1004  // private and not implementing it.
1006  operator= (const CrsGraph<LocalOrdinal,GlobalOrdinal,Node> &rhs);
1007 
1008  protected:
1009  typedef typename LocalMatOps::template graph<LocalOrdinal,Node>::graph_type local_graph_type;
1010 
1011  // these structs are conveniences, to cut down on the number of
1012  // arguments to some of the methods below.
1013  struct SLocalGlobalViews {
1016  };
1017  struct SLocalGlobalNCViews {
1020  };
1021  //
1022  // Allocation
1023  //
1024  bool indicesAreAllocated() const;
1025 
1026  void allocateIndices (ELocalGlobal lg);
1027 
1028  template <class T>
1029  ArrayRCP<T> allocateValues1D () const;
1030  template <class T>
1031  ArrayRCP<Array<T> > allocateValues2D () const;
1032 
1033  template <ELocalGlobal lg, class T>
1034  RowInfo updateAllocAndValues (RowInfo rowinfo, size_t allocSize, Array<T>& rowVals);
1035 
1037 
1038 
1047  void computeIndexState();
1048  void makeColMap ();
1049  void makeIndicesLocal ();
1050  void makeImportExport ();
1051 
1053 
1055 
1056  template<ELocalGlobal lg>
1057  size_t filterIndices (const SLocalGlobalNCViews &inds) const;
1058 
1059  template<class T>
1060  size_t
1061  filterGlobalIndicesAndValues (const ArrayView<GlobalOrdinal>& ginds,
1062  const ArrayView<T>& vals) const;
1063  template<class T>
1064  size_t
1065  filterLocalIndicesAndValues (const ArrayView<LocalOrdinal>& linds,
1066  const ArrayView<T>& vals) const;
1067 
1097  size_t
1098  insertIndices (const RowInfo& rowInfo,
1099  const SLocalGlobalViews& newInds,
1100  const ELocalGlobal lg,
1101  const ELocalGlobal I);
1102 
1142  template<class Scalar>
1143  void
1144  insertIndicesAndValues (const RowInfo& rowInfo,
1145  const SLocalGlobalViews& newInds,
1146  const ArrayView<Scalar>& oldRowVals,
1147  const ArrayView<const Scalar>& newRowVals,
1148  const ELocalGlobal lg,
1149  const ELocalGlobal I);
1150  void
1151  insertGlobalIndicesImpl (const LocalOrdinal myRow,
1152  const ArrayView<const GlobalOrdinal> &indices);
1153  void
1154  insertLocalIndicesImpl (const LocalOrdinal myRow,
1155  const ArrayView<const LocalOrdinal> &indices);
1157  void
1158  insertLocalIndicesFiltered (const LocalOrdinal localRow,
1159  const ArrayView<const LocalOrdinal> &indices);
1160 
1162  void
1163  insertGlobalIndicesFiltered (const GlobalOrdinal localRow,
1164  const ArrayView<const GlobalOrdinal> &indices);
1165 
1188  template<class Scalar, class BinaryFunction>
1189  void
1190  transformLocalValues (RowInfo rowInfo,
1191  const Teuchos::ArrayView<Scalar>& rowVals,
1193  const Teuchos::ArrayView<const Scalar>& newVals,
1194  BinaryFunction f) const;
1195 
1210  template<class Scalar, class BinaryFunction>
1211  void
1212  transformGlobalValues (RowInfo rowInfo,
1213  const Teuchos::ArrayView<Scalar>& rowVals,
1215  const Teuchos::ArrayView<const Scalar>& newVals,
1216  BinaryFunction f) const;
1217 
1219 
1221 
1223  bool isMerged () const;
1224 
1230  void setLocallyModified ();
1231 
1233  void sortAllIndices ();
1234 
1236  void sortRowIndices (RowInfo rowinfo);
1237 
1252  template <class Scalar>
1253  void sortRowIndicesAndValues (RowInfo rowinfo, ArrayView<Scalar> values);
1254 
1263  void mergeAllIndices ();
1264 
1269  void mergeRowIndices (RowInfo rowinfo);
1270 
1271 
1282  template<class Scalar>
1283  void
1284  mergeRowIndicesAndValues (RowInfo rowinfo,
1285  const Teuchos::ArrayView<Scalar>& rowValues);
1287 
1297  void
1298  setDomainRangeMaps (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &domainMap,
1299  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &rangeMap);
1300 
1301  void staticAssertions() const;
1302  // global consts
1303  void clearGlobalConstants();
1304  void computeGlobalConstants();
1305  // graph data accessors
1306  RowInfo getRowInfo(size_t myRow) const;
1307  ArrayView<const LocalOrdinal> getLocalView(RowInfo rowinfo) const;
1308  ArrayView<LocalOrdinal> getLocalViewNonConst(RowInfo rowinfo);
1309  ArrayView<const GlobalOrdinal> getGlobalView(RowInfo rowinfo) const;
1310  ArrayView<GlobalOrdinal> getGlobalViewNonConst(RowInfo rowinfo);
1311 
1346  size_t
1347  findLocalIndex (RowInfo rowinfo,
1348  LocalOrdinal ind,
1349  size_t hint = 0) const;
1350 
1379  size_t
1380  findLocalIndex (RowInfo rowinfo,
1381  LocalOrdinal ind,
1383  size_t hint = 0) const;
1384 
1392  size_t findGlobalIndex (RowInfo rowinfo, GlobalOrdinal ind, size_t hint = 0) const;
1393 
1394  // local Kokkos objects
1395  void fillLocalGraph(const RCP<ParameterList> &params);
1396  const RCP<const local_graph_type> getLocalGraph() const;
1397  const RCP<local_graph_type> getLocalGraphNonConst();
1398  // debugging
1399  void checkInternalState() const;
1400 
1409 
1417 
1424 
1425  // local data, stored in a Kokkos::CrsGraph. only initialized after fillComplete()
1426  RCP<local_graph_type> lclGraph_;
1427 
1428  // Local and Global Counts
1429  // nodeNumEntries_ and nodeNumAllocated_ are required to be always consistent
1430  // nodeMaxNumEntries_, nodeNumDiags_ and the global quantities are computed during fillComplete() and only valid when isFillComplete()
1431  global_size_t globalNumEntries_, globalNumDiags_, globalMaxNumRowEntries_;
1432  size_t nodeNumEntries_, nodeNumDiags_, nodeMaxNumRowEntries_, nodeNumAllocated_;
1433 
1436 
1447 
1453 
1454  // graph indices. before allocation, all are null.
1455  // after allocation, except during makeIndicesLocal(), one of local or global is null.
1456  // we will never have 1D and 2D structures being non-null
1457  // this is host memory
1458  // 1D == StaticAllocation, 2D == DynamicAllocation
1460  //
1461  // 1D/Static structures
1462  //
1464 
1469  // offset to the beg entries of each row. only used for 1D (Static) allocation.
1470  // i.e., indices for row R are lclInds1D_[i] for i in [b,e) where b = rowPtrs_[R] and e = rowPtrs_[R+1]
1471  // only the first numRowEntries_[R] of these are valid
1472  // both of these are null for 2D (Dynamic) allocations
1473  // rowPtrs_ has length N+1, while numRowEntries_ has length N
1474  // we may delete this to save memory on fillComplete, if "Delete Row Pointers" is specified
1475  ArrayRCP<size_t> rowPtrs_;
1476 
1478  //
1479  // 2D/Dynamic structures.
1480  //
1482 
1485 
1488 
1494 
1495  bool indicesAreAllocated_;
1496  bool indicesAreLocal_;
1497  bool indicesAreGlobal_;
1498  bool fillComplete_;
1512 
1514  std::map<GlobalOrdinal, std::deque<GlobalOrdinal> > nonlocals_;
1515 
1516  bool haveRowInfo_;
1517 
1518  inline bool hasRowInfo() const {
1519 #ifdef HAVE_TPETRA_DEBUG
1520  bool actuallyHasRowInfo = true;
1521  if (indicesAreAllocated() && getProfileType() == StaticProfile && rowPtrs_ == null) {
1522  actuallyHasRowInfo = false;
1523  }
1525  actuallyHasRowInfo != haveRowInfo_,
1526  std::logic_error, "Internal logic error. Please contact Tpetra team.");
1527 #endif // HAVE_TPETRA_DEBUG
1528  return haveRowInfo_;
1529  }
1530  }; // class CrsGraph
1531 
1538  template <class LocalOrdinal, class GlobalOrdinal, class Node>
1541  size_t maxNumEntriesPerRow = 0,
1542  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
1543  {
1544  using Teuchos::rcp;
1546  return rcp (new graph_type (map, maxNumEntriesPerRow, DynamicProfile, params));
1547  }
1548 
1549 
1550 } // namespace Tpetra
1551 
1552 #endif
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Sparse matrix that presents a compressed sparse row interface.
A pure virtual interface for row-partitioned graphs.
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > rangeMap_
The Map describing the range of the (matrix corresponding to the) graph.
bool haveGlobalConstants_
Whether all processes have computed global constants.
ArrayRCP< const size_t > numAllocPerRow_
The maximum number of entries to allow in each locally owned row, per row.
ArrayRCP< LocalOrdinal > lclInds1D_
lclInds1D_ are the indices for all rows
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > domainMap_
The Map describing the domain of the (matrix corresponding to the) graph.
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::map< GlobalOrdinal, std::deque< GlobalOrdinal > > nonlocals_
Nonlocal data given to insertGlobalValues or sumIntoGlobalValues.
ArrayRCP< size_t > numRowEntries_
The number of local entries in each locally owned row.
size_type size() const
RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > exporter_
The Export from the row Map to the range Map.
void removeEmptyProcessesInPlace(Teuchos::RCP< DistObjectType > &input, const Teuchos::RCP< const Map< typename DistObjectType::local_ordinal_type, typename DistObjectType::global_ordinal_type, typename DistObjectType::node_type > > &newMap)
Remove processes which contain no elements in this object&#39;s Map.
Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > createCrsGraph(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 CrsGraph given a row map and a non-zero profile.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > colMap_
The Map describing the distribution of columns of the graph.
ArrayRCP< GlobalOrdinal > gblInds1D_
gblInds1D_ are the indices for all rows
size_t global_size_t
Global size_t object.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ProfileType pftype_
Whether the graph was allocated with static or dynamic profile.
bool noRedundancies_
Whether the graph&#39;s indices are non-redundant (merged) in each row, on this process.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Tpetra::Combine Mode enumerable type.
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > rowMap_
The Map describing the distribution of rows of the graph.
Abstract base class for objects that can be the source of an Import or Export operation.
bool lowerTriangular_
Whether the graph is locally lower triangular.
void resize(size_type new_size, const value_type &x=value_type())
ArrayRCP< Array< LocalOrdinal > > lclInds2D_
lclInds2D_[r] are the indices for row r.
size_t numAllocForAllRows_
The maximum number of entries to allow in each locally owned row.
RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > importer_
The Import from the domain Map to the column Map.
static const EVerbosityLevel verbLevel_default
RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node2, typename Kokkos::DefaultKernels< void, LocalOrdinal, Node2 >::SparseOps > > clone(const Teuchos::RCP< Node2 > &node2, const Teuchos::RCP< Teuchos::ParameterList > &params=null) const
Create a cloned CrsGraph for a different Node type.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Describes a parallel distribution of objects over processes.
bool upperTriangular_
Whether the graph is locally upper triangular.
bool indicesAreSorted_
Whether the graph&#39;s indices are sorted in each row, on this process.
bool haveLocalConstants_
Whether this process has computed local constants.
Base class for distributed Tpetra objects that support data redistribution.
bool is_null() const
ArrayRCP< Array< GlobalOrdinal > > gblInds2D_
gblInds2D_[r] are the indices for row r.
std::string typeName(const T &t)