49 #ifndef XPETRA_STRIDEDMAP_HPP
50 #define XPETRA_STRIDEDMAP_HPP
56 #include <Teuchos_Describable.hpp>
95 template <class LocalOrdinal = Map<>::local_ordinal_type,
96 class GlobalOrdinal =
typename Map<LocalOrdinal>::global_ordinal_type,
97 class Node =
typename Map<LocalOrdinal,GlobalOrdinal>::node_type>
98 class StridedMap :
public virtual Map<LocalOrdinal, GlobalOrdinal, Node> {
107 #undef XPETRA_STRIDEDMAP_SHORT
134 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
138 GlobalOrdinal indexBase,
139 std::vector<size_t>& stridingInfo,
141 LocalOrdinal stridedBlockId,
142 GlobalOrdinal offset,
145 : StridedMap(xlib, numGlobalElements, indexBase, stridingInfo, comm,
146 stridedBlockId, offset, lg)
148 #endif // #ifdef TPETRA_ENABLE_DEPRECATED_CODE
151 GlobalOrdinal indexBase,
152 std::vector<size_t>& stridingInfo,
154 LocalOrdinal stridedBlockId = -1,
155 GlobalOrdinal offset = 0,
165 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
168 std::invalid_argument,
169 "StridedMap::StridedMap: numGlobalElements is invalid");
170 TEUCHOS_TEST_FOR_EXCEPTION(
172 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize "
173 "is not an integer multiple of numGlobalElements.");
174 if (stridedBlockId != -1)
175 TEUCHOS_TEST_FOR_EXCEPTION(
176 stridingInfo.size() <
static_cast<size_t> (stridedBlockId),
178 "stridedBlockId > stridingInfo.size()");
181 if (blkSize != 1 ||
offset_ != 0) {
190 size_t nStridedOffset = 0;
191 size_t nDofsPerNode = blkSize;
192 if (stridedBlockId > -1) {
193 for (
int j = 0; j < stridedBlockId; j++)
197 numGlobalElements = numGlobalNodes * Teuchos::as<global_size_t>(nDofsPerNode);
199 size_t numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
201 std::vector<GlobalOrdinal> dofgids(numLocalElements);
202 for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
203 GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
205 for (
size_t j = 0; j < nDofsPerNode; j++)
206 dofgids[i*nDofsPerNode + j] =
indexBase_ +
offset_ + (nodeGID -
indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
211 if (stridedBlockId == -1) {
213 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
215 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
218 size_t nDofsInStridedBlock = stridingInfo[stridedBlockId];
220 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
222 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
252 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
257 : StridedMap(xlib, numGlobalElements, numLocalElements, indexBase,
258 stridingInfo, comm, stridedBlockId, offset)
260 #endif // TPETRA_ENABLE_DEPRECATED_CODE
267 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
270 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
271 #ifdef HAVE_XPETRA_DEBUG
276 "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
280 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numLocalElements.");
281 if (stridedBlockId != -1)
283 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
286 if (blkSize != 1 ||
offset_ != 0) {
290 numGlobalNodes = numGlobalElements / blkSize;
297 size_t nStridedOffset = 0;
298 size_t nDofsPerNode = blkSize;
299 if (stridedBlockId > -1) {
300 for (
int j = 0; j < stridedBlockId; j++)
304 numGlobalElements = nodeMap->getGlobalNumElements() * Teuchos::as<global_size_t>(nDofsPerNode);
306 numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
308 std::vector<GlobalOrdinal> dofgids(numLocalElements);
309 for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
310 GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
312 for (
size_t j = 0; j < nDofsPerNode; j++)
313 dofgids[i*nDofsPerNode + j] =
indexBase_ +
offset_ + (nodeGID -
indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
318 if (stridedBlockId == -1) {
320 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
322 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
325 int nDofsInStridedBlock = stridingInfo[stridedBlockId];
327 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
329 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
349 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
354 : StridedMap(xlib, numGlobalElements, elementList, indexBase,
355 stridingInfo, comm, stridedBlockId)
357 #endif // TPETRA_ENABLE_DEPRECATED_CODE
365 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
366 if (stridedBlockId != -1)
368 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
371 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
372 #ifdef HAVE_XPETRA_DEBUG
377 "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
381 if (stridedBlockId == -1) {
386 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of elementList.size().");
393 "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not an integer multiple of elementList.size().");
402 for (Teuchos_Ordinal k = 0; k < elementList.
size(); k++)
403 if (elementList[k] < minGidOnCurProc)
404 minGidOnCurProc = elementList[k];
409 size_t nStridedOffset = 0;
410 for (
int j = 0; j < stridedBlockId; j++)
411 nStridedOffset += stridingInfo[j];
412 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
420 StridedMap(
const RCP<const Map>& map, std::vector<size_t>& stridingInfo, GlobalOrdinal , LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0)
427 if(Teuchos::rcp_dynamic_cast<const StridedMap>(map) == Teuchos::null)
430 map_ = map->getMap();
473 size_t nStridedOffset = 0;
474 size_t stridedBlockId = 0;
477 if (Teuchos::as<size_t>(tgid) < nStridedOffset) {
482 return stridedBlockId;
490 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
491 #ifdef HAVE_XPETRA_TPETRA
494 local_map_type getLocalMap ()
const {
495 return map_->getLocalMap();
499 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
542 #ifndef HAVE_XPETRA_DEBUG
556 if (dofGids.
size() == 0)
564 size_t nStridedOffset = 0;
568 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
571 GlobalOrdinal cnt = 0;
573 const GlobalOrdinal first_gid = dofGids[i];
580 const GlobalOrdinal gid = dofGids[i+j];
581 const GlobalOrdinal r = (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset -
offset_ -
indexBase_) /
588 std::cout <<
"goZeroOffset : " << goZeroOffset << std::endl
589 <<
"dofGids[0] : " << dofGids[0] << std::endl
590 <<
"stridedOffset : " << nStridedOffset << std::endl
591 <<
"offset_ : " <<
offset_ << std::endl
592 <<
"goStridedOffset: " << goStridedOffset << std::endl
594 <<
"gid: " << gid <<
" GID: " << r << std::endl;
649 LocalOrdinal
getLocalElement(GlobalOrdinal globalIndex)
const {
return map_->getLocalElement(globalIndex); }
656 return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
661 return map_->getRemoteIndexList(GIDList, nodeIDList);
690 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
693 #endif // TPETRA_ENABLE_DEPRECATED_CODE
711 #define XPETRA_STRIDEDMAP_SHORT
712 #endif // XPETRA_STRIDEDMAP_HPP
StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0, LocalGlobal lg=GloballyDistributed)
Map constructor with contiguous uniform distribution.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Returns the node IDs and corresponding local indices for a given list of global indices.
LocalOrdinal getStridedBlockId() const
GlobalOrdinal getMaxGlobalIndex() const
Returns maximum global index owned by this node.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index.
Xpetra::MapFactory< LocalOrdinal, GlobalOrdinal, Node > MapFactory_t
size_t GID2StridingBlockId(GlobalOrdinal gid) const
RCP< const Map > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
LocalOrdinal local_ordinal_type
StridedMap(const RCP< const Map > &map, std::vector< size_t > &stridingInfo, GlobalOrdinal, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
Map constructor with a user-defined contiguous distribution.
GlobalOrdinal global_ordinal_type
StridedMap(UnderlyingLib xlib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1)
Map constructor with user-defined non-contiguous (arbitrary) distribution.
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
void setStridingData(std::vector< size_t > stridingInfo)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
GlobalOrdinal indexBase_
index base for the strided map (default = 0)
GlobalOrdinal getOffset() const
Exception throws to report errors in the internal logical of the program.
LocalOrdinal getMaxLocalIndex() const
Returns maximum local index.
LocalOrdinal stridedBlockId_
member variable denoting which dofs are stored in map
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
bool isCompatible(const Map &map) const
Returns true if map is compatible with this Map.
std::string description() const
Return a simple one-line description of this object.
GlobalOrdinal getMaxAllGlobalIndex() const
Return the maximum global index over all nodes.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Returns true if the global index is found in this Map on this node; returns false if it isn't...
bool isNodeLocalElement(LocalOrdinal localIndex) const
Returns true if the local index is valid for this Map on this node; returns false if it isn't...
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
bool isStrided() const
returns true, if this is a strided map (i.e. more than 1 strided blocks)
bool isSameAs(const Map &map) const
Returns true if map is identical to this Map.
std::vector< size_t > stridingInfo_
vector with size of strided blocks (dofs)
virtual ~StridedMap()
Destructor.
bool isDistributed() const
Returns true if this Map is distributed across more than one node; returns false otherwise.
size_t getFixedBlockSize() const
GlobalOrdinal offset_
offset for gids in map (default = 0)
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
std::vector< size_t > getStridingData() const
GlobalOrdinal getMinGlobalIndex() const
Returns minimum global index owned by this node.
size_t getNodeNumElements() const
Returns the number of elements belonging to the calling node.
size_t global_size_t
Global size_t object.
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
static const EVerbosityLevel verbLevel_default
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
LocalOrdinal getMinLocalIndex() const
Returns minimum local index.
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
GlobalOrdinal getMinAllGlobalIndex() const
Return the minimum global index over all nodes.
virtual bool CheckConsistency()
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const
Returns the node IDs for a given list of global indices.
Create an Xpetra::Map instance.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to a FancyOStream object.
RCP< const Map > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map's communicator with a subset communicator.
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.
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_