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> {
107 #undef XPETRA_STRIDEDMAP_SHORT 136 GlobalOrdinal indexBase,
137 std::vector<size_t>& stridingInfo,
139 LocalOrdinal stridedBlockId = -1,
140 GlobalOrdinal offset = 0,
151 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
154 std::invalid_argument,
155 "StridedMap::StridedMap: numGlobalElements is invalid");
156 TEUCHOS_TEST_FOR_EXCEPTION(
158 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize " 159 "is not an integer multiple of numGlobalElements.");
160 if (stridedBlockId != -1)
161 TEUCHOS_TEST_FOR_EXCEPTION(
162 stridingInfo.size() <
static_cast<size_t> (stridedBlockId),
164 "stridedBlockId > stridingInfo.size()");
167 if (blkSize != 1 ||
offset_ != 0) {
176 size_t nStridedOffset = 0;
177 size_t nDofsPerNode = blkSize;
178 if (stridedBlockId > -1) {
179 for (
int j = 0; j < stridedBlockId; j++)
183 numGlobalElements = numGlobalNodes * Teuchos::as<global_size_t>(nDofsPerNode);
185 size_t numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
187 std::vector<GlobalOrdinal> dofgids(numLocalElements);
188 for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
189 GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
191 for (
size_t j = 0; j < nDofsPerNode; j++)
192 dofgids[i*nDofsPerNode + j] =
indexBase_ +
offset_ + (nodeGID -
indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
197 if (stridedBlockId == -1) {
199 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
201 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
204 size_t nDofsInStridedBlock = stridingInfo[stridedBlockId];
206 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
208 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
245 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
248 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
249 #ifdef HAVE_XPETRA_DEBUG 252 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<global_size_t>(numLocalElements), Teuchos::outArg(sumLocalElements));
254 "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
258 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numLocalElements.");
259 if (stridedBlockId != -1)
261 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
264 if (blkSize != 1 ||
offset_ != 0) {
268 numGlobalNodes = numGlobalElements / blkSize;
275 size_t nStridedOffset = 0;
276 size_t nDofsPerNode = blkSize;
277 if (stridedBlockId > -1) {
278 for (
int j = 0; j < stridedBlockId; j++)
282 numGlobalElements = nodeMap->getGlobalNumElements() * Teuchos::as<global_size_t>(nDofsPerNode);
284 numLocalElements = numLocalNodes * Teuchos::as<size_t>(nDofsPerNode);
286 std::vector<GlobalOrdinal> dofgids(numLocalElements);
287 for (LocalOrdinal i = 0; i < Teuchos::as<LocalOrdinal>(numLocalNodes); i++) {
288 GlobalOrdinal nodeGID = nodeMap->getGlobalElement(i);
290 for (
size_t j = 0; j < nDofsPerNode; j++)
291 dofgids[i*nDofsPerNode + j] =
indexBase_ +
offset_ + (nodeGID -
indexBase_)*Teuchos::as<GlobalOrdinal>(blkSize) + Teuchos::as<GlobalOrdinal>(nStridedOffset + j);
296 if (stridedBlockId == -1) {
298 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
300 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
303 int nDofsInStridedBlock = stridingInfo[stridedBlockId];
305 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
307 "StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
335 "StridedMap::StridedMap: stridingInfo not valid: stridingInfo.size() = 0?");
336 if (stridedBlockId != -1)
338 "StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
341 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of numGlobalElements.");
342 #ifdef HAVE_XPETRA_DEBUG 345 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, numLocalElements, Teuchos::outArg(sumLocalElements));
347 "StridedMap::StridedMap: sum of numbers of local elements is different from the provided number of global elements.");
351 if (stridedBlockId == -1) {
356 "StridedMap::StridedMap: stridingInfo not valid: getFixedBlockSize is not an integer multiple of elementList.size().");
363 "StridedMap::StridedMap: stridingInfo not valid: stridingBlockInfo[stridedBlockId] is not an integer multiple of elementList.size().");
372 for (Teuchos_Ordinal k = 0; k < elementList.
size(); k++)
373 if (elementList[k] < minGidOnCurProc)
374 minGidOnCurProc = elementList[k];
379 size_t nStridedOffset = 0;
380 for (
int j = 0; j < stridedBlockId; j++)
381 nStridedOffset += stridingInfo[j];
382 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
390 StridedMap(
const RCP<const Map>& map, std::vector<size_t>& stridingInfo, GlobalOrdinal indexBase, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0)
397 if(Teuchos::rcp_dynamic_cast<const StridedMap>(map) == Teuchos::null)
400 map_ = map->getMap();
443 size_t nStridedOffset = 0;
444 size_t stridedBlockId = 0;
447 if (Teuchos::as<size_t>(tgid) < nStridedOffset) {
452 return stridedBlockId;
460 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR 461 #ifdef HAVE_XPETRA_TPETRA 464 local_map_type getLocalMap ()
const {
465 return map_->getLocalMap();
469 #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." 512 #ifndef HAVE_XPETRA_DEBUG 526 if (dofGids.
size() == 0)
534 size_t nStridedOffset = 0;
538 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
541 GlobalOrdinal cnt = 0;
543 const GlobalOrdinal first_gid = dofGids[i];
550 const GlobalOrdinal gid = dofGids[i+j];
551 const GlobalOrdinal r = (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset -
offset_ -
indexBase_) /
558 std::cout <<
"goZeroOffset : " << goZeroOffset << std::endl
559 <<
"dofGids[0] : " << dofGids[0] << std::endl
560 <<
"stridedOffset : " << nStridedOffset << std::endl
561 <<
"offset_ : " <<
offset_ << std::endl
562 <<
"goStridedOffset: " << goStridedOffset << std::endl
564 <<
"gid: " << gid <<
" GID: " << r << std::endl;
619 LocalOrdinal
getLocalElement(GlobalOrdinal globalIndex)
const {
return map_->getLocalElement(globalIndex); }
622 GlobalOrdinal
getGlobalElement(LocalOrdinal localIndex)
const {
return map_->getGlobalElement(localIndex); }
626 return map_->getRemoteIndexList(GIDList, nodeIDList, LIDList);
631 return map_->getRemoteIndexList(GIDList, nodeIDList);
638 bool isNodeLocalElement(LocalOrdinal localIndex)
const {
return map_->isNodeLocalElement(localIndex); }
641 bool isNodeGlobalElement(GlobalOrdinal globalIndex)
const {
return map_->isNodeGlobalElement(globalIndex); }
655 bool isSameAs(
const Map& map)
const {
return map_->isSameAs(map); }
679 #define XPETRA_STRIDEDMAP_SHORT 680 #endif // XPETRA_STRIDEDMAP_HPP 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=Teuchos::rcp(new Node))
Map constructor with user-defined non-contiguous (arbitrary) distribution.
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=Teuchos::rcp(new Node))
Map constructor with a user-defined contiguous distribution.
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
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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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)
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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)
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
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.
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
size_t global_size_t
Global size_t object.
static const EVerbosityLevel verbLevel_default
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.
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
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 > &=Teuchos::null)
Map constructor with Xpetra-defined contiguous uniform distribution.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
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=Teuchos::rcp(new Node))
Map constructor with contiguous uniform distribution.
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.