49 #ifndef XPETRA_STRIDEDMAP_HPP 50 #define XPETRA_STRIDEDMAP_HPP 56 #include <Teuchos_Describable.hpp> 95 template <class LocalOrdinal = Map<>::local_ordinal_type,
98 class StridedMap :
public virtual Map<LocalOrdinal, GlobalOrdinal, Node> {
110 return KokkosClassic::Details::getNode<Node>();
116 #undef XPETRA_STRIDEDMAP_SHORT 145 GlobalOrdinal indexBase,
146 std::vector<size_t>& stridingInfo,
148 LocalOrdinal stridedBlockId = -1,
149 GlobalOrdinal offset = 0,
160 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
163 std::invalid_argument,
164 "StridedMap::StridedMap: numGlobalElements is invalid");
165 TEUCHOS_TEST_FOR_EXCEPTION(
167 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize " 168 "is not an integer multiple of numGlobalElements.");
169 if (stridedBlockId != -1)
170 TEUCHOS_TEST_FOR_EXCEPTION(
171 stridingInfo.size() <
static_cast<size_t> (stridedBlockId),
173 "stridedBlockId > stridingInfo.size()");
176 if (blkSize != 1 ||
offset_ != 0) {
185 size_t nStridedOffset = 0;
186 size_t nDofsPerNode = blkSize;
187 if (stridedBlockId > -1) {
188 for (
int j = 0; j < stridedBlockId; j++)
192 numGlobalElements = numGlobalNodes * Teuchos::as<global_size_t>(nDofsPerNode);
194 size_t numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
196 std::vector<GlobalOrdinal> dofgids(numLocalElements);
197 for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
198 GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
200 for (
size_t j = 0; j < nDofsPerNode; j++)
201 dofgids[i*nDofsPerNode + j] =
indexBase_ +
offset_ + (nodeGID -
indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
206 if (stridedBlockId == -1) {
208 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
210 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
213 size_t nDofsInStridedBlock = stridingInfo[stridedBlockId];
215 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
217 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
254 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
257 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
258 #ifdef HAVE_TPETRA_DEBUG 261 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<global_size_t>(numLocalElements), Teuchos::outArg(sumLocalElements));
263 "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
267 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numLocalElements.");
268 if (stridedBlockId != -1)
270 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
273 if (blkSize != 1 ||
offset_ != 0) {
277 numGlobalNodes = numGlobalElements / blkSize;
284 size_t nStridedOffset = 0;
285 size_t nDofsPerNode = blkSize;
286 if (stridedBlockId > -1) {
287 for (
int j = 0; j < stridedBlockId; j++)
291 numGlobalElements = nodeMap->getGlobalNumElements() * Teuchos::as<global_size_t>(nDofsPerNode);
293 numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
295 std::vector<GlobalOrdinal> dofgids(numLocalElements);
296 for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
297 GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
299 for (
size_t j = 0; j < nDofsPerNode; j++)
300 dofgids[i*nDofsPerNode + j] =
indexBase_ +
offset_ + (nodeGID -
indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
305 if (stridedBlockId == -1) {
307 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
309 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
312 int nDofsInStridedBlock = stridingInfo[stridedBlockId];
314 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
316 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
344 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
345 if (stridedBlockId != -1)
347 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
350 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
351 #ifdef HAVE_TPETRA_DEBUG 354 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, numLocalElements, Teuchos::outArg(sumLocalElements));
356 "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
360 if (stridedBlockId == -1) {
365 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of elementList.size().");
372 "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not an integer multiple of elementList.size().");
381 for (Teuchos_Ordinal k = 0; k < elementList.
size(); k++)
382 if (elementList[k] < minGidOnCurProc)
383 minGidOnCurProc = elementList[k];
388 size_t nStridedOffset = 0;
389 for (
int j = 0; j < stridedBlockId; j++)
390 nStridedOffset += stridingInfo[j];
391 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
399 StridedMap(
const RCP<const Map>& map, std::vector<size_t>& stridingInfo, GlobalOrdinal indexBase, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0)
406 if(Teuchos::rcp_dynamic_cast<const StridedMap>(map) == Teuchos::null)
409 map_ = map->getMap();
452 size_t nStridedOffset = 0;
453 size_t stridedBlockId = 0;
456 if (Teuchos::as<size_t>(tgid) < nStridedOffset) {
461 return stridedBlockId;
507 #ifndef HAVE_XPETRA_DEBUG 521 if (dofGids.
size() == 0)
529 size_t nStridedOffset = 0;
533 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
536 GlobalOrdinal cnt = 0;
538 const GlobalOrdinal first_gid = dofGids[i];
545 const GlobalOrdinal gid = dofGids[i+j];
546 const GlobalOrdinal r = (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset -
offset_ -
indexBase_) /
549 std::cout <<
"goZeroOffset : " << goZeroOffset << std::endl
550 <<
"dofGids[0] : " << dofGids[0] << std::endl
551 <<
"stridedOffset : " << nStridedOffset << std::endl
552 <<
"offset_ : " <<
offset_ << std::endl
553 <<
"goStridedOffset: " << goStridedOffset << std::endl
555 <<
"gid: " << gid <<
" GID: " << r << std::endl;
610 LocalOrdinal
getLocalElement(GlobalOrdinal globalIndex)
const {
return map_->getLocalElement(globalIndex); }
613 GlobalOrdinal
getGlobalElement(LocalOrdinal localIndex)
const {
return map_->getGlobalElement(localIndex); }
617 return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
622 return map_->getRemoteIndexList(GIDList, nodeIDList);
629 bool isNodeLocalElement(LocalOrdinal localIndex)
const {
return map_->isNodeLocalElement(localIndex); }
632 bool isNodeGlobalElement(GlobalOrdinal globalIndex)
const {
return map_->isNodeGlobalElement(globalIndex); }
646 bool isSameAs(
const Map& map)
const {
return map_->isSameAs(map); }
670 #define XPETRA_STRIDEDMAP_SHORT 671 #endif // XPETRA_STRIDEDMAP_HPP
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
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, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with Xpetra-defined contiguous uniform distribution.
static Teuchos::RCP< Node > defaultArgNode()
RCP< const Map > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
LocalOrdinal local_ordinal_type
GlobalOrdinal global_ordinal_type
GlobalOrdinal global_ordinal_type
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.
Teuchos::RCP< Node > getNode() const
Get the Node object for this Map.
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...
StridedMap(const RCP< const Map > &map, std::vector< size_t > &stridingInfo, GlobalOrdinal indexBase, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
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)
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, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with contiguous uniform distribution.
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
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, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with a user-defined contiguous distribution.
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.
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, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with user-defined non-contiguous (arbitrary) distribution.
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.
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_