Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_StridedMap_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Xpetra: A linear algebra interface package
4 //
5 // Copyright 2012 NTESS and the Xpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // WARNING: This code is experimental. Backwards compatibility should not be expected.
11 
12 #ifndef XPETRA_STRIDEDMAP_DECL_HPP
13 #define XPETRA_STRIDEDMAP_DECL_HPP
14 
15 #include <Tpetra_KokkosCompat_DefaultNode.hpp>
16 #include <Teuchos_Describable.hpp>
17 
18 #include "Xpetra_ConfigDefs.hpp"
19 #include "Xpetra_Map_decl.hpp"
20 
21 namespace Xpetra {
22 
61 template <class LocalOrdinal,
62  class GlobalOrdinal,
63  class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
64 class StridedMap : public virtual Map<LocalOrdinal, GlobalOrdinal, Node> {
65  public:
66  typedef LocalOrdinal local_ordinal_type;
67  typedef GlobalOrdinal global_ordinal_type;
68  typedef Node node_type;
70 
71  private:
72 #undef XPETRA_STRIDEDMAP_SHORT
74 
75  public:
77 
78 
100  global_size_t numGlobalElements,
101  GlobalOrdinal indexBase,
102  std::vector<size_t>& stridingInfo,
103  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
104  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
105  GlobalOrdinal offset = 0,
107 
109 
131  global_size_t numGlobalElements,
132  size_t numLocalElements,
133  GlobalOrdinal indexBase,
134  std::vector<size_t>& stridingInfo,
135  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
136  LocalOrdinal stridedBlockId = -1,
137  GlobalOrdinal offset = 0);
138 
151  global_size_t numGlobalElements,
152  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
153  GlobalOrdinal indexBase,
154  std::vector<size_t>& stridingInfo,
155  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
156  LocalOrdinal stridedBlockId = -1);
157 
158  StridedMap(const RCP<const Map>& map,
159  std::vector<size_t>& stridingInfo,
160  GlobalOrdinal /* indexBase */,
161  LocalOrdinal stridedBlockId = -1,
162  GlobalOrdinal offset = 0);
163 
165  virtual ~StridedMap();
166 
168 
170 
171 
172  std::vector<size_t> getStridingData() const;
173 
174  void setStridingData(std::vector<size_t> stridingInfo);
175 
176  size_t getFixedBlockSize() const;
177 
180  LocalOrdinal getStridedBlockId() const;
181 
183  bool isStrided() const;
184 
187  bool isBlocked() const;
188 
189  GlobalOrdinal getOffset() const;
190 
191  void setOffset(GlobalOrdinal offset);
192 
193  // returns number of strided block id which gid belongs to.
194  size_t GID2StridingBlockId(GlobalOrdinal gid) const;
195 
197 
198 
199  RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> getMap() const;
200 
201 #ifdef HAVE_XPETRA_TPETRA
203 
206  return map_->getLocalMap();
207  }
208 #else // HAVE_XPETRA_TPETRA
209 #ifdef __GNUC__
210 #warning \
211  "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
212 #endif // __GNUC__
213 #endif // HAVE_XPETRA_TPETRA ELSE
214 
216 
217  /* // function currently not needed but maybe useful
218  std::vector<GlobalOrdinal> NodeId2GlobalDofIds(GlobalOrdinal nodeId) const {
219  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds:
220  stridingInfo not valid: stridingInfo.size() = 0?"); std::vector<GlobalOrdinal> dofs; if(stridedBlockId_ > -1) {
221  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_[stridedBlockId_] == 0, Exceptions::RuntimeError,
222  "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo[stridedBlockId] = 0?");
223 
224  // determine nStridedOffset
225  size_t nStridedOffset = 0;
226  for(int j=0; j<stridedBlockId_; j++) {
227  nStridedOffset += stridingInfo_[j];
228  }
229 
230  for(size_t i = 0; i<stridingInfo_[stridedBlockId_]; i++) {
231  GlobalOrdinal gid =
232  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
233  offset_ +
234  Teuchos::as<GlobalOrdinal>(nStridedOffset) +
235  Teuchos::as<GlobalOrdinal>(i);
236  dofs.push_back(gid);
237  }
238  } else {
239  for(size_t i = 0; i<getFixedBlockSize(); i++) {
240  GlobalOrdinal gid =
241  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
242  offset_ +
243  Teuchos::as<GlobalOrdinal>(i);
244  dofs.push_back(gid);
245  }
246  }
247  return dofs;
248  }*/
250 
251  private:
252  virtual bool CheckConsistency();
253 
254  private:
255  RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> map_;
256 
258  std::vector<size_t> stridingInfo_;
259 
265  LocalOrdinal stridedBlockId_;
266 
268  GlobalOrdinal offset_;
269 
271  GlobalOrdinal indexBase_;
272 
273  public:
275 
276 
279 
281  size_t getLocalNumElements() const;
282 
284  GlobalOrdinal getIndexBase() const;
285 
287  LocalOrdinal getMinLocalIndex() const;
288 
290  LocalOrdinal getMaxLocalIndex() const;
291 
293  GlobalOrdinal getMinGlobalIndex() const;
294 
296  GlobalOrdinal getMaxGlobalIndex() const;
297 
299  GlobalOrdinal getMinAllGlobalIndex() const;
300 
302  GlobalOrdinal getMaxAllGlobalIndex() const;
303 
305  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const;
306 
308  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const;
309 
311  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
312  const Teuchos::ArrayView<int>& nodeIDList,
313  const Teuchos::ArrayView<LocalOrdinal>& LIDList) const;
314 
316  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
317  const Teuchos::ArrayView<int>& nodeIDList) const;
318 
320  Teuchos::ArrayView<const GlobalOrdinal> getLocalElementList() const;
321 
324 
326  bool isNodeLocalElement(LocalOrdinal localIndex) const;
327 
329  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const;
330 
332  bool isContiguous() const;
333 
335  bool isDistributed() const;
336 
338 
340  bool isCompatible(const Map& map) const;
341 
343  bool isSameAs(const Map& map) const;
344 
346  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const;
347 
348  RCP<const Map> removeEmptyProcesses() const;
349 
350  RCP<const Map> replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int>>& newComm) const;
351 
353  std::string description() const;
354 
356  void describe(Teuchos::FancyOStream& out,
357  const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
358 
360  UnderlyingLib lib() const;
361 
362 }; // StridedMap class
363 
364 } // namespace Xpetra
365 
366 #define XPETRA_STRIDEDMAP_SHORT
367 #endif // XPETRA_STRIDEDMAP_DECL_HPP
Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a list 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.
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
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
void setStridingData(std::vector< size_t > stridingInfo)
size_t getLocalNumElements() const
Returns the number of elements belonging to the calling node.
GlobalOrdinal indexBase_
Index base for the strided map (default = 0)
GlobalOrdinal getOffset() const
local_map_type getLocalMap() const
Get the local Map for Kokkos kernels.
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.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Returns true if the global index is found in this Map on this node; returns false if it isn&#39;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&#39;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
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process on the Map&#39;s device.
GlobalOrdinal offset_
Offset for gids in map (default = 0)
GlobalOrdinal getMinGlobalIndex() const
Returns minimum global index owned by this 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.
Kokkos::View< const global_ordinal_type *, typename Node::device_type > global_indices_array_device_type
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.
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.
Map< LocalOrdinal, GlobalOrdinal, Node >::global_indices_array_device_type global_indices_array_device_type
virtual ~StridedMap()
Destructor.
Class that stores a strided map.
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_