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)
445 size_t nStridedOffset = 0;
446 size_t stridedBlockId = 0;
449 if (Teuchos::as<size_t>(tgid) < nStridedOffset) {
454 return stridedBlockId;
500 #ifndef HAVE_XPETRA_DEBUG 514 if (dofGids.
size() == 0)
522 size_t nStridedOffset = 0;
526 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
529 GlobalOrdinal cnt = 0;
531 const GlobalOrdinal first_gid = dofGids[i];
538 const GlobalOrdinal gid = dofGids[i+j];
539 const GlobalOrdinal r = (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset -
offset_ -
indexBase_) /
542 std::cout <<
"goZeroOffset : " << goZeroOffset << std::endl
543 <<
"dofGids[0] : " << dofGids[0] << std::endl
544 <<
"stridedOffset : " << nStridedOffset << std::endl
545 <<
"offset_ : " <<
offset_ << std::endl
546 <<
"goStridedOffset: " << goStridedOffset << std::endl
548 <<
"gid: " << gid <<
" GID: " << r << std::endl;
603 LocalOrdinal
getLocalElement(GlobalOrdinal globalIndex)
const {
return map_->getLocalElement(globalIndex); }
606 GlobalOrdinal
getGlobalElement(LocalOrdinal localIndex)
const {
return map_->getGlobalElement(localIndex); }
610 return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
615 return map_->getRemoteIndexList(GIDList, nodeIDList);
622 bool isNodeLocalElement(LocalOrdinal localIndex)
const {
return map_->isNodeLocalElement(localIndex); }
625 bool isNodeGlobalElement(GlobalOrdinal globalIndex)
const {
return map_->isNodeGlobalElement(globalIndex); }
639 bool isSameAs(
const Map& map)
const {
return map_->isSameAs(map); }
663 #define XPETRA_STRIDEDMAP_SHORT 664 #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)
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.
RCP< const Map > getMap() const
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?)
bool isStrided()
returns true, if this is a strided map (i.e. more than 1 strided blocks)
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)