42 #ifndef TPETRA_FECRSGRAPH_DEF_HPP
43 #define TPETRA_FECRSGRAPH_DEF_HPP
45 #include <type_traits>
46 #include "Tpetra_CrsGraph.hpp"
53 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
55 FECrsGraph(
const Teuchos::RCP<const map_type> & ownedRowMap,
56 const Teuchos::RCP<const map_type> & ownedPlusSharedRowMap,
57 const size_t maxNumEntriesPerRow,
58 const Teuchos::RCP<const import_type> & ownedPlusSharedToOwnedimporter,
59 const Teuchos::RCP<const map_type> & domainMap,
60 const Teuchos::RCP<const map_type> & rangeMap,
61 const Teuchos::RCP<Teuchos::ParameterList>& params):
62 crs_graph_type(ownedPlusSharedRowMap, maxNumEntriesPerRow, StaticProfile, params),
63 importer_(ownedPlusSharedToOwnedimporter),
64 domainMap_(domainMap.is_null() ? ownedRowMap : domainMap),
65 rangeMap_(rangeMap.is_null() ? ownedRowMap : rangeMap)
67 Teuchos::RCP<const map_type> dummy;
68 setup(ownedRowMap,ownedPlusSharedRowMap,dummy,params);
72 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
74 FECrsGraph (
const Teuchos::RCP<const map_type> & ownedRowMap,
75 const Teuchos::RCP<const map_type> & ownedPlusSharedRowMap,
76 const Kokkos::DualView<const size_t*, execution_space>& numEntPerRow,
77 const Teuchos::RCP<const import_type> & ownedPlusSharedToOwnedimporter,
78 const Teuchos::RCP<const map_type> & domainMap,
79 const Teuchos::RCP<const map_type> & rangeMap,
80 const Teuchos::RCP<Teuchos::ParameterList>& params):
81 crs_graph_type( ownedPlusSharedRowMap, numEntPerRow, StaticProfile, params),
82 importer_(ownedPlusSharedToOwnedimporter),
83 domainMap_(domainMap.is_null() ? ownedRowMap : domainMap),
84 rangeMap_(rangeMap.is_null() ? ownedRowMap : rangeMap)
87 Teuchos::RCP<const map_type> dummy;
88 setup(ownedRowMap,ownedPlusSharedRowMap,dummy,params);
92 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
94 FECrsGraph(
const Teuchos::RCP<const map_type> & ownedRowMap,
95 const Teuchos::RCP<const map_type> & ownedPlusSharedRowMap,
96 const Teuchos::RCP<const map_type> & ownedPlusSharedColMap,
97 const size_t maxNumEntriesPerRow,
98 const Teuchos::RCP<const import_type> & ownedPlusSharedToOwnedimporter,
99 const Teuchos::RCP<const map_type> & domainMap,
100 const Teuchos::RCP<const map_type> & rangeMap,
101 const Teuchos::RCP<Teuchos::ParameterList>& params):
102 crs_graph_type(ownedPlusSharedRowMap, ownedPlusSharedColMap,maxNumEntriesPerRow, StaticProfile, params),
103 importer_(ownedPlusSharedToOwnedimporter),
104 domainMap_(domainMap.is_null() ? ownedRowMap : domainMap),
105 rangeMap_(rangeMap.is_null() ? ownedRowMap : rangeMap)
107 setup(ownedRowMap,ownedPlusSharedRowMap, ownedPlusSharedColMap,params);
110 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
112 FECrsGraph (
const Teuchos::RCP<const map_type> & ownedRowMap,
113 const Teuchos::RCP<const map_type> & ownedPlusSharedRowMap,
114 const Teuchos::RCP<const map_type> & ownedPlusSharedColMap,
115 const Kokkos::DualView<const size_t*, execution_space>& numEntPerRow,
116 const Teuchos::RCP<const import_type> & ownedPlusSharedToOwnedimporter,
117 const Teuchos::RCP<const map_type> & domainMap,
118 const Teuchos::RCP<const map_type> & rangeMap,
119 const Teuchos::RCP<Teuchos::ParameterList>& params):
120 crs_graph_type(ownedPlusSharedRowMap, ownedPlusSharedColMap, numEntPerRow, StaticProfile, params),
121 importer_(ownedPlusSharedToOwnedimporter),
122 domainMap_(domainMap.is_null() ? ownedRowMap : domainMap),
123 rangeMap_(rangeMap.is_null() ? ownedRowMap : rangeMap)
126 setup(ownedRowMap,ownedPlusSharedRowMap, ownedPlusSharedColMap,params);
130 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
131 void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::setup(
const Teuchos::RCP<const map_type> & ownedRowMap,
const Teuchos::RCP<const map_type> & ownedPlusSharedRowMap,
const Teuchos::RCP<const map_type> & ownedPlusSharedColMap,
const Teuchos::RCP<Teuchos::ParameterList>& params) {
132 const char tfecfFuncName[] =
"FECrsGraph::setup(): ";
134 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(ownedRowMap.is_null (), std::runtime_error,
"ownedRowMap is null.");
135 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(ownedPlusSharedRowMap.is_null (), std::runtime_error,
"ownedPlusSharedRowMap is null.");
138 if(ownedPlusSharedColMap.is_null()) this->allocateIndices(GlobalIndices);
139 else this->allocateIndices(LocalIndices);
141 activeCrsGraph_ = Teuchos::rcp(
new FEWhichActive(FE_ACTIVE_OWNED_PLUS_SHARED));
144 bool maps_are_the_same = ownedRowMap->isSameAs(*ownedPlusSharedRowMap);
145 if(!maps_are_the_same) {
147 if(importer_.is_null()) {
148 importer_ = Teuchos::rcp(
new import_type(ownedRowMap,ownedPlusSharedRowMap));
151 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!ownedRowMap->isSameAs(*importer_->getSourceMap()), std::runtime_error,
"ownedRowMap does not match importer source map.");
152 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!ownedPlusSharedRowMap->isSameAs(*importer_->getTargetMap()), std::runtime_error,
"ownedPlusSharedRowMap does not match importer target map.");
156 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( importer_->getNumSameIDs() != importer_->getSourceMap()->getNodeNumElements(),
157 std::runtime_error,
"ownedRowMap contains entries which are not in the ownedPlusSharedRowMap.");
159 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( ownedRowMap->getNodeNumElements() > ownedPlusSharedRowMap->getNodeNumElements(),
160 std::runtime_error,
"ownedRowMap more entries than the ownedPlusSharedRowMap.");
165 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( !ownedPlusSharedRowMap->isLocallyFitted(*ownedRowMap),
166 std::runtime_error,
"ownedPlusSharedRowMap must be locally fitted to the ownedRowMap");
171 if(ownedPlusSharedColMap.is_null())
172 inactiveCrsGraph_ = Teuchos::rcp(
new crs_graph_type(ownedRowMap,0,StaticProfile,params));
174 inactiveCrsGraph_ = Teuchos::rcp(
new crs_graph_type(ownedRowMap,ownedPlusSharedColMap,0,StaticProfile,params));
179 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
180 void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::doOwnedPlusSharedToOwned(
const CombineMode CM) {
181 const char tfecfFuncName[] =
"FECrsGraph::doOwnedPlusSharedToOwned(CombineMode): ";
182 if(!inactiveCrsGraph_.is_null() && *activeCrsGraph_ == FE_ACTIVE_OWNED_PLUS_SHARED) {
183 Teuchos::RCP<const map_type> ownedRowMap = inactiveCrsGraph_->getRowMap();
186 this->doExport(*
this,*importer_,CM,
true);
190 if(!this->hasColMap()) {
191 Teuchos::Array<int> remotePIDs (0);
196 crs_graph_type::fillComplete(domainMap_,this->getRowMap());
201 Teuchos::RCP<const map_type> colmap = this->getColMap();
202 Teuchos::Array<bool> flag(colmap->getNodeNumElements(),
false);
203 Teuchos::Array<LocalOrdinal> indices(this->getNodeMaxNumRowEntries());
204 for(
size_t i=0; i<ownedRowMap->getNodeNumElements(); i++) {
206 this->getLocalRowCopy(i,indices,NumEntries);
207 for(
size_t j=0; j<NumEntries; j++)
208 flag[indices[j]] =
true;
211 bool lclSuccess =
true;
212 for(
size_t i=0; i<(size_t)flag.size(); i++)
213 if(!flag[i]) {lclSuccess=
false;
break;}
214 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
216 std::invalid_argument,
"if you own an element (in the finite element sense) you "
217 "must also own one of the attached nodes. This assumption has been violated in "
218 "your matrix fill.");
222 local_graph_type ownedPlusSharedGraph = this->getLocalGraph();
223 size_t numOwnedRows = ownedRowMap->getNodeNumElements();
224 size_t numOwnedNonZeros = Tpetra::Details::getEntryOnHost(ownedPlusSharedGraph.row_map,numOwnedRows);
228 if(!inactiveCrsGraph_->hasColMap()) inactiveCrsGraph_->replaceColMap(this->getColMap());
229 inactiveCrsGraph_->setAllIndices(Kokkos::subview(ownedPlusSharedGraph.row_map,Kokkos::pair<size_t,size_t>(0,numOwnedRows+1)),
230 Kokkos::subview(ownedPlusSharedGraph.entries,Kokkos::pair<size_t,size_t>(0,numOwnedNonZeros)));
232 inactiveCrsGraph_->expertStaticFillComplete(domainMap_,rangeMap_,this->getImporter(),Teuchos::null);
237 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
238 void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::doOwnedToOwnedPlusShared(
const CombineMode ) {
242 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
244 if(*activeCrsGraph_ == FE_ACTIVE_OWNED_PLUS_SHARED)
245 *activeCrsGraph_ = FE_ACTIVE_OWNED;
247 *activeCrsGraph_ = FE_ACTIVE_OWNED_PLUS_SHARED;
249 if(inactiveCrsGraph_.is_null())
return;
251 this->swap(*inactiveCrsGraph_);
257 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
259 const char tfecfFuncName[] =
"FECrsGraph::endFill(): ";
280 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(*activeCrsGraph_ != FE_ACTIVE_OWNED_PLUS_SHARED,std::runtime_error,
"must be in owned+shared mode.");
282 if(inactiveCrsGraph_.is_null()) {
284 switchActiveCrsGraph();
285 crs_graph_type::fillComplete(domainMap_,rangeMap_);
295 switchActiveCrsGraph();
301 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
303 const char tfecfFuncName[] =
"FECrsGraph::beginFill(): ";
307 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(*activeCrsGraph_ == FE_ACTIVE_OWNED,std::runtime_error,
"can only be called once.");
320 #define TPETRA_FECRSGRAPH_INSTANT(LO,GO,NODE) \
321 template class FECrsGraph<LO, GO, NODE>;
325 #endif // TPETRA_FECRSGRAPH_DEF
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
void endFill()
Migrates data to the owned mode.
static bool debug()
Whether Tpetra is in debug mode.
void beginFill()
Activates the owned+shared mode for assembly. This can only be called once.
CombineMode
Rule for combining data in an Import or Export.
Sum new values into existing values.
void switchActiveCrsGraph()
Switches which CrsGraph is active (without migrating data)
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
int makeColMap(Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &colMap, Teuchos::Array< int > &remotePIDs, const Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &domMap, const RowGraph< LO, GO, NT > &graph, const bool sortEachProcsGids=true, std::ostream *errStrm=NULL)
Make the graph's column Map.
Declaration and definition of Tpetra::Details::getEntryOnHost.
FECrsGraph(const Teuchos::RCP< const map_type > &ownedRowMap, const Teuchos::RCP< const map_type > &ownedPlusSharedRowMap, const size_t maxNumEntriesPerRow, const Teuchos::RCP< const import_type > &ownedPlusSharedToOwnedimporter=Teuchos::null, const Teuchos::RCP< const map_type > &domainMap=Teuchos::null, const Teuchos::RCP< const map_type > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Constructorfor globally-indexed assembly specifying a single upper bound for the number of entries in...
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.