49 #ifndef XPETRA_STRIDEDMAP_DEF_HPP
50 #define XPETRA_STRIDEDMAP_DEF_HPP
52 #include "Xpetra_StridedMap.hpp"
54 #include <Teuchos_OrdinalTraits.hpp>
57 #include "Xpetra_MapFactory.hpp"
65 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 GlobalOrdinal indexBase,
70 std::vector<size_t>& stridingInfo,
71 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
72 LocalOrdinal stridedBlockId,
75 : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), offset_(offset), indexBase_(indexBase)
81 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0,
83 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
85 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements == Teuchos::OrdinalTraits<global_size_t>::invalid(),
86 std::invalid_argument,
87 "StridedMap::StridedMap: numGlobalElements is invalid");
89 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0,
91 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize "
92 "is not an integer multiple of numGlobalElements.");
94 if(stridedBlockId != -1)
96 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() <
static_cast<size_t>(stridedBlockId),
98 "StridedTpetraMap::StridedTpetraMap: "
99 "stridedBlockId > stridingInfo.size()");
103 if(blkSize != 1 ||
offset_ != 0)
109 RCP<Map> nodeMap = MapFactory_t::Build(xlib, numGlobalNodes, indexBase, comm, lg);
113 size_t nStridedOffset = 0;
114 size_t nDofsPerNode = blkSize;
115 if(stridedBlockId > -1)
117 for(
int j = 0; j < stridedBlockId; j++)
123 numGlobalElements = numGlobalNodes * Teuchos::as<global_size_t>(nDofsPerNode);
125 size_t numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
127 std::vector<GlobalOrdinal> dofgids(numLocalElements);
128 for(LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++)
130 GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
132 for(
size_t j = 0; j < nDofsPerNode; j++)
135 + (nodeGID -
indexBase_) * Teuchos::as<GlobalOrdinal>(blkSize)
136 + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
140 map_ = MapFactory_t::Build(xlib, numGlobalElements, dofgids, indexBase, comm);
142 if(stridedBlockId == -1)
144 TEUCHOS_TEST_FOR_EXCEPTION(
getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements() * nDofsPerNode),
146 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
149 != Teuchos::as<size_t>(nodeMap->getGlobalNumElements() * nDofsPerNode),
151 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
155 size_t nDofsInStridedBlock = stridingInfo[ stridedBlockId ];
157 != Teuchos::as<size_t>(nodeMap->getNodeNumElements() * nDofsInStridedBlock),
159 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
162 != Teuchos::as<size_t>(nodeMap->getGlobalNumElements() * nDofsInStridedBlock),
164 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
169 map_ = MapFactory_t::Build(xlib, numGlobalElements, indexBase, comm, lg);
178 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
182 size_t numLocalElements,
183 GlobalOrdinal indexBase,
184 std::vector<size_t>& stridingInfo,
185 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
186 LocalOrdinal stridedBlockId,
187 GlobalOrdinal offset)
188 : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), offset_(offset), indexBase_(indexBase)
193 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0,
195 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
196 if(numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid())
198 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0,
200 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer "
201 "multiple of numGlobalElements.");
202 #ifdef HAVE_XPETRA_DEBUG
205 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<global_size_t>(numLocalElements), Teuchos::outArg(sumLocalElements));
207 TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements,
208 std::invalid_argument,
209 "StridedMap::StridedMap: sum of numbers of local elements is different from the provided "
210 "number of global elements.");
214 TEUCHOS_TEST_FOR_EXCEPTION(
215 numLocalElements % blkSize != 0,
217 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numLocalElements.");
219 if(stridedBlockId != -1)
221 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId),
223 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
227 if(blkSize != 1 ||
offset_ != 0)
230 global_size_t numGlobalNodes = Teuchos::OrdinalTraits<global_size_t>::invalid();
231 if(numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid())
233 numGlobalNodes = numGlobalElements / blkSize;
238 RCP<Map> nodeMap = MapFactory_t::Build(xlib, numGlobalNodes, numLocalNodes, indexBase, comm);
241 size_t nStridedOffset = 0;
242 size_t nDofsPerNode = blkSize;
243 if(stridedBlockId > -1)
245 for(
int j = 0; j < stridedBlockId; j++)
251 numGlobalElements = nodeMap->getGlobalNumElements() * Teuchos::as<global_size_t>(nDofsPerNode);
253 numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
255 std::vector<GlobalOrdinal> dofgids(numLocalElements);
256 for(LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++)
258 GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
260 for(
size_t j = 0; j < nDofsPerNode; j++)
263 + (nodeGID -
indexBase_) * Teuchos::as<GlobalOrdinal>(blkSize)
264 + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
268 map_ = MapFactory_t::Build(xlib, numGlobalElements, dofgids, indexBase, comm);
270 if(stridedBlockId == -1)
272 TEUCHOS_TEST_FOR_EXCEPTION(
getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements() * nDofsPerNode),
274 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
277 != Teuchos::as<size_t>(nodeMap->getGlobalNumElements() * nDofsPerNode),
279 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
283 int nDofsInStridedBlock = stridingInfo[ stridedBlockId ];
286 != Teuchos::as<size_t>(nodeMap->getNodeNumElements() * nDofsInStridedBlock),
288 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
291 != Teuchos::as<size_t>(nodeMap->getGlobalNumElements() * nDofsInStridedBlock),
293 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
298 map_ = MapFactory_t::Build(xlib, numGlobalElements, numLocalElements, indexBase, comm);
307 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
311 const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
312 GlobalOrdinal indexBase,
313 std::vector<size_t>& stridingInfo,
314 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
315 LocalOrdinal stridedBlockId)
316 : stridingInfo_(stridingInfo), stridedBlockId_(stridedBlockId), indexBase_(indexBase)
322 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() == 0,
324 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
325 if(stridedBlockId != -1)
326 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId),
328 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
329 if(numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid())
331 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements % blkSize != 0,
333 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer "
334 "multiple of numGlobalElements.");
335 #ifdef HAVE_XPETRA_DEBUG
337 global_size_t sumLocalElements, numLocalElements = elementList.size();
338 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, numLocalElements, Teuchos::outArg(sumLocalElements));
339 TEUCHOS_TEST_FOR_EXCEPTION(sumLocalElements != numGlobalElements,
340 std::invalid_argument,
341 "StridedMap::StridedMap: sum of numbers of local elements is different from the provided "
342 "number of global elements.");
346 if(stridedBlockId == -1)
352 TEUCHOS_TEST_FOR_EXCEPTION(elementList.size() % blkSize != 0,
354 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer "
355 "multiple of elementList.size().");
363 TEUCHOS_TEST_FOR_EXCEPTION(elementList.size() % stridingInfo[ stridedBlockId ] != 0,
365 "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not "
366 "an integer multiple of elementList.size().");
369 map_ = MapFactory_t::Build(xlib, numGlobalElements, elementList, indexBase, comm);
374 GlobalOrdinal minGidOnCurProc = Teuchos::OrdinalTraits<GlobalOrdinal>::max();
375 for(Teuchos_Ordinal k = 0; k < elementList.size(); k++)
377 if(elementList[ k ] < minGidOnCurProc)
379 minGidOnCurProc = elementList[ k ];
383 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, minGidOnCurProc, Teuchos::outArg(
offset_));
386 size_t nStridedOffset = 0;
387 for(
int j = 0; j < stridedBlockId; j++)
389 nStridedOffset += stridingInfo[ j ];
391 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
400 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
403 std::vector<size_t>& stridingInfo,
405 LocalOrdinal stridedBlockId,
406 GlobalOrdinal offset)
407 : stridingInfo_(stridingInfo),
408 stridedBlockId_(stridedBlockId),
410 indexBase_(map->getIndexBase())
416 if(Teuchos::rcp_dynamic_cast<const StridedMap>(map) == Teuchos::null)
422 map_ = map->getMap();
427 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
434 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
439 return stridingInfo_;
443 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
448 stridingInfo_ = stridingInfo;
452 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
458 for(std::vector<size_t>::const_iterator it = stridingInfo_.begin(); it != stridingInfo_.end(); ++it)
466 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
471 return stridedBlockId_;
475 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
480 return stridingInfo_.size() > 1 ?
true :
false;
484 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
489 return getFixedBlockSize() > 1 ?
true :
false;
493 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
502 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
511 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
516 GlobalOrdinal tgid = gid - offset_ - indexBase_;
517 tgid = tgid % getFixedBlockSize();
519 size_t nStridedOffset = 0;
520 size_t stridedBlockId = 0;
521 for(
size_t j = 0; j < stridingInfo_.size(); j++)
523 nStridedOffset += stridingInfo_[ j ];
524 if(Teuchos::as<size_t>(tgid) < nStridedOffset)
530 return stridedBlockId;
534 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
535 RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
543 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
548 #ifndef HAVE_XPETRA_DEBUG
551 if(getStridedBlockId() == -1)
554 if(getNodeNumElements() % getFixedBlockSize() != 0 ||
555 getGlobalNumElements() % getFixedBlockSize() != 0)
561 Teuchos::ArrayView<const GlobalOrdinal> dofGids = getNodeElementList();
564 if(dofGids.size() == 0)
569 if(dofGids.size() % stridingInfo_[ stridedBlockId_ ] != 0)
576 size_t nStridedOffset = 0;
577 for(
int j = 0; j < stridedBlockId_; j++)
579 nStridedOffset += stridingInfo_[ j ];
582 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
583 const GlobalOrdinal goZeroOffset = (dofGids[ 0 ] - nStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize());
585 GlobalOrdinal cnt = 0;
587 i < Teuchos::as<size_t>(dofGids.size()) / stridingInfo_[ stridedBlockId_ ];
588 i += stridingInfo_[ stridedBlockId_ ])
590 const GlobalOrdinal first_gid = dofGids[ i ];
593 cnt = (first_gid - goStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset;
596 for(
size_t j = 0; j < stridingInfo_[ stridedBlockId_ ]; j++)
598 const GlobalOrdinal gid = dofGids[ i + j ];
599 const GlobalOrdinal r = (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset - offset_ - indexBase_)
600 / Teuchos::as<GlobalOrdinal>(getFixedBlockSize())
601 - goZeroOffset - cnt;
608 std::cout <<
"goZeroOffset : " << goZeroOffset << std::endl
609 <<
"dofGids[0] : " << dofGids[ 0 ] << std::endl
610 <<
"stridedOffset : " << nStridedOffset << std::endl
611 <<
"offset_ : " << offset_ << std::endl
612 <<
"goStridedOffset: " << goStridedOffset << std::endl
613 <<
"getFixedBlkSize: " << getFixedBlockSize() << std::endl
614 <<
"gid: " << gid <<
" GID: " << r << std::endl;
627 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
632 return map_->getGlobalNumElements();
636 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
641 return map_->getNodeNumElements();
645 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
650 return map_->getIndexBase();
654 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
659 return map_->getMinLocalIndex();
663 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
668 return map_->getMaxLocalIndex();
672 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
677 return map_->getMinGlobalIndex();
681 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
686 return map_->getMaxGlobalIndex();
690 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
695 return map_->getMinAllGlobalIndex();
699 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
704 return map_->getMaxAllGlobalIndex();
708 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
713 return map_->getLocalElement(globalIndex);
717 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
722 return map_->getGlobalElement(localIndex);
726 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
730 const Teuchos::ArrayView<int>& nodeIDList,
731 const Teuchos::ArrayView<LocalOrdinal>& LIDList)
const
733 return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
737 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
741 const Teuchos::ArrayView<int>& nodeIDList)
const
743 return map_->getRemoteIndexList(GIDList, nodeIDList);
747 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
748 Teuchos::ArrayView<const GlobalOrdinal>
752 return map_->getNodeElementList();
756 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
761 return map_->isNodeLocalElement(localIndex);
765 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
770 return map_->isNodeGlobalElement(globalIndex);
774 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
779 return map_->isContiguous();
783 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
788 return map_->isDistributed();
792 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
797 return map_->isCompatible(map);
801 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
806 return map_->isSameAs(map);
810 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
811 Teuchos::RCP<const Teuchos::Comm<int>>
815 return map_->getComm();
821 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
822 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>>
826 return map_->removeEmptyProcesses();
830 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
831 RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>>
835 return map_->replaceCommWithSubset(newComm);
839 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
844 return map_->description();
848 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
851 describe(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const
853 map_->describe(out, verbLevel);
857 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
871 #endif // XPETRA_STRIDEDMAP_DEF_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.
size_t GID2StridingBlockId(GlobalOrdinal gid) const
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
void setStridingData(std::vector< size_t > stridingInfo)
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.
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...
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)
RCP< const Map > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
RCP< const Map > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int >> &newComm) 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)
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.
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
virtual bool CheckConsistency()
std::vector< size_t > getStridingData() const
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
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.
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.
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.
virtual ~StridedMap()
Destructor.
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_