10#ifndef TPETRA_FECRSGRAPH_DEF_HPP
11#define TPETRA_FECRSGRAPH_DEF_HPP
13#include "Tpetra_CrsGraph.hpp"
22template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
28 const Teuchos::RCP<const map_type> & domainMap,
30 const Teuchos::RCP<Teuchos::ParameterList>&
params):
39template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
48 const Teuchos::RCP<Teuchos::ParameterList>&
params):
55 Teuchos::RCP<const map_type>
dummy;
59template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 const Kokkos::DualView<const size_t*, device_type>&
numEntPerRow,
65 const Teuchos::RCP<const map_type> & domainMap,
67 const Teuchos::RCP<Teuchos::ParameterList>&
params):
75template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 const Kokkos::DualView<const size_t*, device_type>&
numEntPerRow,
84 const Teuchos::RCP<Teuchos::ParameterList>&
params):
91 Teuchos::RCP<const map_type>
dummy;
95template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 const Teuchos::RCP<const map_type> & domainMap,
104 const Teuchos::RCP<Teuchos::ParameterList>&
params):
112template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
122 const Teuchos::RCP<Teuchos::ParameterList>&
params):
132template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137 const Kokkos::DualView<const size_t*, device_type>&
numEntPerRow,
139 const Teuchos::RCP<const map_type> & domainMap,
141 const Teuchos::RCP<Teuchos::ParameterList>&
params):
149template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
154 const Kokkos::DualView<const size_t*, device_type>&
numEntPerRow,
159 const Teuchos::RCP<Teuchos::ParameterList>&
params):
169template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
174 const Teuchos::RCP<Teuchos::ParameterList>&
params)
183 else this->allocateIndices(LocalIndices);
185 activeCrsGraph_ = Teuchos::rcp(
new FE::WhichActive(FE::ACTIVE_OWNED_PLUS_SHARED));
186 fillState_ = Teuchos::rcp(
new FE::FillState(FE::FillState::closed));
192 if(ownedRowsImporter_.is_null()) {
196 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!ownedRowMap->isSameAs(*ownedRowsImporter_->getSourceMap()), std::runtime_error,
"ownedRowMap does not match importer source map.");
197 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!ownedPlusSharedRowMap->isSameAs(*ownedRowsImporter_->getTargetMap()), std::runtime_error,
"ownedPlusSharedRowMap does not match importer target map.");
201 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( ownedRowsImporter_->getNumSameIDs() != ownedRowsImporter_->getSourceMap()->getLocalNumElements(),
202 std::runtime_error,
"ownedRowMap contains entries which are not in the ownedPlusSharedRowMap.");
204 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( ownedRowMap->getLocalNumElements() > ownedPlusSharedRowMap->getLocalNumElements(),
205 std::runtime_error,
"ownedRowMap more entries than the ownedPlusSharedRowMap.");
210 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( !ownedPlusSharedRowMap->isLocallyFitted(*ownedRowMap),
211 std::runtime_error,
"ownedPlusSharedRowMap must be locally fitted to the ownedRowMap");
217 ownedRowsImporter_ = Teuchos::null;
221template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
222void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::doOwnedPlusSharedToOwned(
const CombineMode CM) {
223 const char tfecfFuncName[] =
"FECrsGraph::doOwnedPlusSharedToOwned(CombineMode): ";
224 if(!ownedRowsImporter_.is_null() && *activeCrsGraph_ == FE::ACTIVE_OWNED_PLUS_SHARED) {
225 Teuchos::RCP<const map_type> ownedRowMap = ownedRowsImporter_->getSourceMap();
228 this->doExport(*
this,*ownedRowsImporter_,CM,
true);
232 if(!this->hasColMap()) {
233 Teuchos::Array<int> remotePIDs (0);
238 crs_graph_type::fillComplete(this->domainMap_,this->getRowMap());
245 const bool checkColGIDsInAtLeastOneOwnedRow =
246 this->getMyNonconstParamList().is_null() ? true :
247 this->getMyNonconstParamList()->get(
"Check Col GIDs In At Least One Owned Row",
true);
248 if (debug && checkColGIDsInAtLeastOneOwnedRow) {
249 Teuchos::RCP<const map_type> colmap = this->getColMap();
250 Teuchos::Array<bool> flag(colmap->getLocalNumElements(),
false);
251 typename crs_graph_type::nonconst_local_inds_host_view_type indices(
"indices",this->getLocalMaxNumRowEntries());
253 for(
size_t i=0; i<ownedRowMap->getLocalNumElements(); i++) {
255 this->getLocalRowCopy(i,indices,NumEntries);
256 for(
size_t j=0; j<NumEntries; j++)
257 flag[indices[j]] =
true;
261 for(
size_t i=0; i<(size_t)flag.size(); i++)
267 int gblCount = lclCount;
268 auto comm = this->getComm();
269 if (!comm.is_null()) {
270 Teuchos::reduceAll<int,int>(*comm, Teuchos::REDUCE_SUM, 1, &lclCount, &gblCount);
272 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
274 std::invalid_argument,
"if you own an element (in the finite element sense) you "
275 "must also own one of the attached nodes. This assumption has been violated in "
276 "your matrix fill on at least one MPI rank:\n"
277 " locally, there are " + std::to_string(lclCount) +
" col gids not connected to any owned gid.\n"
278 " globally, there are " + std::to_string(gblCount) +
" col gids not connected to any owned gid.\n"
279 "NOTE: you can disable this check by setting a parameter list with the option\n"
280 " 'Check Col GIDs In At Least One Owned Row' set to false.\n"
281 "NOTE: the parameter list must be set AFTER construction, since it would not be recognized as valid"
282 "by the base class CrsGraph.\n");
286 inactiveCrsGraph_ = Teuchos::rcp(
new crs_graph_type(*
this, ownedRowMap));
287 inactiveCrsGraph_->fillComplete(ownedDomainMap_,ownedRangeMap_);
292template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
293void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::doOwnedToOwnedPlusShared(
const CombineMode ) {
297template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
299 if(*activeCrsGraph_ == FE::ACTIVE_OWNED_PLUS_SHARED)
300 *activeCrsGraph_ = FE::ACTIVE_OWNED;
302 *activeCrsGraph_ = FE::ACTIVE_OWNED_PLUS_SHARED;
304 if(inactiveCrsGraph_.is_null())
return;
306 this->swap(*inactiveCrsGraph_);
311template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
313 const Teuchos::RCP<const map_type>& domainMap,
314 const Teuchos::RCP<const map_type>&
rangeMap)
335 const char tfecfFuncName[] =
"FECrsGraph::endFill(domainMap, rangeMap): ";
337 if(ownedRowsImporter_.is_null()) {
339 switchActiveCrsGraph();
350 switchActiveCrsGraph();
356template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
357void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::endFill() {
358 this->endFill(ownedDomainMap_, ownedRangeMap_);
362template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
363void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::beginFill() {
364 const char tfecfFuncName[] =
"FECrsGraph::beginFill(): ";
368 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(*activeCrsGraph_ == FE::ACTIVE_OWNED,std::runtime_error,
"can only be called once.");
372template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
376 *fillState_ != FE::FillState::closed,
378 "Cannot beginAssembly, matrix is not in a closed state"
380 *fillState_ = FE::FillState::open;
384template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
388 *fillState_ != FE::FillState::open,
390 "Cannot endAssembly, matrix is not open to fill but is closed."
392 *fillState_ = FE::FillState::closed;
396template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
398 const Teuchos::RCP<const map_type>& domainMap,
399 const Teuchos::RCP<const map_type>&
rangeMap)
403 *fillState_ != FE::FillState::open,
405 "Cannot endAssembly, matrix is not open to fill but is closed."
407 *fillState_ = FE::FillState::closed;
411template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
412Teuchos::RCP<const Teuchos::ParameterList>
415 auto valid_pl = Teuchos::rcp(
new Teuchos::ParameterList(
"Tpetra::FECrsGraph"));
416 valid_pl->validateParametersAndSetDefaults(*crs_graph_type::getValidParameters());
417 valid_pl->set(
"Check Col GIDs In At Least One Owned Row",
true);
422template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
429 const char tfecfFuncName[] =
"FECrsGraph::insertGlobalIndices: ";
431 *fillState_ != FE::FillState::open,
433 "Cannot replace global values, matrix is not open to fill but is closed."
438template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
444 std::function<
void(
const size_t,
const size_t,
const size_t)>
fun
446 const char tfecfFuncName[] =
"FECrsGraph::insertGlobalIndices: ";
448 *fillState_ != FE::FillState::open,
450 "Cannot replace global values, matrix is not open to fill but is closed."
455template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
458 const local_ordinal_type
lclRow,
459 const Teuchos::ArrayView<const local_ordinal_type>&
gblColInds,
460 std::function<
void(
const size_t,
const size_t,
const size_t)>
fun
462 const char tfecfFuncName[] =
"FECrsGraph::insertLocalIndices: ";
464 *fillState_ != FE::FillState::open,
466 "Cannot replace global values, matrix is not open to fill but is closed."
479#define TPETRA_FECRSGRAPH_INSTANT(LO,GO,NODE) \
480 template class FECrsGraph<LO, GO, NODE>;
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration and definition of Tpetra::Details::getEntryOnHost.
Teuchos::RCP< const map_type > domainMap_
The Map describing the domain of the (matrix corresponding to the) graph.
Struct that holds views of the contents of a CrsMatrix.
Teuchos::RCP< const map_type > domainMap
Domain map for original matrix.
static bool debug()
Whether Tpetra is in debug mode.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
void endAssembly()
Migrates data to the owned mode.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Default parameter list suitable for validation.
void beginAssembly()
Activates the owned+shared mode for assembly.
void switchActiveCrsGraph()
Switches which CrsGraph is active (without migrating data)
LocalOrdinal local_ordinal_type
This class' first template parameter; the type of local indices.
size_t insertGlobalIndicesImpl(const local_ordinal_type lclRow, const global_ordinal_type inputGblColInds[], const size_t numInputInds)
Insert global indices, using an input local row index.
GlobalOrdinal global_ordinal_type
This class' second template parameter; the type of global indices.
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.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
CombineMode
Rule for combining data in an Import or Export.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.