49 #ifndef XPETRA_STRIDEDTPETRAMAP_HPP 50 #define XPETRA_STRIDEDTPETRAMAP_HPP 54 #include <Tpetra_Map_decl.hpp> 63 template <
class LocalOrdinal,
class GlobalOrdinal = LocalOrdinal,
class Node = Kokkos::DefaultNode::DefaultNodeType>
64 class StridedTpetraMap
65 :
public virtual TpetraMap<LocalOrdinal,GlobalOrdinal,Node>,
public virtual StridedMap<LocalOrdinal,GlobalOrdinal,Node> {
92 :
Xpetra::
TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElements, indexBase, comm, lg, node),
Xpetra::
StridedMap<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElements, indexBase, stridingInfo, comm, stridedBlockId, offset)
97 global_size_t numGlobalNodes = Teuchos::OrdinalTraits<global_size_t>::invalid();
98 if(numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid())
99 numGlobalNodes = numGlobalElements / StridedMapClass::getFixedBlockSize();
102 RCP<Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > nodeMap = Teuchos::rcp(
new Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node >(numGlobalNodes, indexBase, comm,
toTpetra(lg), node));
105 size_t nStridedOffset = 0;
106 size_t nDofsPerNode = StridedMapClass::getFixedBlockSize();
107 if(stridedBlockId > -1) {
109 for(
int j=0; j<stridedBlockId; j++) {
110 nStridedOffset += stridingInfo[j];
112 nDofsPerNode = stridingInfo[stridedBlockId];
114 numGlobalElements = nodeMap->getGlobalNumElements()*Teuchos::as<global_size_t>(nDofsPerNode);
116 std::vector<GlobalOrdinal> dofgids;
117 for(LocalOrdinal i = 0; i<Teuchos::as<LocalOrdinal>(nodeMap->getNodeNumElements()); i++) {
118 GlobalOrdinal gid = nodeMap->getGlobalElement(i);
119 for(
size_t dof = 0; dof < nDofsPerNode; ++dof) {
122 dofgids.push_back(indexBase + StridedMapClass::offset_ + (gid-indexBase)*Teuchos::as<GlobalOrdinal>(StridedMapClass::getFixedBlockSize()) + Teuchos::as<GlobalOrdinal>(nStridedOffset + dof));
126 const Teuchos::ArrayView<const GlobalOrdinal> dofgidsview = Teuchos::ArrayView<const GlobalOrdinal>(dofgids);
130 if(stridedBlockId == -1) {
131 TEUCHOS_TEST_FOR_EXCEPTION(
getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsPerNode),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
132 TEUCHOS_TEST_FOR_EXCEPTION(
getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsPerNode),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
134 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
135 int nDofsInStridedBlock = stridingInfo[stridedBlockId];
136 TEUCHOS_TEST_FOR_EXCEPTION(
getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsInStridedBlock),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
137 TEUCHOS_TEST_FOR_EXCEPTION(
getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsInStridedBlock),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
165 :
Xpetra::
TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElements, numLocalElements, indexBase, comm, node),
Xpetra::
StridedMap<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElements, numLocalElements, indexBase, stridingInfo, comm, stridedBlockId, offset)
170 global_size_t numGlobalNodes = Teuchos::OrdinalTraits<global_size_t>::invalid();
171 if(numGlobalElements != Teuchos::OrdinalTraits<global_size_t>::invalid())
172 numGlobalNodes = numGlobalElements / StridedMapClass::getFixedBlockSize();
173 global_size_t numLocalNodes = numLocalElements / StridedMapClass::getFixedBlockSize();
176 RCP<Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > nodeMap = Teuchos::rcp(
new Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node >(numGlobalNodes, numLocalNodes, indexBase, comm, node));
179 size_t nStridedOffset = 0;
180 size_t nDofsPerNode = StridedMapClass::getFixedBlockSize();
181 if(stridedBlockId > -1) {
183 for(
int j=0; j<stridedBlockId; j++) {
184 nStridedOffset += stridingInfo[j];
186 nDofsPerNode = stridingInfo[stridedBlockId];
188 numGlobalElements = nodeMap->getGlobalNumElements()*Teuchos::as<global_size_t>(nDofsPerNode);
190 std::vector<GlobalOrdinal> dofgids;
191 for(LocalOrdinal i = 0; i<Teuchos::as<LocalOrdinal>(nodeMap->getNodeNumElements()); i++) {
192 GlobalOrdinal gid = nodeMap->getGlobalElement(i);
193 for(
size_t dof = 0; dof < nDofsPerNode; ++dof) {
196 dofgids.push_back(indexBase + StridedMapClass::offset_ + (gid-indexBase)*Teuchos::as<GlobalOrdinal>(StridedMapClass::getFixedBlockSize()) + Teuchos::as<GlobalOrdinal>(nStridedOffset + dof));
200 const Teuchos::ArrayView<const GlobalOrdinal> dofgidsview = Teuchos::ArrayView<const GlobalOrdinal>(dofgids);
204 if(stridedBlockId == -1) {
205 TEUCHOS_TEST_FOR_EXCEPTION(
getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsPerNode),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
206 TEUCHOS_TEST_FOR_EXCEPTION(
getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsPerNode),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
208 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
209 int nDofsInStridedBlock = stridingInfo[stridedBlockId];
210 TEUCHOS_TEST_FOR_EXCEPTION(
getNodeNumElements() != Teuchos::as<size_t>(nodeMap->getNodeNumElements()*nDofsInStridedBlock),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
211 TEUCHOS_TEST_FOR_EXCEPTION(
getGlobalNumElements() != Teuchos::as<size_t>(nodeMap->getGlobalNumElements()*nDofsInStridedBlock),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: wrong distribution of dofs among processors.");
228 StridedTpetraMap(
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=
Kokkos::DefaultNode::getDefaultNode())
229 :
Xpetra::
TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElements, elementList, indexBase, comm, node),
Xpetra::
StridedMap<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElements, elementList, indexBase, stridingInfo, comm, stridedBlockId)
231 if(stridedBlockId != -1) {
232 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo.size() < Teuchos::as<size_t>(stridedBlockId),
Exceptions::RuntimeError,
"StridedTpetraMap::StridedTpetraMap: stridedBlockId > stridingInfo.size()");
343 StridedTpetraMap(
const Teuchos::RCP<
const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node > > &map, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset = 0)
363 if(StridedMapClass::getStridedBlockId() == -1) {
373 size_t nStridedOffset = 0;
374 for(
int j=0; j<StridedMapClass::stridedBlockId_; j++) {
375 nStridedOffset += StridedMapClass::stridingInfo_[j];
379 const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
380 const GlobalOrdinal goZeroOffset = (dofGids[0] - nStridedOffset - StridedMapClass::offset_) / Teuchos::as<GlobalOrdinal>(StridedMapClass::getFixedBlockSize());
382 GlobalOrdinal cnt = 0;
383 for(
size_t i = 0; i<Teuchos::as<size_t>(dofGids.size())/StridedMapClass::stridingInfo_[StridedMapClass::stridedBlockId_]; i+=StridedMapClass::stridingInfo_[StridedMapClass::stridedBlockId_]) {
385 for(
size_t j=0; j<StridedMapClass::stridingInfo_[StridedMapClass::stridedBlockId_]; j++) {
386 const GlobalOrdinal gid = dofGids[i+j];
387 if((gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset - StridedMapClass::offset_) / Teuchos::as<GlobalOrdinal>(StridedMapClass::getFixedBlockSize()) - goZeroOffset - cnt != 0) {
404 #define XPETRA_STRIDEDTPETRAMAP_SHORT 405 #endif // XPETRA_STRIDEDTPETRAMAP_HPP GlobalOrdinal getMaxGlobalIndex() const
Returns maximum global index owned by this node.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this node.
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.
std::string description() const
Return a simple one-line description of this object.
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
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 getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
Returns true if map is identical to this Map.
GlobalOrdinal getMaxAllGlobalIndex() const
Return the maximum global index over all nodes.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
bool isDistributed() const
Returns true if this Map is distributed across more than one node; returns false otherwise.
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
bool isNodeLocalElement(LocalOrdinal localIndex) const
True if the local index is valid for this Map on this node, else false.
static Teuchos::RCP< DefaultNodeType > getDefaultNode()
Exception throws to report errors in the internal logical of the program.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity level to the given FancyOStream.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Return the process IDs and corresponding local IDs for the given global IDs.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index.
StridedTpetraMap(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=Kokkos::DefaultNode::getDefaultNode())
Map constructor with user-defined non-contiguous (arbitrary) distribution.
LocalOrdinal getMinLocalIndex() const
The minimum local index.
const Teuchos::RCP< Node > getNode() const
Get the Node object for this Map.
const Teuchos::RCP< Node > getNode() const
Get this Map's Node object.
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
global_size_t getGlobalNumElements() const
The number of elements in this Map.
StridedTpetraMap(const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &map, std::vector< size_t > &stridingInfo, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
TpetraMap constructor to wrap a Tpetra::Map object.
StridedTpetraMap(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=Kokkos::DefaultNode::getDefaultNode())
Map constructor with a user-defined contiguous distribution.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
~StridedTpetraMap()
Map destructor.
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map's Comm object.
LocalOrdinal getMaxLocalIndex() const
Returns maximum local index.
std::string description() const
Return a simple one-line description of this object.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
size_t global_size_t
Global size_t object.
GlobalOrdinal getIndexBase() const
The index base 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...
GlobalOrdinal getMinAllGlobalIndex() const
Return the minimum global index over all nodes.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
size_t getNodeNumElements() const
The number of elements belonging to the calling node.
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
Returns true if map is compatible with this Map.
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
True if the global index is found in this Map on this node, else false.
LocalOrdinal getMinLocalIndex() const
Returns minimum local index.
StridedTpetraMap(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=Kokkos::DefaultNode::getDefaultNode())
Map constructor with Tpetra-defined contiguous uniform distribution.
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
size_t getNodeNumElements() const
Returns the number of elements belonging to the calling node.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
GlobalOrdinal getMinGlobalIndex() const
Returns minimum global index owned by this node.
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > &graph)
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
Class that stores a strided map.
GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
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...
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.