49 #ifndef XPETRA_STRIDEDMAP_HPP 50 #define XPETRA_STRIDEDMAP_HPP 56 #include <Teuchos_Describable.hpp> 57 #include <Teuchos_OrdinalTraits.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,
147 const Teuchos::RCP<
const Teuchos::Comm< int > >& comm,
148 LocalOrdinal stridedBlockId = -1,
149 GlobalOrdinal offset = 0,
158 TEUCHOS_TEST_FOR_EXCEPTION(
160 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
161 TEUCHOS_TEST_FOR_EXCEPTION(
162 numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid (),
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.");
248 const Teuchos::RCP<
const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0,
254 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
255 if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
257 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
258 #ifdef HAVE_XPETRA_DEBUG 261 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<global_size_t>(numLocalElements), Teuchos::outArg(sumLocalElements));
262 TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements, std::invalid_argument,
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) {
275 global_size_t numGlobalNodes = Teuchos::OrdinalTraits<global_size_t>::invalid();
276 if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid())
277 numGlobalNodes = numGlobalElements / blkSize;
281 RCP<Map> nodeMap =
MapFactory_t::Build(xlib, numGlobalNodes, numLocalNodes, indexBase, comm, node);
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.");
337 std::vector<size_t>& stridingInfo,
const Teuchos::RCP<
const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId = -1,
344 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
345 if (stridedBlockId != -1)
347 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
348 if (numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid()) {
350 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
351 #ifdef HAVE_XPETRA_DEBUG 353 global_size_t sumLocalElements, numLocalElements = elementList.size();
354 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, numLocalElements, Teuchos::outArg(sumLocalElements));
355 TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements, std::invalid_argument,
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().");
380 GlobalOrdinal minGidOnCurProc = Teuchos::OrdinalTraits<GlobalOrdinal>::max();
381 for (Teuchos_Ordinal k = 0; k < elementList.size(); k++)
382 if (elementList[k] < minGidOnCurProc)
383 minGidOnCurProc = elementList[k];
385 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, minGidOnCurProc, Teuchos::outArg(
offset_));
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;
467 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
getMap()
const {
return map_; }
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_) /
553 std::cout <<
"goZeroOffset : " << goZeroOffset << std::endl
554 <<
"dofGids[0] : " << dofGids[0] << std::endl
555 <<
"stridedOffset : " << nStridedOffset << std::endl
556 <<
"offset_ : " <<
offset_ << std::endl
557 <<
"goStridedOffset: " << goStridedOffset << std::endl
559 <<
"gid: " << gid <<
" GID: " << r << std::endl;
572 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
map_;
614 LocalOrdinal
getLocalElement(GlobalOrdinal globalIndex)
const {
return map_->getLocalElement(globalIndex); }
620 LookupStatus getRemoteIndexList(
const Teuchos::ArrayView<const GlobalOrdinal> &GIDList,
const Teuchos::ArrayView<int> &nodeIDList,
const Teuchos::ArrayView<LocalOrdinal> &LIDList)
const {
621 return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
626 return map_->getRemoteIndexList(GIDList, nodeIDList);
653 Teuchos::RCP< const Teuchos::Comm< int > >
getComm()
const {
return map_->getComm(); }
659 RCP<const Map>
replaceCommWithSubset (
const Teuchos::RCP<
const Teuchos::Comm<int> >& newComm)
const {
return map_->replaceCommWithSubset(newComm); }
665 void describe(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default)
const {
map_->describe(out, verbLevel); }
674 #define XPETRA_STRIDEDMAP_SHORT 675 #endif // XPETRA_STRIDEDMAP_HPP
bool isStrided() const
returns true, if this is a strided map (i.e. more than 1 strided blocks)
std::vector< size_t > getStridingData() const
Xpetra::MapFactory< LocalOrdinal, GlobalOrdinal, Node > MapFactory_t
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()
LocalOrdinal local_ordinal_type
GlobalOrdinal global_ordinal_type
GlobalOrdinal global_ordinal_type
GlobalOrdinal getOffset() const
bool isSameAs(const Map &map) const
Returns true if map is identical to this Map.
LocalOrdinal getMinLocalIndex() const
Returns minimum local index.
void setStridingData(std::vector< size_t > stridingInfo)
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
GlobalOrdinal indexBase_
index base for the strided map (default = 0)
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.
LocalOrdinal getMaxLocalIndex() const
Returns maximum local index.
Exception throws to report errors in the internal logical of the program.
GlobalOrdinal getMinAllGlobalIndex() const
Return the minimum global index over all nodes.
std::string description() const
Return a simple one-line description of this object.
Teuchos::RCP< Node > getNode() const
Get the Node object for this Map.
LocalOrdinal stridedBlockId_
member variable denoting which dofs are stored in map
RCP< const Map > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map's communicator with a subset communicator.
GlobalOrdinal getMaxAllGlobalIndex() const
Return the maximum global index over all nodes.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index.
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.
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
std::vector< size_t > stridingInfo_
vector with size of strided blocks (dofs)
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
virtual ~StridedMap()
Destructor.
LocalOrdinal getStridedBlockId() const
RCP< const Map > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
GlobalOrdinal offset_
offset for gids in map (default = 0)
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.
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.
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
size_t global_size_t
Global size_t object.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
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.
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...
virtual bool CheckConsistency()
size_t getFixedBlockSize() const
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.
bool isDistributed() const
Returns true if this Map is distributed across more than one node; returns false otherwise.
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...
GlobalOrdinal getMaxGlobalIndex() const
Returns maximum global index owned by this node.
bool isCompatible(const Map &map) const
Returns true if map is compatible with this Map.
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
size_t GID2StridingBlockId(GlobalOrdinal gid) const
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_
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.