42 #ifndef TPETRA_CRSGRAPH_DECL_HPP 43 #define TPETRA_CRSGRAPH_DECL_HPP 53 #include "Tpetra_ConfigDefs.hpp" 54 #include "Tpetra_RowGraph.hpp" 55 #include "Tpetra_DistObject.hpp" 56 #include "Tpetra_Exceptions.hpp" 58 #include "KokkosCompat_ClassicNodeAPI_Wrapper.hpp" 59 #include "Kokkos_DualView.hpp" 60 #include "Kokkos_StaticCrsGraph.hpp" 62 #include "Teuchos_Describable.hpp" 63 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp" 68 #ifndef DOXYGEN_SHOULD_SKIP_THIS 74 template <
class LO,
class GO,
class N, const
bool isClassic>
78 template <
class S,
class LO,
class GO,
class N, const
bool isClassic>
81 namespace Experimental {
83 template<
class S,
class LO,
class GO,
class N>
89 template<
class OutputCrsGraphType,
class InputCrsGraphType>
90 class CrsGraphCopier {
92 static Teuchos::RCP<OutputCrsGraphType>
93 clone (
const InputCrsGraphType& graphIn,
94 const Teuchos::RCP<typename OutputCrsGraphType::node_type> nodeOut,
95 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
98 #endif // DOXYGEN_SHOULD_SKIP_THIS 227 class GlobalOrdinal = Details::DefaultTypes::global_ordinal_type,
229 const bool classic = Node::classic>
231 public RowGraph<LocalOrdinal, GlobalOrdinal, Node>,
236 public Teuchos::ParameterListAcceptorDefaultBase
238 static_assert (! classic,
"The 'classic' version of Tpetra was deprecated long ago, and has been removed.");
240 template <
class S,
class LO,
class GO,
class N, const
bool isClassic>
242 template <
class LO2,
class GO2,
class N2, const
bool isClassic>
244 template <
class S,
class LO,
class GO,
class N>
245 friend class ::Tpetra::Experimental::BlockCrsMatrix;
264 typedef Kokkos::StaticCrsGraph<LocalOrdinal,
275 typedef typename local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D
TPETRA_DEPRECATED;
305 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
306 size_t maxNumEntriesPerRow,
308 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
327 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
328 const Kokkos::DualView<const size_t*, execution_space>& numEntPerRow,
330 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
350 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
351 const Teuchos::ArrayRCP<const size_t>& numEntPerRow,
353 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
376 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
377 const Teuchos::RCP<const map_type>& colMap,
378 const size_t maxNumEntriesPerRow,
380 const Teuchos::RCP<Teuchos::ParameterList>& params = null);
400 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
401 const Teuchos::RCP<const map_type>& colMap,
402 const Kokkos::DualView<const size_t*, execution_space>& numEntPerRow,
404 const Teuchos::RCP<Teuchos::ParameterList>& params = null);
425 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
426 const Teuchos::RCP<const map_type>& colMap,
427 const Teuchos::ArrayRCP<const size_t>& numEntPerRow,
429 const Teuchos::RCP<Teuchos::ParameterList>& params = null);
450 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
451 const Teuchos::RCP<const map_type>& colMap,
452 const typename local_graph_type::row_map_type& rowPointers,
453 const typename local_graph_type::entries_type::non_const_type& columnIndices,
454 const Teuchos::RCP<Teuchos::ParameterList>& params = null);
475 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
476 const Teuchos::RCP<const map_type>& colMap,
477 const Teuchos::ArrayRCP<size_t> & rowPointers,
478 const Teuchos::ArrayRCP<LocalOrdinal> & columnIndices,
479 const Teuchos::RCP<Teuchos::ParameterList>& params = null);
499 CrsGraph (
const Teuchos::RCP<const map_type>& rowMap,
500 const Teuchos::RCP<const map_type>& colMap,
501 const local_graph_type& lclGraph,
502 const Teuchos::RCP<Teuchos::ParameterList>& params);
531 template<
class Node2>
532 Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node2, Node2::classic> >
533 clone (
const Teuchos::RCP<Node2>& node2,
534 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
const 538 typedef Details::CrsGraphCopier<output_crs_graph_type, input_crs_graph_type> copier_type;
539 return copier_type::clone (*
this, node2, params);
550 void setParameterList (
const Teuchos::RCP<Teuchos::ParameterList>& params);
553 Teuchos::RCP<const ParameterList> getValidParameters ()
const;
581 insertGlobalIndices (GlobalOrdinal globalRow,
582 const Teuchos::ArrayView<const GlobalOrdinal>& indices);
600 insertLocalIndices (
const LocalOrdinal localRow,
601 const Teuchos::ArrayView<const LocalOrdinal> &indices);
613 void removeLocalIndices (LocalOrdinal localRow);
629 void globalAssemble ();
639 void resumeFill (
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
659 fillComplete (
const Teuchos::RCP<const map_type> &domainMap,
660 const Teuchos::RCP<const map_type> &rangeMap,
661 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
669 void fillComplete (
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
682 expertStaticFillComplete (
const Teuchos::RCP<const map_type> & domainMap,
683 const Teuchos::RCP<const map_type> & rangeMap,
684 const Teuchos::RCP<const import_type> &importer=Teuchos::null,
685 const Teuchos::RCP<const export_type> &exporter=Teuchos::null,
686 const Teuchos::RCP<Teuchos::ParameterList> ¶ms=Teuchos::null);
692 Teuchos::RCP<const Comm<int> > getComm()
const;
695 Teuchos::RCP<node_type> getNode()
const;
698 Teuchos::RCP<const map_type> getRowMap ()
const;
701 Teuchos::RCP<const map_type> getColMap ()
const;
704 Teuchos::RCP<const map_type> getDomainMap ()
const;
707 Teuchos::RCP<const map_type> getRangeMap ()
const;
710 Teuchos::RCP<const import_type> getImporter ()
const;
713 Teuchos::RCP<const export_type> getExporter ()
const;
727 size_t getNodeNumRows()
const;
732 size_t getNodeNumCols()
const;
735 GlobalOrdinal getIndexBase()
const;
743 size_t getNodeNumEntries()
const;
747 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow)
const;
751 size_t getNumEntriesInLocalRow(LocalOrdinal localRow)
const;
761 size_t getNodeAllocationSize()
const;
765 size_t getNumAllocatedEntriesInGlobalRow(GlobalOrdinal globalRow)
const;
769 size_t getNumAllocatedEntriesInLocalRow(LocalOrdinal localRow)
const;
779 size_t getNodeNumDiags()
const;
793 size_t getGlobalMaxNumRowEntries()
const;
798 size_t getNodeMaxNumRowEntries()
const;
814 bool hasColMap()
const;
823 bool isLowerTriangular()
const;
832 bool isUpperTriangular()
const;
835 bool isLocallyIndexed()
const;
838 bool isGloballyIndexed()
const;
841 bool isFillComplete()
const;
844 bool isFillActive()
const;
853 bool isSorted()
const;
862 bool isStorageOptimized()
const;
873 getGlobalRowCopy (GlobalOrdinal GlobalRow,
874 const Teuchos::ArrayView<GlobalOrdinal>& Indices,
875 size_t& NumIndices)
const;
885 getLocalRowCopy (LocalOrdinal LocalRow,
886 const Teuchos::ArrayView<LocalOrdinal>& indices,
887 size_t& NumIndices)
const;
899 getGlobalRowView (GlobalOrdinal GlobalRow,
900 Teuchos::ArrayView<const GlobalOrdinal>& Indices)
const;
912 getLocalRowView (LocalOrdinal LocalRow,
913 Teuchos::ArrayView<const LocalOrdinal>& indices)
const;
920 std::string description()
const;
924 describe (Teuchos::FancyOStream& out,
925 const Teuchos::EVerbosityLevel verbLevel =
926 Teuchos::Describable::verbLevel_default)
const;
938 const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
939 const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs);
943 const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
944 Teuchos::Array<GlobalOrdinal> &exports,
945 const Teuchos::ArrayView<size_t> & numPacketsPerLID,
946 size_t& constantNumPackets,
950 pack (
const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
951 Teuchos::Array<GlobalOrdinal>& exports,
952 const Teuchos::ArrayView<size_t>& numPacketsPerLID,
953 size_t& constantNumPackets,
957 unpackAndCombine (
const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
958 const Teuchos::ArrayView<const GlobalOrdinal> &imports,
959 const Teuchos::ArrayView<size_t> &numPacketsPerLID,
960 size_t constantNumPackets,
990 getNumEntriesPerLocalRowUpperBound (Teuchos::ArrayRCP<const size_t>& boundPerLocalRow,
991 size_t& boundForAllLocalRows,
992 bool& boundSameForAllLocalRows)
const;
1003 setAllIndices (
const typename local_graph_type::row_map_type& rowPointers,
1004 const typename local_graph_type::entries_type::non_const_type& columnIndices);
1015 setAllIndices (
const Teuchos::ArrayRCP<size_t> & rowPointers,
1016 const Teuchos::ArrayRCP<LocalOrdinal> & columnIndices);
1025 Teuchos::ArrayRCP<const size_t> getNodeRowPtrs ()
const;
1030 Teuchos::ArrayRCP<const LocalOrdinal> getNodePackedIndices()
const;
1042 void replaceColMap (
const Teuchos::RCP<const map_type>& newColMap);
1064 reindexColumns (
const Teuchos::RCP<const map_type>& newColMap,
1065 const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1066 const bool sortIndicesInEachRow =
true);
1081 replaceDomainMapAndImporter (
const Teuchos::RCP<const map_type>& newDomainMap,
1082 const Teuchos::RCP<const import_type>& newImporter);
1115 template<
class ViewType,
class OffsetViewType >
1116 struct pack_functor {
1117 typedef typename ViewType::execution_space execution_space;
1120 OffsetViewType src_offset;
1121 OffsetViewType dest_offset;
1122 typedef typename OffsetViewType::non_const_value_type ScalarIndx;
1124 pack_functor(ViewType dest_, ViewType src_, OffsetViewType dest_offset_, OffsetViewType src_offset_):
1125 src(src_),dest(dest_),src_offset(src_offset_),dest_offset(dest_offset_) {};
1127 KOKKOS_INLINE_FUNCTION
1128 void operator() (
size_t row)
const {
1129 ScalarIndx i = src_offset(row);
1130 ScalarIndx j = dest_offset(row);
1131 const ScalarIndx k = dest_offset(row+1);
1141 struct SLocalGlobalViews {
1142 Teuchos::ArrayView<const GlobalOrdinal> ginds;
1143 Teuchos::ArrayView<const LocalOrdinal> linds;
1145 struct SLocalGlobalNCViews {
1146 Teuchos::ArrayView<GlobalOrdinal> ginds;
1147 Teuchos::ArrayView<LocalOrdinal> linds;
1150 bool indicesAreAllocated ()
const;
1151 void allocateIndices (
const ELocalGlobal lg);
1154 Teuchos::ArrayRCP<Teuchos::Array<T> > allocateValues2D ()
const;
1158 const size_t newAllocSize,
1159 Teuchos::Array<T>& rowVals)
1161 #ifdef HAVE_TPETRA_DEBUG 1162 TEUCHOS_TEST_FOR_EXCEPT( ! isLocallyIndexed () );
1163 TEUCHOS_TEST_FOR_EXCEPT( ! indicesAreAllocated() );
1164 TEUCHOS_TEST_FOR_EXCEPT( newAllocSize == 0 );
1165 TEUCHOS_TEST_FOR_EXCEPT( newAllocSize < rowInfo.allocSize );
1166 TEUCHOS_TEST_FOR_EXCEPT( ! rowMap_->isNodeLocalElement (rowInfo.localRow) );
1167 #endif // HAVE_TPETRA_DEBUG 1170 lclInds2D_[rowInfo.localRow].resize (newAllocSize);
1171 rowVals.resize (newAllocSize);
1172 nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
1175 rowInfoOut.allocSize = newAllocSize;
1181 updateGlobalAllocAndValues (
const RowInfo rowInfo,
1182 const size_t newAllocSize,
1183 Teuchos::Array<T>& rowVals)
1185 #ifdef HAVE_TPETRA_DEBUG 1186 TEUCHOS_TEST_FOR_EXCEPT( ! isGloballyIndexed () );
1187 TEUCHOS_TEST_FOR_EXCEPT( ! indicesAreAllocated () );
1188 TEUCHOS_TEST_FOR_EXCEPT( newAllocSize == 0 );
1189 TEUCHOS_TEST_FOR_EXCEPT( newAllocSize < rowInfo.allocSize );
1190 TEUCHOS_TEST_FOR_EXCEPT( ! rowMap_->isNodeLocalElement (rowInfo.localRow) );
1191 #endif // HAVE_TPETRA_DEBUG 1194 gblInds2D_[rowInfo.localRow].resize (newAllocSize);
1195 rowVals.resize (newAllocSize);
1196 nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
1199 rowInfoOut.allocSize = newAllocSize;
1208 void makeIndicesLocal ();
1209 void makeImportExport ();
1215 template<ELocalGlobal lg>
1216 size_t filterIndices (
const SLocalGlobalNCViews& inds)
const 1218 using Teuchos::ArrayView;
1219 static_assert (lg == GlobalIndices || lg == LocalIndices,
1220 "Tpetra::CrsGraph::filterIndices: The template parameter " 1221 "lg must be either GlobalIndices or LocalIndicies.");
1223 const map_type& cmap = *colMap_;
1224 size_t numFiltered = 0;
1225 #ifdef HAVE_TPETRA_DEBUG 1226 size_t numFiltered_debug = 0;
1228 if (lg == GlobalIndices) {
1229 ArrayView<GlobalOrdinal> ginds = inds.ginds;
1230 typename ArrayView<GlobalOrdinal>::iterator fend = ginds.begin();
1231 typename ArrayView<GlobalOrdinal>::iterator cptr = ginds.begin();
1232 while (cptr != ginds.end()) {
1235 #ifdef HAVE_TPETRA_DEBUG 1236 ++numFiltered_debug;
1241 numFiltered = fend - ginds.begin();
1243 else if (lg == LocalIndices) {
1244 ArrayView<LocalOrdinal> linds = inds.linds;
1245 typename ArrayView<LocalOrdinal>::iterator fend = linds.begin();
1246 typename ArrayView<LocalOrdinal>::iterator cptr = linds.begin();
1247 while (cptr != linds.end()) {
1250 #ifdef HAVE_TPETRA_DEBUG 1251 ++numFiltered_debug;
1256 numFiltered = fend - linds.begin();
1258 #ifdef HAVE_TPETRA_DEBUG 1259 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
1267 filterGlobalIndicesAndValues (
const Teuchos::ArrayView<GlobalOrdinal>& ginds,
1268 const Teuchos::ArrayView<T>& vals)
const 1270 using Teuchos::ArrayView;
1271 const map_type& cmap = *colMap_;
1272 size_t numFiltered = 0;
1273 typename ArrayView<T>::iterator fvalsend = vals.begin();
1274 typename ArrayView<T>::iterator valscptr = vals.begin();
1275 #ifdef HAVE_TPETRA_DEBUG 1276 size_t numFiltered_debug = 0;
1278 typename ArrayView<GlobalOrdinal>::iterator fend = ginds.begin();
1279 typename ArrayView<GlobalOrdinal>::iterator cptr = ginds.begin();
1280 while (cptr != ginds.end()) {
1283 *fvalsend++ = *valscptr;
1284 #ifdef HAVE_TPETRA_DEBUG 1285 ++numFiltered_debug;
1291 numFiltered = fend - ginds.begin();
1292 #ifdef HAVE_TPETRA_DEBUG 1293 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
1294 TEUCHOS_TEST_FOR_EXCEPT( valscptr != vals.end() );
1295 const size_t numFilteredActual =
1296 static_cast<size_t> (fvalsend - vals.begin ());
1297 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFilteredActual );
1298 #endif // HAVE_TPETRA_DEBUG 1304 filterLocalIndicesAndValues (
const Teuchos::ArrayView<LocalOrdinal>& linds,
1305 const Teuchos::ArrayView<T>& vals)
const 1307 using Teuchos::ArrayView;
1308 const map_type& cmap = *colMap_;
1309 size_t numFiltered = 0;
1310 typename ArrayView<T>::iterator fvalsend = vals.begin();
1311 typename ArrayView<T>::iterator valscptr = vals.begin();
1312 #ifdef HAVE_TPETRA_DEBUG 1313 size_t numFiltered_debug = 0;
1315 typename ArrayView<LocalOrdinal>::iterator fend = linds.begin();
1316 typename ArrayView<LocalOrdinal>::iterator cptr = linds.begin();
1317 while (cptr != linds.end()) {
1320 *fvalsend++ = *valscptr;
1321 #ifdef HAVE_TPETRA_DEBUG 1322 ++numFiltered_debug;
1328 numFiltered = fend - linds.begin();
1329 #ifdef HAVE_TPETRA_DEBUG 1330 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
1331 TEUCHOS_TEST_FOR_EXCEPT( valscptr != vals.end() );
1332 const size_t numFilteredActual =
1333 Teuchos::as<size_t> (fvalsend - vals.begin ());
1334 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFilteredActual );
1369 insertIndices (
const RowInfo& rowInfo,
1370 const SLocalGlobalViews& newInds,
1371 const ELocalGlobal lg,
1372 const ELocalGlobal I);
1413 template<
class Scalar>
1415 insertIndicesAndValues (
const RowInfo& rowInfo,
1416 const SLocalGlobalViews& newInds,
1417 const Teuchos::ArrayView<Scalar>& oldRowVals,
1418 const Teuchos::ArrayView<const Scalar>& newRowVals,
1419 const ELocalGlobal lg,
1420 const ELocalGlobal I);
1422 insertGlobalIndicesImpl (
const LocalOrdinal myRow,
1423 const Teuchos::ArrayView<const GlobalOrdinal> &indices);
1425 insertLocalIndicesImpl (
const LocalOrdinal myRow,
1426 const Teuchos::ArrayView<const LocalOrdinal> &indices);
1429 insertLocalIndicesFiltered (
const LocalOrdinal localRow,
1430 const Teuchos::ArrayView<const LocalOrdinal> &indices);
1434 insertGlobalIndicesFiltered (
const GlobalOrdinal localRow,
1435 const Teuchos::ArrayView<const GlobalOrdinal> &indices);
1464 template<
class Scalar,
class BinaryFunction>
1467 const Teuchos::ArrayView<Scalar>& rowVals,
1468 const Teuchos::ArrayView<const LocalOrdinal>& inds,
1469 const Teuchos::ArrayView<const Scalar>& newVals,
1470 BinaryFunction f)
const 1472 typedef typename Teuchos::ArrayView<Scalar>::size_type size_type;
1473 const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid ();
1474 const size_type numElts = inds.size ();
1479 Teuchos::ArrayView<const LocalOrdinal> colInds = getLocalView (rowInfo);
1481 LocalOrdinal numValid = 0;
1482 for (size_type j = 0; j < numElts; ++j) {
1483 const size_t k = findLocalIndex (rowInfo, inds[j], colInds, hint);
1485 rowVals[k] = f (rowVals[k], newVals[j]);
1512 template<
class Scalar,
class BinaryFunction>
1515 const Teuchos::ArrayView<Scalar>& rowVals,
1516 const Teuchos::ArrayView<const GlobalOrdinal>& inds,
1517 const Teuchos::ArrayView<const Scalar>& newVals,
1518 BinaryFunction f)
const 1520 typedef typename Teuchos::ArrayView<Scalar>::size_type size_type;
1521 const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid ();
1522 const size_type numElts = inds.size ();
1525 LocalOrdinal numValid = 0;
1526 for (size_type j = 0; j < numElts; ++j) {
1527 const size_t k = findGlobalIndex (rowInfo, inds[j], hint);
1529 rowVals[k] = f (rowVals[k], newVals[j]);
1542 bool isMerged ()
const;
1549 void setLocallyModified ();
1552 void sortAllIndices ();
1555 void sortRowIndices (
const RowInfo rowinfo);
1571 template <
class Scalar>
1572 void sortRowIndicesAndValues (
const RowInfo rowinfo,
1573 const Teuchos::ArrayView<Scalar>& values);
1583 void mergeAllIndices ();
1589 void mergeRowIndices (
RowInfo rowinfo);
1601 template<
class Scalar>
1603 mergeRowIndicesAndValues (
RowInfo rowinfo,
1604 const Teuchos::ArrayView<Scalar>& rowValues);
1617 setDomainRangeMaps (
const Teuchos::RCP<const map_type>& domainMap,
1618 const Teuchos::RCP<const map_type>& rangeMap);
1620 void staticAssertions()
const;
1621 void clearGlobalConstants();
1622 void computeGlobalConstants();
1626 RowInfo getRowInfo (
const size_t myRow)
const;
1631 Teuchos::ArrayView<const LocalOrdinal>
1632 getLocalView (
const RowInfo rowinfo)
const;
1637 Teuchos::ArrayView<LocalOrdinal>
1638 getLocalViewNonConst (
const RowInfo rowinfo);
1643 Teuchos::ArrayView<const GlobalOrdinal>
1644 getGlobalView (
const RowInfo rowinfo)
const;
1649 Teuchos::ArrayView<GlobalOrdinal>
1650 getGlobalViewNonConst (
const RowInfo rowinfo);
1687 findLocalIndex (
RowInfo rowinfo,
1689 size_t hint = 0)
const;
1720 findLocalIndex (
RowInfo rowinfo,
1722 Teuchos::ArrayView<const LocalOrdinal> colInds,
1723 size_t hint = 0)
const;
1733 size_t findGlobalIndex (
RowInfo rowinfo, GlobalOrdinal ind,
size_t hint = 0)
const;
1739 local_graph_type getLocalGraph ()
const;
1742 TPETRA_DEPRECATED local_graph_type getLocalGraph_Kokkos ()
const;
1744 void fillLocalGraph (
const Teuchos::RCP<Teuchos::ParameterList>& params);
1747 bool hasRowInfo ()
const;
1750 void checkInternalState ()
const;
1782 global_size_t globalNumEntries_, globalNumDiags_, globalMaxNumRowEntries_;
1783 size_t nodeNumEntries_, nodeNumDiags_, nodeMaxNumRowEntries_, nodeNumAllocated_;
1911 typedef Kokkos::DualView<size_t*, Kokkos::LayoutLeft, execution_space> t_numRowEntries_;
1934 bool indicesAreAllocated_;
1935 bool indicesAreLocal_;
1936 bool indicesAreGlobal_;
1980 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic = Node::
classic>
1981 Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node, classic> >
1983 size_t maxNumEntriesPerRow = 0,
1984 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
1988 return rcp (
new graph_type (map, maxNumEntriesPerRow,
DynamicProfile, params));
1993 template<
class LocalOrdinal,
1994 class GlobalOrdinal,
1995 class OutputNodeType,
1996 class InputNodeType>
1997 class CrsGraphCopier<CrsGraph<LocalOrdinal, GlobalOrdinal, OutputNodeType>,
1998 CrsGraph<LocalOrdinal, GlobalOrdinal, InputNodeType> > {
2003 static Teuchos::RCP<output_crs_graph_type>
2004 clone (
const input_crs_graph_type& graphIn,
2005 const Teuchos::RCP<OutputNodeType> &nodeOut,
2006 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2008 using Teuchos::arcp;
2009 using Teuchos::ArrayRCP;
2010 using Teuchos::ArrayView;
2011 using Teuchos::null;
2012 using Teuchos::outArg;
2013 using Teuchos::ParameterList;
2014 using Teuchos::parameterList;
2017 using Teuchos::REDUCE_MIN;
2018 using Teuchos::reduceAll;
2019 using Teuchos::sublist;
2022 typedef LocalOrdinal LO;
2023 typedef GlobalOrdinal GO;
2024 typedef typename ArrayView<const GO>::size_type size_type;
2025 typedef ::Tpetra::Map<LO, GO, InputNodeType> input_map_type;
2026 typedef ::Tpetra::Map<LO, GO, OutputNodeType> output_map_type;
2027 const char prefix[] =
"Tpetra::Details::CrsGraphCopier::clone: ";
2031 bool fillCompleteClone =
true;
2032 bool useLocalIndices = graphIn.hasColMap ();
2035 if (! params.is_null ()) {
2036 fillCompleteClone = params->get (
"fillComplete clone", fillCompleteClone);
2037 useLocalIndices = params->get (
"Locally indexed clone", useLocalIndices);
2038 if (params->get (
"Static profile clone",
true) ==
false) {
2041 debug = params->get (
"Debug", debug);
2044 const Teuchos::Comm<int>& comm = * (graphIn.getRowMap ()->getComm ());
2045 const int myRank = comm.getRank ();
2047 TEUCHOS_TEST_FOR_EXCEPTION(
2048 ! graphIn.hasColMap () && useLocalIndices, std::runtime_error,
2049 prefix <<
"You asked clone() to use local indices (by setting the " 2050 "\"Locally indexed clone\" parameter to true), but the source graph " 2051 "does not yet have a column Map, so this is impossible.");
2054 std::ostringstream os;
2055 os <<
"Process " << myRank <<
": Cloning row Map" << endl;
2059 RCP<const output_map_type> clonedRowMap =
2060 graphIn.getRowMap ()->template clone<OutputNodeType> (nodeOut);
2064 RCP<output_crs_graph_type> clonedGraph;
2066 ArrayRCP<const size_t> numEntriesPerRow;
2067 size_t numEntriesForAll = 0;
2068 bool boundSameForAllLocalRows =
true;
2071 std::ostringstream os;
2072 os <<
"Process " << myRank <<
": Getting per-row bounds" << endl;
2075 graphIn.getNumEntriesPerLocalRowUpperBound (numEntriesPerRow,
2077 boundSameForAllLocalRows);
2079 std::ostringstream os;
2080 os <<
"Process " << myRank <<
": numEntriesForAll = " 2081 << numEntriesForAll << endl;
2086 std::ostringstream os;
2087 os <<
"Process " << myRank <<
": graphIn.getNodeMaxNumRowEntries() = " 2088 << graphIn.getNodeMaxNumRowEntries () << endl;
2092 RCP<ParameterList> graphparams;
2093 if (params.is_null ()) {
2094 graphparams = parameterList (
"CrsGraph");
2096 graphparams = sublist (params,
"CrsGraph");
2098 if (useLocalIndices) {
2099 RCP<const output_map_type> clonedColMap =
2100 graphIn.getColMap ()->template clone<OutputNodeType> (nodeOut);
2101 if (boundSameForAllLocalRows) {
2102 clonedGraph = rcp (
new output_crs_graph_type (clonedRowMap, clonedColMap,
2103 numEntriesForAll, pftype,
2106 clonedGraph = rcp (
new output_crs_graph_type (clonedRowMap, clonedColMap,
2107 numEntriesPerRow, pftype,
2111 if (boundSameForAllLocalRows) {
2112 clonedGraph = rcp (
new output_crs_graph_type (clonedRowMap,
2113 numEntriesForAll, pftype,
2116 clonedGraph = rcp (
new output_crs_graph_type (clonedRowMap,
2118 pftype, graphparams));
2123 std::ostringstream os;
2124 os <<
"Process " << myRank <<
": Invoked output graph's constructor" << endl;
2129 numEntriesPerRow = null;
2130 numEntriesForAll = 0;
2133 const input_map_type& inputRowMap = * (graphIn.getRowMap ());
2134 const size_type numRows =
2135 static_cast<size_type
> (inputRowMap.getNodeNumElements ());
2137 bool failed =
false;
2139 if (useLocalIndices) {
2140 const LO localMinLID = inputRowMap.getMinLocalIndex ();
2141 const LO localMaxLID = inputRowMap.getMaxLocalIndex ();
2143 if (graphIn.isLocallyIndexed ()) {
2146 ArrayView<const LO> linds;
2147 for (LO lrow = localMinLID; lrow <= localMaxLID; ++lrow) {
2148 graphIn.getLocalRowView (lrow, linds);
2149 if (linds.size () != 0) {
2150 clonedGraph->insertLocalIndices (lrow, linds);
2154 catch (std::exception& e) {
2155 std::ostringstream os;
2156 os <<
"Process " << myRank <<
": copying (reading local by view, " 2157 "writing local) indices into the output graph threw an " 2158 "exception: " << e.what () << endl;
2165 TEUCHOS_TEST_FOR_EXCEPTION(
2166 ! graphIn.hasColMap () && useLocalIndices, std::invalid_argument,
2167 prefix <<
"You asked clone() to use local indices (by setting the " 2168 "\"Locally indexed clone\" parameter to true), but the source graph " 2169 "does not yet have a column Map, so this is impossible.");
2184 size_t myMaxNumRowEntries =
2185 graphIn.isFillActive () ?
static_cast<size_t> (0) :
2186 graphIn.getNodeMaxNumRowEntries ();
2188 Array<LO> linds (myMaxNumRowEntries);
2191 for (LO lrow = localMinLID; lrow <= localMaxLID; ++lrow) {
2192 size_t theNumEntries = graphIn.getNumEntriesInLocalRow (lrow);
2193 if (theNumEntries > myMaxNumRowEntries) {
2194 myMaxNumRowEntries = theNumEntries;
2195 linds.resize (myMaxNumRowEntries);
2197 graphIn.getLocalRowCopy (lrow, linds (), theNumEntries);
2198 if (theNumEntries != 0) {
2199 clonedGraph->insertLocalIndices (lrow, linds (0, theNumEntries));
2203 catch (std::exception& e) {
2204 std::ostringstream os;
2205 os <<
"Process " << myRank <<
": copying (reading local by copy, " 2206 "writing local) indices into the output graph threw an exception: " 2207 << e.what () << endl;
2215 const GlobalOrdinal localMinGID = inputRowMap.getMinGlobalIndex ();
2216 const GlobalOrdinal localMaxGID = inputRowMap.getMaxGlobalIndex ();
2217 const bool inputRowMapIsContiguous = inputRowMap.isContiguous ();
2219 if (graphIn.isGloballyIndexed ()) {
2220 ArrayView<const GlobalOrdinal> ginds;
2222 if (inputRowMapIsContiguous) {
2224 for (GO grow = localMinGID; grow <= localMaxGID; ++grow) {
2225 graphIn.getGlobalRowView (grow, ginds);
2226 if (ginds.size () != 0) {
2227 clonedGraph->insertGlobalIndices (grow, ginds);
2231 catch (std::exception& e) {
2232 std::ostringstream os;
2233 os <<
"Process " << myRank <<
": copying (reading global by view, " 2234 "writing global) indices into the output graph threw an " 2235 "exception: " << e.what () << endl;
2242 ArrayView<const GO> inputRowMapGIDs = inputRowMap.getNodeElementList ();
2243 for (size_type k = 0; k < numRows; ++k) {
2244 const GO grow = inputRowMapGIDs[k];
2245 graphIn.getGlobalRowView (grow, ginds);
2246 if (ginds.size () != 0) {
2247 clonedGraph->insertGlobalIndices (grow, ginds);
2251 catch (std::exception& e) {
2252 std::ostringstream os;
2253 os <<
"Process " << myRank <<
": copying (reading global by view, " 2254 "writing global) indices into the output graph threw an " 2255 "exception: " << e.what () << endl;
2268 size_t myMaxNumRowEntries =
2269 graphIn.isFillActive () ?
static_cast<size_t> (0) :
2270 graphIn.getNodeMaxNumRowEntries ();
2272 Array<GO> ginds (myMaxNumRowEntries);
2274 if (inputRowMapIsContiguous) {
2276 for (GO grow = localMinGID; grow <= localMaxGID; ++grow) {
2277 size_t theNumEntries = graphIn.getNumEntriesInGlobalRow (grow);
2278 if (theNumEntries > myMaxNumRowEntries) {
2279 myMaxNumRowEntries = theNumEntries;
2280 ginds.resize (myMaxNumRowEntries);
2282 graphIn.getGlobalRowCopy (grow, ginds (), theNumEntries);
2283 if (theNumEntries != 0) {
2284 clonedGraph->insertGlobalIndices (grow, ginds (0, theNumEntries));
2288 catch (std::exception& e) {
2289 std::ostringstream os;
2290 os <<
"Process " << myRank <<
": copying (reading global by copy, " 2291 "writing global) indices into the output graph threw an " 2292 "exception: " << e.what () << endl;
2299 ArrayView<const GO> inputRowMapGIDs = inputRowMap.getNodeElementList ();
2300 for (size_type k = 0; k < numRows; ++k) {
2301 const GO grow = inputRowMapGIDs[k];
2303 size_t theNumEntries = graphIn.getNumEntriesInGlobalRow (grow);
2304 if (theNumEntries > myMaxNumRowEntries) {
2305 myMaxNumRowEntries = theNumEntries;
2306 ginds.resize (myMaxNumRowEntries);
2308 graphIn.getGlobalRowCopy (grow, ginds (), theNumEntries);
2309 if (theNumEntries != 0) {
2310 clonedGraph->insertGlobalIndices (grow, ginds (0, theNumEntries));
2314 catch (std::exception& e) {
2315 std::ostringstream os;
2316 os <<
"Process " << myRank <<
": copying (reading global by copy, " 2317 "writing global) indices into the output graph threw an " 2318 "exception: " << e.what () << endl;
2328 std::ostringstream os;
2329 os <<
"Process " << myRank <<
": copied entries" << endl;
2333 if (fillCompleteClone) {
2334 RCP<ParameterList> fillparams = params.is_null () ?
2335 parameterList (
"fillComplete") :
2336 sublist (params,
"fillComplete");
2338 RCP<const output_map_type> clonedRangeMap;
2339 RCP<const output_map_type> clonedDomainMap;
2340 if (! graphIn.getRangeMap ().is_null () &&
2341 graphIn.getRangeMap () != graphIn.getRowMap ()) {
2343 graphIn.getRangeMap ()->template clone<OutputNodeType> (nodeOut);
2346 clonedRangeMap = clonedRowMap;
2348 if (! graphIn.getDomainMap ().is_null ()
2349 && graphIn.getDomainMap () != graphIn.getRowMap ()) {
2351 graphIn.getDomainMap ()->template clone<OutputNodeType> (nodeOut);
2354 clonedDomainMap = clonedRowMap;
2358 std::ostringstream os;
2359 os <<
"Process " << myRank <<
": About to call fillComplete on " 2360 "cloned graph" << endl;
2363 clonedGraph->fillComplete (clonedDomainMap, clonedRangeMap, fillparams);
2365 catch (std::exception &e) {
2367 std::ostringstream os;
2368 os << prefix <<
"Process " << myRank <<
": Caught the following " 2369 "exception while calling fillComplete() on clone of type" 2370 << endl << Teuchos::typeName (*clonedGraph) << endl;
2375 int lclSuccess = failed ? 0 : 1;
2377 reduceAll<int, int> (comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
2378 TEUCHOS_TEST_FOR_EXCEPTION(
2379 gblSuccess != 1, std::logic_error, prefix <<
2380 "Clone failed on at least one process.");
2383 std::ostringstream os;
2384 os <<
"Process " << myRank <<
": Done with CrsGraph::clone" << endl;
2394 #endif // TPETRA_CRSGRAPH_DECL_HPP 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.
bool haveGlobalConstants_
Whether all processes have computed global constants.
Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node2, Node2::classic > > clone(const Teuchos::RCP< Node2 > &node2, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null) const
Create a cloned CrsGraph for a different Node type.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
An abstract interface for graphs accessed by rows.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is owned by this Map on the calling process.
bool indicesAreSorted_
Whether the graph's indices are sorted in each row, on this process.
GlobalOrdinal global_ordinal_type
This class' second template parameter; the type of global indices.
bool noRedundancies_
Whether the graph's indices are non-redundant (merged) in each row, on this process.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
local_graph_type LocalStaticCrsGraphType TPETRA_DEPRECATED
DEPRECATED; use local_graph_type (above) instead.
bool sortGhostsAssociatedWithEachProcessor_
Whether to require makeColMap() (and therefore fillComplete()) to order column Map GIDs associated wi...
Node::device_type device_type
This class' Kokkos device type.
Teuchos::RCP< const map_type > rangeMap_
The Map describing the range of the (matrix corresponding to the) graph.
ProfileType pftype_
Whether the graph was allocated with static or dynamic profile.
t_numRowEntries_ k_numRowEntries_
The number of local entries in each locally owned row.
local_graph_type::entries_type::non_const_type k_lclInds1D_
Local column indices for all rows.
Teuchos::ArrayRCP< Teuchos::Array< GlobalOrdinal > > gblInds2D_
Global column indices for all rows.
LocalOrdinal local_ordinal_type
This class' first template parameter; the type of local indices.
Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node, classic > > createCrsGraph(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Nonmember function to create an empty CrsGraph given a row Map and the max number of entries allowed ...
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's Map.
bool upperTriangular_
Whether the graph is locally upper triangular.
Teuchos::RCP< const map_type > domainMap_
The Map describing the domain of the (matrix corresponding to the) graph.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
int local_ordinal_type
Default value of LocalOrdinal template parameter.
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on the calling process.
Teuchos::RCP< const map_type > colMap_
The Map describing the distribution of columns of the graph.
Implementation details of Tpetra.
size_t numAllocForAllRows_
The maximum number of entries to allow in each locally owned row.
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.
bool haveLocalConstants_
Whether this process has computed local constants.
t_GlobalOrdinal_1D k_gblInds1D_
Global column indices for all rows.
local_graph_type lclGraph_
Local graph; only initialized after first fillComplete() call.
LocalOrdinal transformLocalValues(RowInfo rowInfo, const Teuchos::ArrayView< Scalar > &rowVals, const Teuchos::ArrayView< const LocalOrdinal > &inds, const Teuchos::ArrayView< const Scalar > &newVals, BinaryFunction f) const
Transform the given values using local indices.
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
Rule for combining data in an Import or Export.
Kokkos::DualView< const size_t *, Kokkos::LayoutLeft, execution_space > k_numAllocPerRow_
The maximum number of entries to allow in each locally owned row, per row.
Abstract base class for objects that can be the source of an Import or Export operation.
Teuchos::RCP< const import_type > importer_
The Import from the domain Map to the column Map.
Node node_type
This class' Kokkos Node type.
Teuchos::RCP< const map_type > rowMap_
The Map describing the distribution of rows of the graph.
Teuchos::ArrayRCP< Teuchos::Array< LocalOrdinal > > lclInds2D_
Local column indices for all rows.
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The Map specialization used by this class.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
LocalOrdinal transformGlobalValues(RowInfo rowInfo, const Teuchos::ArrayView< Scalar > &rowVals, const Teuchos::ArrayView< const GlobalOrdinal > &inds, const Teuchos::ArrayView< const Scalar > &newVals, BinaryFunction f) const
Transform the given values using global indices.
Describes a parallel distribution of objects over processes.
Details::EStorageStatus storageStatus_
Status of the graph's storage, when not in a fill-complete state.
device_type::execution_space execution_space
This class' Kokkos execution space.
local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED
DEPRECATED; use local_graph_type::entries_type::non_const_type instead.
local_graph_type::row_map_type::const_type k_rowPtrs_
Row offsets for "1-D" storage.
std::map< GlobalOrdinal, std::vector< GlobalOrdinal > > nonlocals_
Nonlocal data given to insertGlobalValues or sumIntoGlobalValues.
local_graph_type::row_map_type t_RowPtrs TPETRA_DEPRECATED
DEPRECATED; use local_graph_type::row_map_type instead.
local_graph_type::row_map_type::non_const_type t_RowPtrsNC TPETRA_DEPRECATED
DEPRECATED; use local_graph_type::row_map_type::non_const_type instead.
Kokkos::View< GlobalOrdinal *, execution_space > t_GlobalOrdinal_1D
Type of the k_gblInds1D_ array of global column indices.
Base class for distributed Tpetra objects that support data redistribution.
Tpetra::Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization used by this class.
EStorageStatus
Status of the graph's or matrix's storage, when not in a fill-complete state.
Teuchos::RCP< const export_type > exporter_
The Export from the row Map to the range Map.
bool lowerTriangular_
Whether the graph is locally lower triangular.
Tpetra::Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization used by this class.