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 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 
47 // WARNING: This code is experimental. Backwards compatibility should not be expected.
48 
49 #ifndef XPETRA_STRIDEDMAP_DECL_HPP
50 #define XPETRA_STRIDEDMAP_DECL_HPP
51 
52 #include <Tpetra_KokkosCompat_DefaultNode.hpp>
53 #include <Teuchos_Describable.hpp>
54 
55 #include "Xpetra_ConfigDefs.hpp"
56 #include "Xpetra_Map_decl.hpp"
57 
58 namespace Xpetra {
59 
98 template <class LocalOrdinal,
99  class GlobalOrdinal,
100  class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
101 class StridedMap : public virtual Map<LocalOrdinal, GlobalOrdinal, Node> {
102  public:
103  typedef LocalOrdinal local_ordinal_type;
104  typedef GlobalOrdinal global_ordinal_type;
105  typedef Node node_type;
107 
108  private:
109 #undef XPETRA_STRIDEDMAP_SHORT
111 
112  public:
114 
115 
137  global_size_t numGlobalElements,
138  GlobalOrdinal indexBase,
139  std::vector<size_t>& stridingInfo,
140  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
141  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
142  GlobalOrdinal offset = 0,
144 
146 
168  global_size_t numGlobalElements,
169  size_t numLocalElements,
170  GlobalOrdinal indexBase,
171  std::vector<size_t>& stridingInfo,
172  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
173  LocalOrdinal stridedBlockId = -1,
174  GlobalOrdinal offset = 0);
175 
188  global_size_t numGlobalElements,
189  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
190  GlobalOrdinal indexBase,
191  std::vector<size_t>& stridingInfo,
192  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
193  LocalOrdinal stridedBlockId = -1);
194 
195  StridedMap(const RCP<const Map>& map,
196  std::vector<size_t>& stridingInfo,
197  GlobalOrdinal /* indexBase */,
198  LocalOrdinal stridedBlockId = -1,
199  GlobalOrdinal offset = 0);
200 
202  virtual ~StridedMap();
203 
205 
207 
208 
209  std::vector<size_t> getStridingData() const;
210 
211  void setStridingData(std::vector<size_t> stridingInfo);
212 
213  size_t getFixedBlockSize() const;
214 
217  LocalOrdinal getStridedBlockId() const;
218 
220  bool isStrided() const;
221 
224  bool isBlocked() const;
225 
226  GlobalOrdinal getOffset() const;
227 
228  void setOffset(GlobalOrdinal offset);
229 
230  // returns number of strided block id which gid belongs to.
231  size_t GID2StridingBlockId(GlobalOrdinal gid) const;
232 
234 
235 
236  RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> getMap() const;
237 
238 #ifdef HAVE_XPETRA_TPETRA
240 
243  return map_->getLocalMap();
244  }
245 #else // HAVE_XPETRA_TPETRA
246 #ifdef __GNUC__
247 #warning \
248  "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
249 #endif // __GNUC__
250 #endif // HAVE_XPETRA_TPETRA ELSE
251 
253 
254  /* // function currently not needed but maybe useful
255  std::vector<GlobalOrdinal> NodeId2GlobalDofIds(GlobalOrdinal nodeId) const {
256  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds:
257  stridingInfo not valid: stridingInfo.size() = 0?"); std::vector<GlobalOrdinal> dofs; if(stridedBlockId_ > -1) {
258  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_[stridedBlockId_] == 0, Exceptions::RuntimeError,
259  "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo[stridedBlockId] = 0?");
260 
261  // determine nStridedOffset
262  size_t nStridedOffset = 0;
263  for(int j=0; j<stridedBlockId_; j++) {
264  nStridedOffset += stridingInfo_[j];
265  }
266 
267  for(size_t i = 0; i<stridingInfo_[stridedBlockId_]; i++) {
268  GlobalOrdinal gid =
269  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
270  offset_ +
271  Teuchos::as<GlobalOrdinal>(nStridedOffset) +
272  Teuchos::as<GlobalOrdinal>(i);
273  dofs.push_back(gid);
274  }
275  } else {
276  for(size_t i = 0; i<getFixedBlockSize(); i++) {
277  GlobalOrdinal gid =
278  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
279  offset_ +
280  Teuchos::as<GlobalOrdinal>(i);
281  dofs.push_back(gid);
282  }
283  }
284  return dofs;
285  }*/
287 
288  private:
289  virtual bool CheckConsistency();
290 
291  private:
292  RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> map_;
293 
295  std::vector<size_t> stridingInfo_;
296 
302  LocalOrdinal stridedBlockId_;
303 
305  GlobalOrdinal offset_;
306 
308  GlobalOrdinal indexBase_;
309 
310  public:
312 
313 
316 
318  size_t getLocalNumElements() const;
319 
321  GlobalOrdinal getIndexBase() const;
322 
324  LocalOrdinal getMinLocalIndex() const;
325 
327  LocalOrdinal getMaxLocalIndex() const;
328 
330  GlobalOrdinal getMinGlobalIndex() const;
331 
333  GlobalOrdinal getMaxGlobalIndex() const;
334 
336  GlobalOrdinal getMinAllGlobalIndex() const;
337 
339  GlobalOrdinal getMaxAllGlobalIndex() const;
340 
342  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const;
343 
345  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const;
346 
348  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
349  const Teuchos::ArrayView<int>& nodeIDList,
350  const Teuchos::ArrayView<LocalOrdinal>& LIDList) const;
351 
353  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
354  const Teuchos::ArrayView<int>& nodeIDList) const;
355 
357  Teuchos::ArrayView<const GlobalOrdinal> getLocalElementList() const;
358 
361 
363  bool isNodeLocalElement(LocalOrdinal localIndex) const;
364 
366  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const;
367 
369  bool isContiguous() const;
370 
372  bool isDistributed() const;
373 
375 
377  bool isCompatible(const Map& map) const;
378 
380  bool isSameAs(const Map& map) const;
381 
383  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const;
384 
385  RCP<const Map> removeEmptyProcesses() const;
386 
387  RCP<const Map> replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int>>& newComm) const;
388 
390  std::string description() const;
391 
393  void describe(Teuchos::FancyOStream& out,
394  const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
395 
397  UnderlyingLib lib() const;
398 
399 }; // StridedMap class
400 
401 } // namespace Xpetra
402 
403 #define XPETRA_STRIDEDMAP_SHORT
404 #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.
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_