10 #ifndef PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DEF_HPP_
11 #define PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DEF_HPP_
17 #include "Xpetra_MapFactory.hpp"
21 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
27 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
29 BlockedMap(
const RCP<const Map>& fullmap,
const std::vector<RCP<const Map>>& maps,
bool bThyraMode) {
30 bThyraMode_ = bThyraMode;
32 if (bThyraMode ==
false) {
37 size_t numAllElements = 0;
38 for (
size_t v = 0; v < maps.size(); ++v) {
39 numAllElements += maps[v]->getGlobalNumElements();
41 TEUCHOS_TEST_FOR_EXCEPTION(fullmap->getGlobalNumElements() != numAllElements,
43 "logic error. full map and sub maps have not same number of elements ("
44 << fullmap->getGlobalNumElements() <<
" versus " << numAllElements
45 <<
"). We cannot build MapExtractor with Xpetra-style numbering. Please make sure that you want "
46 "Xpetra-style numbering instead of Thyra-style numbering.");
56 for (
size_t v = 0; v < maps.size(); ++v) {
57 TEUCHOS_TEST_FOR_EXCEPTION(maps[v]->getMinAllGlobalIndex() != 0,
59 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID. Map block "
60 << v <<
" starts with GID " << maps[v]->getMinAllGlobalIndex());
67 std::vector<GlobalOrdinal> gidOffsets(maps.size(), 0);
68 for (
size_t v = 1; v < maps.size(); ++v) {
69 gidOffsets[v] = maps[v - 1]->getMaxAllGlobalIndex() + gidOffsets[v - 1] + 1;
73 maps_.resize(maps.size());
74 std::vector<GlobalOrdinal> fullMapGids;
75 const GO INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
76 for (
size_t v = 0; v < maps.size(); ++v) {
77 size_t myNumElements = maps[v]->getLocalNumElements();
78 std::vector<GlobalOrdinal> subMapGids(myNumElements, 0);
79 for (LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l) {
80 GlobalOrdinal myGid = maps[v]->getGlobalElement(l);
81 subMapGids[l] = myGid + gidOffsets[v];
82 fullMapGids.push_back(myGid + gidOffsets[v]);
87 Teuchos::ArrayView<GlobalOrdinal> subMapGidsView(&subMapGids[0], subMapGids.size());
90 maps[v]->lib(), INVALID, subMapGidsView, maps[v]->getIndexBase(), maps[v]->getComm());
101 Teuchos::ArrayView<GlobalOrdinal> fullMapGidsView(&fullMapGids[0], fullMapGids.size());
104 fullmap->lib(), INVALID, fullMapGidsView, fullmap->getIndexBase(), fullmap->getComm());
107 size_t numAllElements = 0;
108 for (
size_t v = 0; v < maps_.size(); ++v) {
109 numAllElements += maps_[v]->getGlobalNumElements();
111 TEUCHOS_TEST_FOR_EXCEPTION(
112 fullmap_->getGlobalNumElements() != numAllElements,
114 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
118 importers_.resize(maps_.size());
119 for (
unsigned i = 0; i < maps_.size(); ++i) {
120 if (maps[i] != null) {
124 TEUCHOS_TEST_FOR_EXCEPTION(
125 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
128 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
130 BlockedMap(
const std::vector<RCP<const Map>>& maps,
const std::vector<RCP<const Map>>& thyramaps) {
134 TEUCHOS_TEST_FOR_EXCEPTION(thyramaps.size() != maps.size(), std::logic_error,
"logic error. The number of submaps must be identical!");
135 for (
size_t v = 0; v < thyramaps.size(); ++v) {
136 TEUCHOS_TEST_FOR_EXCEPTION(thyramaps[v]->getMinAllGlobalIndex() != 0,
138 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID.");
142 "logic error. The size of the submaps must be identical (same distribution, just different GIDs)");
146 thyraMaps_ = thyramaps;
148 fullmap_ = this->concatenateMaps(maps);
151 size_t numAllElements = 0;
152 for (
size_t v = 0; v < maps_.size(); ++v) {
153 numAllElements += maps_[v]->getGlobalNumElements();
155 TEUCHOS_TEST_FOR_EXCEPTION(
156 fullmap_->getGlobalNumElements() != numAllElements,
158 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
161 importers_.resize(maps_.size());
162 for (
unsigned i = 0; i < maps_.size(); ++i) {
163 if (maps[i] != null) {
167 TEUCHOS_TEST_FOR_EXCEPTION(
168 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
171 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 fullmap_ = Teuchos::null;
176 maps_.resize(input.
getNumMaps(), Teuchos::null);
177 thyraMaps_.resize(input.
getNumMaps(), Teuchos::null);
181 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
185 for (
size_t v = 0; v < maps_.size(); ++v) {
186 maps_[v] = Teuchos::null;
187 if (bThyraMode_ ==
true)
188 thyraMaps_[v] = Teuchos::null;
189 importers_[v] = Teuchos::null;
192 fullmap_ = Teuchos::null;
195 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
199 return fullmap_->getGlobalNumElements();
202 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
205 return fullmap_->getLocalNumElements();
208 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
212 return fullmap_->getIndexBase();
215 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
219 return fullmap_->getMinLocalIndex();
222 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 return fullmap_->getMaxLocalIndex();
229 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
233 return fullmap_->getMinGlobalIndex();
236 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
240 return fullmap_->getMaxGlobalIndex();
243 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
247 return fullmap_->getMinAllGlobalIndex();
250 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
254 return fullmap_->getMaxAllGlobalIndex();
257 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
261 return fullmap_->getLocalElement(globalIndex);
264 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
268 return fullmap_->getGlobalElement(localIndex);
271 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
275 const Teuchos::ArrayView<int>& ,
276 const Teuchos::ArrayView<LocalOrdinal>& )
const {
281 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
285 const Teuchos::ArrayView<int>& )
const {
290 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
291 Teuchos::ArrayView<const GlobalOrdinal>
294 return fullmap_->getLocalElementList();
297 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
301 return fullmap_->getMyGlobalIndicesDevice();
304 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
307 return fullmap_->isNodeLocalElement(localIndex);
310 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
313 return fullmap_->isNodeGlobalElement(globalIndex);
316 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
320 TEUCHOS_UNREACHABLE_RETURN(
false);
323 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
326 return fullmap_->isDistributed();
329 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
332 RCP<const Map> rcpMap = Teuchos::rcpFromRef(map);
333 RCP<const BlockedMap> rcpBMap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(rcpMap);
334 if (rcpBMap.is_null() ==
true)
337 for (
size_t v = 0; v < maps_.size(); ++v) {
338 bool bSame = getMap(v,
false)->
isCompatible(*(rcpBMap->getMap(v,
false)));
342 bSame = getMap(v,
true)->isCompatible(*(rcpBMap->getMap(v,
true)));
348 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
351 RCP<const Map> rcpMap = Teuchos::rcpFromRef(map);
352 RCP<const BlockedMap> rcpBMap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(rcpMap);
353 if (rcpBMap.is_null() ==
true) {
355 if (this->getNumMaps() > 1) {
360 bool bSame = getMap(0, bThyraMode_)->
isSameAs(*rcpMap);
364 for (
size_t v = 0; v < maps_.size(); ++v) {
365 bool bSame = getMap(v,
false)->isSameAs(*(rcpBMap->getMap(v,
false)));
366 if (bSame ==
false) {
370 bSame = getMap(v,
true)->isSameAs(*(rcpBMap->getMap(v,
true)));
371 if (bSame ==
false) {
379 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
380 Teuchos::RCP<const Teuchos::Comm<int>>
383 return fullmap_->getComm();
386 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
394 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
399 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
400 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
406 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
407 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
413 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
416 return fullmap_->lib();
419 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
420 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
426 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
433 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
434 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
437 bool bThyraMode)
const {
440 "BlockedMap::getMap: tried to access block " << i <<
", but BlockedMap has only " << getNumMaps()
441 <<
" blocks! Block indices must be between 0 and " << getNumMaps() - 1
443 if (bThyraMode_ ==
true && bThyraMode ==
true) {
444 return thyraMaps_[i];
449 "BlockedMap::getMap: cannot return sub map in Thyra-style numbering if BlockedMap object is not created using "
450 "Thyra-style numbered submaps.");
454 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
455 const RCP<Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node>>
460 "BlockedMap::getImporter: tried to access block " << i <<
", but BlockedMap has only " << getNumMaps()
461 <<
" blocks! Block indices must be between 0 and " << getNumMaps() - 1
463 return importers_[i];
466 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
467 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
473 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
477 for (
size_t i = 0; i < getNumMaps(); i++)
478 if (getMap(i)->isNodeGlobalElement(gid) ==
true)
481 TEUCHOS_TEST_FOR_EXCEPTION(
486 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
490 return std::string(
"BlockedMap");
493 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
495 describe(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const {
496 out <<
"------------- Blocked Map -----------" << std::endl;
497 out << description() << std::endl;
498 out <<
"Thyra mode: " << getThyraMode() << std::endl;
499 out <<
"No of submaps: " << getNumMaps() << std::endl;
500 Teuchos::OSTab tab(out);
501 for (
size_t r = 0; r < getNumMaps(); r++) {
502 std::cout <<
"MAP " << r <<
"/" << getNumMaps() - 1 << std::endl;
503 getMap(r,
false)->describe(out, verbLevel);
505 if (getThyraMode() ==
true) {
506 for (
size_t r = 0; r < getNumMaps(); r++) {
507 std::cout <<
"Thyra MAP " << r <<
"/" << getNumMaps() - 1 << std::endl;
508 getMap(r,
true)->describe(out, verbLevel);
511 out <<
"-------------------------------------" << std::endl;
514 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
522 maps_.resize(input.
getNumMaps(), Teuchos::null);
523 if (bThyraMode_ ==
true)
524 thyraMaps_.resize(input.
getNumMaps(), Teuchos::null);
525 for (
size_t i = 0; i < input.
getNumMaps(); ++i) {
527 if (bThyraMode_ ==
true)
532 size_t numAllElements = 0;
533 for (
size_t v = 0; v < maps_.size(); ++v) {
534 numAllElements += maps_[v]->getGlobalNumElements();
536 TEUCHOS_TEST_FOR_EXCEPTION(
537 fullmap_->getGlobalNumElements() != numAllElements,
539 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
542 importers_.resize(maps_.size());
543 for (
unsigned i = 0; i < maps_.size(); ++i)
544 if (maps_[i] != null)
546 TEUCHOS_TEST_FOR_EXCEPTION(
547 CheckConsistency() ==
false, std::logic_error,
"logic error. full map and sub maps are inconsistently distributed over the processors.");
550 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
551 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
555 std::vector<GlobalOrdinal> gids;
556 for (
size_t tt = 0; tt < subMaps.size(); ++tt) {
557 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> subMap = subMaps[tt];
559 #if 1 // WCMCLEN : IS THIS NECESSARY TO HANG ONTO?
560 Teuchos::ArrayView<const GlobalOrdinal> subMapGids = subMap->getLocalElementList();
561 gids.insert(gids.end(), subMapGids.begin(), subMapGids.end());
563 size_t myNumElements = subMap->getLocalNumElements();
564 for (LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(myNumElements); ++l) {
565 GlobalOrdinal gid = subMap->getGlobalElement(l);
571 const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
574 Teuchos::ArrayView<GlobalOrdinal> gidsView(&gids[0], gids.size());
577 Build(subMaps[0]->lib(), INVALID, gidsView, subMaps[0]->getIndexBase(), subMaps[0]->getComm());
582 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
585 const RCP<const Map> fullMap = getFullMap();
587 for (
size_t i = 0; i < getNumMaps(); i++) {
588 const RCP<const Map> map = getMap(i);
590 ArrayView<const GlobalOrdinal> mapGids = map->getLocalElementList();
591 for (
typename ArrayView<const GlobalOrdinal>::const_iterator it = mapGids.begin(); it != mapGids.end(); it++) {
592 if (fullMap->isNodeGlobalElement(*it) ==
false) {
virtual GlobalOrdinal getIndexBase() const
The index base for this Map.
virtual std::string description() const
A simple one-line description of this object.
bool CheckConsistency() const
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map's Comm object.
virtual ~BlockedMap()
Destructor.
Exception throws to report errors in the internal logical of the program.
virtual bool isCompatible(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getFullMap() const
the full map
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
virtual global_size_t getGlobalNumElements() const
The number of elements in this Map.
virtual GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
virtual bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
const RCP< Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > > getImporter(size_t i) const
get the importer between full map and partial map
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int >> &) const
Replace this Map's communicator with a subset communicator.
virtual void assign(const BlockedMap &input)
Implementation of the assignment operator (operator=); does a deep copy.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
virtual global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process.
virtual LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &, const Teuchos::ArrayView< int > &, const Teuchos::ArrayView< LocalOrdinal > &) const
Return the process ranks and corresponding local indices for the given global indices.
virtual bool isSameAs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
virtual LocalOrdinal getMinLocalIndex() const
The minimum local index.
size_t getNumMaps() const
number of partial maps
virtual GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
virtual LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
virtual bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
BlockedMap< LocalOrdinal, GlobalOrdinal, Node > & operator=(const BlockedMap &rhs)
Assignment operator: Does a deep copy.
size_t global_size_t
Global size_t object.
Kokkos::View< const global_ordinal_type *, typename Node::device_type > global_indices_array_device_type
static Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > concatenateMaps(const std::vector< Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node >>> &subMaps)
Helper function to concatenate several maps.
virtual UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
virtual GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
virtual bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
virtual bool isContiguous() const
True if this Map is distributed contiguously, else false.
virtual size_t getLocalNumElements() const
The number of elements belonging to the calling process.
virtual GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
size_t getMapIndexForGID(GlobalOrdinal gid) const
returns map index in map extractor which contains GID
virtual bool getThyraMode() const
Local number of rows on the calling process.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
static RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &source, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &target, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying the number of non-zeros for all rows.
virtual Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a view of the global indices owned by this process.