42 #ifndef TPETRA_CRSGRAPH_DECL_HPP 43 #define TPETRA_CRSGRAPH_DECL_HPP 46 #include <Teuchos_Describable.hpp> 47 #include <Teuchos_ParameterListAcceptorDefaultBase.hpp> 49 #include <Kokkos_DefaultNode.hpp> 50 #include <Kokkos_DefaultKernels.hpp> 52 #include "Tpetra_ConfigDefs.hpp" 53 #include "Tpetra_RowGraph.hpp" 54 #include "Tpetra_DistObject.hpp" 55 #include "Tpetra_Exceptions.hpp" 60 #ifndef DOXYGEN_SHOULD_SKIP_THIS 62 template <
class S,
class LO,
class GO,
class N,
class SpMatOps>
163 template <
class LocalOrdinal,
164 class GlobalOrdinal = LocalOrdinal,
165 class Node = Kokkos::DefaultNode::DefaultNodeType,
166 class LocalMatOps =
typename Kokkos::DefaultKernels<void,LocalOrdinal,Node>::SparseOps >
168 public RowGraph<LocalOrdinal,GlobalOrdinal,Node>,
169 public DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>,
172 template <
class S,
class LO,
class GO,
class N,
class SpMatOps>
174 template <
class LO2,
class GO2,
class N2,
class SpMatOps2>
178 typedef LocalOrdinal local_ordinal_type;
179 typedef GlobalOrdinal global_ordinal_type;
180 typedef Node node_type;
204 size_t maxNumEntriesPerRow,
251 size_t maxNumEntriesPerRow,
333 template<
class Node2>
335 typename Kokkos::DefaultKernels<void, LocalOrdinal, Node2>::SparseOps> >
344 typedef CrsGraph<LocalOrdinal, GlobalOrdinal, Node2,
345 typename Kokkos::DefaultKernels<void,LocalOrdinal,Node2>::SparseOps> CrsGraph2;
347 const char tfecfFuncName[] =
"clone()";
349 bool fillCompleteClone =
true;
350 bool useLocalIndices = hasColMap();
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) {
361 hasColMap() ==
false && useLocalIndices ==
true,
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.");
370 size_t numEntriesForAll = 0;
371 if (indicesAreAllocated() ==
false) {
372 if (numAllocPerRow_ != null) {
373 numEntries = numAllocPerRow_;
376 numEntriesForAll = numAllocForAllRows_;
379 else if (numRowEntries_ != null) {
380 numEntries = numRowEntries_;
382 else if (nodeNumAllocated_ == 0) {
383 numEntriesForAll = 0;
389 "Internal logic error. Please report this to Tpetra team.");
390 const size_t numRows = getNodeNumRows();
391 numEntriesForAll = 0;
394 numEnt = arcp<size_t> (numRows);
396 for (
size_t i=0; i<numRows; ++i) {
397 numEnt[i] = rowPtrs_[i+1] - rowPtrs_[i];
403 if (useLocalIndices) {
405 if (numEntries == null) {
406 clonedGraph =
rcp (
new CrsGraph2 (clonedRowMap, clonedColMap, numEntriesForAll, pftype, graphparams));
409 clonedGraph =
rcp (
new CrsGraph2 (clonedRowMap, clonedColMap, numEntries, pftype, graphparams));
414 clonedGraph =
rcp (
new CrsGraph2 (clonedRowMap, numEntriesForAll, pftype, graphparams));
417 clonedGraph =
rcp (
new CrsGraph2 (clonedRowMap, numEntries, pftype, graphparams));
422 numEntriesForAll = 0;
424 if (useLocalIndices) {
425 clonedGraph->allocateIndices(LocalIndices);
426 if (this->isLocallyIndexed ()) {
428 for (LocalOrdinal lrow = rowMap_->getMinLocalIndex ();
429 lrow <= rowMap_->getMaxLocalIndex ();
431 this->getLocalRowView (lrow, linds);
433 clonedGraph->insertLocalIndices (lrow, linds);
439 for (LocalOrdinal lrow = rowMap_->getMinLocalIndex();
440 lrow <= rowMap_->getMaxLocalIndex();
442 size_t theNumEntries;
443 linds.
resize (this->getNumEntriesInLocalRow (lrow));
444 this->getLocalRowCopy (rowMap_->getGlobalElement (lrow), linds (), theNumEntries);
446 clonedGraph->insertLocalIndices (lrow, linds (0, theNumEntries));
452 clonedGraph->allocateIndices (GlobalIndices);
453 if (this->isGloballyIndexed ()) {
455 for (GlobalOrdinal grow = rowMap_->getMinGlobalIndex();
456 grow <= rowMap_->getMaxGlobalIndex();
458 this->getGlobalRowView (grow, ginds);
460 clonedGraph->insertGlobalIndices (grow, ginds);
466 for (GlobalOrdinal grow = rowMap_->getMinGlobalIndex();
467 grow <= rowMap_->getMaxGlobalIndex();
469 size_t theNumEntries;
470 ginds.
resize (this->getNumEntriesInGlobalRow (grow));
471 this->getGlobalRowCopy (grow, ginds (), theNumEntries);
473 clonedGraph->insertGlobalIndices (grow, ginds (0,theNumEntries));
479 if (fillCompleteClone) {
484 if (rangeMap_ != null && rangeMap_ != rowMap_) {
485 clonedRangeMap = rangeMap_->template clone<Node2>(node2);
488 clonedRangeMap = clonedRowMap;
490 if (domainMap_ != null && domainMap_ != rowMap_) {
491 clonedDomainMap = domainMap_->template clone<Node2>(node2);
494 clonedDomainMap = clonedRowMap;
496 clonedGraph->fillComplete (clonedDomainMap, clonedRangeMap, fillparams);
498 catch (std::exception &e) {
499 const bool caughtExceptionOnClone =
true;
501 caughtExceptionOnClone, std::runtime_error,
502 ": Caught the following exception while calling fillComplete() on " 504 << endl <<
":" << endl << e.what() << endl);
549 insertGlobalIndices (GlobalOrdinal globalRow,
568 insertLocalIndices (
const LocalOrdinal localRow,
581 void removeLocalIndices (LocalOrdinal localRow);
597 void globalAssemble ();
695 size_t getNodeNumRows()
const;
700 size_t getNodeNumCols()
const;
703 GlobalOrdinal getIndexBase()
const;
711 size_t getNodeNumEntries()
const;
715 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow)
const;
719 size_t getNumEntriesInLocalRow(LocalOrdinal localRow)
const;
729 size_t getNodeAllocationSize()
const;
733 size_t getNumAllocatedEntriesInGlobalRow(GlobalOrdinal globalRow)
const;
737 size_t getNumAllocatedEntriesInLocalRow(LocalOrdinal localRow)
const;
747 size_t getNodeNumDiags()
const;
761 size_t getGlobalMaxNumRowEntries()
const;
766 size_t getNodeMaxNumRowEntries()
const;
782 bool hasColMap()
const;
791 bool isLowerTriangular()
const;
800 bool isUpperTriangular()
const;
803 bool isLocallyIndexed()
const;
806 bool isGloballyIndexed()
const;
809 bool isFillComplete()
const;
812 bool isFillActive()
const;
818 bool isSorted()
const;
827 bool isStorageOptimized()
const;
842 void getGlobalRowCopy(GlobalOrdinal GlobalRow,
859 void getLocalRowCopy(LocalOrdinal LocalRow,
891 std::string description()
const;
914 size_t& constantNumPackets,
921 size_t constantNumPackets,
1009 typedef typename LocalMatOps::template graph<LocalOrdinal,Node>::graph_type local_graph_type;
1013 struct SLocalGlobalViews {
1017 struct SLocalGlobalNCViews {
1024 bool indicesAreAllocated()
const;
1026 void allocateIndices (ELocalGlobal lg);
1033 template <ELocalGlobal lg,
class T>
1047 void computeIndexState();
1049 void makeIndicesLocal ();
1050 void makeImportExport ();
1056 template<ELocalGlobal lg>
1057 size_t filterIndices (
const SLocalGlobalNCViews &inds)
const;
1098 insertIndices (
const RowInfo& rowInfo,
1099 const SLocalGlobalViews& newInds,
1100 const ELocalGlobal lg,
1101 const ELocalGlobal I);
1142 template<
class Scalar>
1144 insertIndicesAndValues (
const RowInfo& rowInfo,
1145 const SLocalGlobalViews& newInds,
1148 const ELocalGlobal lg,
1149 const ELocalGlobal I);
1151 insertGlobalIndicesImpl (
const LocalOrdinal myRow,
1154 insertLocalIndicesImpl (
const LocalOrdinal myRow,
1158 insertLocalIndicesFiltered (
const LocalOrdinal localRow,
1163 insertGlobalIndicesFiltered (
const GlobalOrdinal localRow,
1188 template<
class Scalar,
class BinaryFunction>
1190 transformLocalValues (
RowInfo rowInfo,
1194 BinaryFunction f)
const;
1210 template<
class Scalar,
class BinaryFunction>
1212 transformGlobalValues (
RowInfo rowInfo,
1216 BinaryFunction f)
const;
1223 bool isMerged ()
const;
1230 void setLocallyModified ();
1233 void sortAllIndices ();
1236 void sortRowIndices (
RowInfo rowinfo);
1252 template <
class Scalar>
1263 void mergeAllIndices ();
1269 void mergeRowIndices (
RowInfo rowinfo);
1282 template<
class Scalar>
1284 mergeRowIndicesAndValues (
RowInfo rowinfo,
1301 void staticAssertions()
const;
1303 void clearGlobalConstants();
1304 void computeGlobalConstants();
1306 RowInfo getRowInfo(
size_t myRow)
const;
1347 findLocalIndex (
RowInfo rowinfo,
1349 size_t hint = 0)
const;
1380 findLocalIndex (
RowInfo rowinfo,
1383 size_t hint = 0)
const;
1392 size_t findGlobalIndex (
RowInfo rowinfo, GlobalOrdinal ind,
size_t hint = 0)
const;
1399 void checkInternalState()
const;
1431 global_size_t globalNumEntries_, globalNumDiags_, globalMaxNumRowEntries_;
1432 size_t nodeNumEntries_, nodeNumDiags_, nodeMaxNumRowEntries_, nodeNumAllocated_;
1495 bool indicesAreAllocated_;
1496 bool indicesAreLocal_;
1497 bool indicesAreGlobal_;
1518 inline bool hasRowInfo()
const {
1519 #ifdef HAVE_TPETRA_DEBUG 1520 bool actuallyHasRowInfo =
true;
1521 if (indicesAreAllocated() && getProfileType() ==
StaticProfile && rowPtrs_ == null) {
1522 actuallyHasRowInfo =
false;
1525 actuallyHasRowInfo != haveRowInfo_,
1526 std::logic_error,
"Internal logic error. Please contact Tpetra team.");
1527 #endif // HAVE_TPETRA_DEBUG 1528 return haveRowInfo_;
1538 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1541 size_t maxNumEntriesPerRow = 0,
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.
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'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 > ¶ms=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'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 > ¶ms=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'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.
ArrayRCP< Array< GlobalOrdinal > > gblInds2D_
gblInds2D_[r] are the indices for row r.
std::string typeName(const T &t)