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)
37template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
46 const Teuchos::RCP<Teuchos::ParameterList>&
params)
52 Teuchos::RCP<const map_type>
dummy;
56template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 const Kokkos::DualView<const size_t*, device_type>&
numEntPerRow,
62 const Teuchos::RCP<const map_type>& domainMap,
64 const Teuchos::RCP<Teuchos::ParameterList>&
params)
71template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 const Kokkos::DualView<const size_t*, device_type>&
numEntPerRow,
80 const Teuchos::RCP<Teuchos::ParameterList>&
params)
86 Teuchos::RCP<const map_type>
dummy;
90template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 const Teuchos::RCP<const map_type>& domainMap,
99 const Teuchos::RCP<Teuchos::ParameterList>&
params)
106template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
116 const Teuchos::RCP<Teuchos::ParameterList>&
params)
125template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
130 const Kokkos::DualView<const size_t*, device_type>&
numEntPerRow,
132 const Teuchos::RCP<const map_type>& domainMap,
134 const Teuchos::RCP<Teuchos::ParameterList>&
params)
141template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
146 const Kokkos::DualView<const size_t*, device_type>&
numEntPerRow,
151 const Teuchos::RCP<Teuchos::ParameterList>&
params)
160template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
165 const Teuchos::RCP<Teuchos::ParameterList>&
params) {
173 this->allocateIndices(GlobalIndices);
175 this->allocateIndices(LocalIndices);
177 activeCrsGraph_ = Teuchos::rcp(
new FE::WhichActive(FE::ACTIVE_OWNED_PLUS_SHARED));
178 fillState_ = Teuchos::rcp(
new FE::FillState(FE::FillState::closed));
184 if (ownedRowsImporter_.is_null()) {
187 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!ownedRowMap->isSameAs(*ownedRowsImporter_->getSourceMap()), std::runtime_error,
"ownedRowMap does not match importer source map.");
188 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!ownedPlusSharedRowMap->isSameAs(*ownedRowsImporter_->getTargetMap()), std::runtime_error,
"ownedPlusSharedRowMap does not match importer target map.");
192 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(ownedRowsImporter_->getNumSameIDs() != ownedRowsImporter_->getSourceMap()->getLocalNumElements(),
193 std::runtime_error,
"ownedRowMap contains entries which are not in the ownedPlusSharedRowMap.");
195 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(ownedRowMap->getLocalNumElements() > ownedPlusSharedRowMap->getLocalNumElements(),
196 std::runtime_error,
"ownedRowMap more entries than the ownedPlusSharedRowMap.");
201 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!ownedPlusSharedRowMap->isLocallyFitted(*ownedRowMap),
202 std::runtime_error,
"ownedPlusSharedRowMap must be locally fitted to the ownedRowMap");
207 ownedRowsImporter_ = Teuchos::null;
211template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
212void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::doOwnedPlusSharedToOwned(
const CombineMode CM) {
213 const char tfecfFuncName[] =
"FECrsGraph::doOwnedPlusSharedToOwned(CombineMode): ";
214 if (!ownedRowsImporter_.is_null() && *activeCrsGraph_ == FE::ACTIVE_OWNED_PLUS_SHARED) {
215 Teuchos::RCP<const map_type> ownedRowMap = ownedRowsImporter_->getSourceMap();
218 this->doExport(*
this, *ownedRowsImporter_, CM,
true);
222 if (!this->hasColMap()) {
223 Teuchos::Array<int> remotePIDs(0);
228 crs_graph_type::fillComplete(this->domainMap_, this->getRowMap());
235 const bool checkColGIDsInAtLeastOneOwnedRow =
236 this->getMyNonconstParamList().is_null() ? true : this->getMyNonconstParamList()->get(
"Check Col GIDs In At Least One Owned Row",
true);
237 if (debug && checkColGIDsInAtLeastOneOwnedRow) {
238 Teuchos::RCP<const map_type> colmap = this->getColMap();
239 Teuchos::Array<bool> flag(colmap->getLocalNumElements(),
false);
240 typename crs_graph_type::nonconst_local_inds_host_view_type indices(
"indices", this->getLocalMaxNumRowEntries());
242 for (
size_t i = 0; i < ownedRowMap->getLocalNumElements(); i++) {
243 size_t NumEntries = 0;
244 this->getLocalRowCopy(i, indices, NumEntries);
245 for (
size_t j = 0; j < NumEntries; j++)
246 flag[indices[j]] =
true;
250 for (
size_t i = 0; i < (size_t)flag.size(); i++)
256 int gblCount = lclCount;
257 auto comm = this->getComm();
258 if (!comm.is_null()) {
259 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_SUM, 1, &lclCount, &gblCount);
261 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(gblCount > 0,
262 std::invalid_argument,
263 "if you own an element (in the finite element sense) you "
264 "must also own one of the attached nodes. This assumption has been violated in "
265 "your matrix fill on at least one MPI rank:\n"
266 " locally, there are " +
267 std::to_string(lclCount) +
268 " col gids not connected to any owned gid.\n"
269 " globally, there are " +
270 std::to_string(gblCount) +
271 " col gids not connected to any owned gid.\n"
272 "NOTE: you can disable this check by setting a parameter list with the option\n"
273 " 'Check Col GIDs In At Least One Owned Row' set to false.\n"
274 "NOTE: the parameter list must be set AFTER construction, since it would not be recognized as valid"
275 "by the base class CrsGraph.\n");
279 inactiveCrsGraph_ = Teuchos::rcp(
new crs_graph_type(*
this, ownedRowMap));
280 inactiveCrsGraph_->fillComplete(ownedDomainMap_, ownedRangeMap_);
284template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
285void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::doOwnedToOwnedPlusShared(
const CombineMode ) {
289template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
291 if (*activeCrsGraph_ == FE::ACTIVE_OWNED_PLUS_SHARED)
292 *activeCrsGraph_ = FE::ACTIVE_OWNED;
294 *activeCrsGraph_ = FE::ACTIVE_OWNED_PLUS_SHARED;
296 if (inactiveCrsGraph_.is_null())
return;
298 this->swap(*inactiveCrsGraph_);
302template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
304 const Teuchos::RCP<const map_type>& domainMap,
305 const Teuchos::RCP<const map_type>&
rangeMap) {
325 const char tfecfFuncName[] =
"FECrsGraph::endFill(domainMap, rangeMap): ";
327 if (ownedRowsImporter_.is_null()) {
329 switchActiveCrsGraph();
339 switchActiveCrsGraph();
343template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
344void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::endFill() {
345 this->endFill(ownedDomainMap_, ownedRangeMap_);
348template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
349void FECrsGraph<LocalOrdinal, GlobalOrdinal, Node>::beginFill() {
350 const char tfecfFuncName[] =
"FECrsGraph::beginFill(): ";
354 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(*activeCrsGraph_ == FE::ACTIVE_OWNED, std::runtime_error,
"can only be called once.");
357template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
361 *fillState_ != FE::FillState::closed,
363 "Cannot beginAssembly, matrix is not in a closed state");
364 *fillState_ = FE::FillState::open;
368template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
372 *fillState_ != FE::FillState::open,
374 "Cannot endAssembly, matrix is not open to fill but is closed.");
375 *fillState_ = FE::FillState::closed;
379template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
381 const Teuchos::RCP<const map_type>& domainMap,
382 const Teuchos::RCP<const map_type>&
rangeMap) {
385 *fillState_ != FE::FillState::open,
387 "Cannot endAssembly, matrix is not open to fill but is closed.");
388 *fillState_ = FE::FillState::closed;
392template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
393Teuchos::RCP<const Teuchos::ParameterList>
395 auto valid_pl = Teuchos::rcp(
new Teuchos::ParameterList(
"Tpetra::FECrsGraph"));
396 valid_pl->validateParametersAndSetDefaults(*crs_graph_type::getValidParameters());
397 valid_pl->set(
"Check Col GIDs In At Least One Owned Row",
true);
402template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
408 const char tfecfFuncName[] =
"FECrsGraph::insertGlobalIndices: ";
410 *fillState_ != FE::FillState::open,
412 "Cannot replace global values, matrix is not open to fill but is closed.");
416template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
422 std::function<
void(
const size_t,
const size_t,
const size_t)>
fun) {
423 const char tfecfFuncName[] =
"FECrsGraph::insertGlobalIndices: ";
425 *fillState_ != FE::FillState::open,
427 "Cannot replace global values, matrix is not open to fill but is closed.");
431template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
433 const local_ordinal_type
lclRow,
434 const Teuchos::ArrayView<const local_ordinal_type>&
gblColInds,
435 std::function<
void(
const size_t,
const size_t,
const size_t)>
fun) {
436 const char tfecfFuncName[] =
"FECrsGraph::insertLocalIndices: ";
438 *fillState_ != FE::FillState::open,
440 "Cannot replace global values, matrix is not open to fill but is closed.");
451#define TPETRA_FECRSGRAPH_INSTANT(LO, GO, NODE) \
452 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.