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 <Kokkos_DefaultNode.hpp>
53 #include <Teuchos_Describable.hpp>
54 
55 #include "Xpetra_ConfigDefs.hpp"
56 #include "Xpetra_Map_decl.hpp"
57 
58 namespace Xpetra {
59 
88 template<class LocalOrdinal,
89  class GlobalOrdinal,
91 class StridedMap : public virtual Map<LocalOrdinal, GlobalOrdinal, Node>
92 {
93 
94 
95  public:
96 
97 
98  typedef LocalOrdinal local_ordinal_type;
99  typedef GlobalOrdinal global_ordinal_type;
100  typedef Node node_type;
101 
102 
103  private:
104 
105 
106 #undef XPETRA_STRIDEDMAP_SHORT
108 
109 
110  public:
111 
112 
114 
115 
138  global_size_t numGlobalElements,
139  GlobalOrdinal indexBase,
140  std::vector<size_t>& stridingInfo,
141  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
142  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
143  GlobalOrdinal offset = 0,
145 
146 
148 
171  global_size_t numGlobalElements,
172  size_t numLocalElements,
173  GlobalOrdinal indexBase,
174  std::vector<size_t>& stridingInfo,
175  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
176  LocalOrdinal stridedBlockId = -1,
177  GlobalOrdinal offset = 0);
178 
179 
193  global_size_t numGlobalElements,
194  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
195  GlobalOrdinal indexBase,
196  std::vector<size_t>& stridingInfo,
197  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
198  LocalOrdinal stridedBlockId = -1);
199 
200 
201  StridedMap(const RCP<const Map>& map,
202  std::vector<size_t>& stridingInfo,
203  GlobalOrdinal /* indexBase */,
204  LocalOrdinal stridedBlockId = -1,
205  GlobalOrdinal offset = 0);
206 
207 
209  virtual ~StridedMap();
210 
212 
214 
215 
216 
217  std::vector<size_t> getStridingData() const;
218 
219 
220  void setStridingData(std::vector<size_t> stridingInfo);
221 
222 
223  size_t getFixedBlockSize() const;
224 
225 
228  LocalOrdinal getStridedBlockId() const;
229 
230 
232  bool isStrided() const;
233 
234 
237  bool isBlocked() const;
238 
239 
240  GlobalOrdinal getOffset() const;
241 
242 
243  void setOffset(GlobalOrdinal offset);
244 
245 
246  // returns number of strided block id which gid belongs to.
247  size_t GID2StridingBlockId(GlobalOrdinal gid) const;
248 
249 
251 
252 
253 
254  RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> getMap() const;
255 
256 
257 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
258  #ifdef HAVE_XPETRA_TPETRA
260 
262  local_map_type getLocalMap() const
263  {
264  return map_->getLocalMap();
265  }
266  #else // HAVE_XPETRA_TPETRA
267  #ifdef __GNUC__
268  #warning \
269  "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
270  #endif // __GNUC__
271  #endif // HAVE_XPETRA_TPETRA ELSE
272 #endif // HAVE_XPETRA_KOKKOS_REFACTOR
273 
274 
276 
277  /* // function currently not needed but maybe useful
278  std::vector<GlobalOrdinal> NodeId2GlobalDofIds(GlobalOrdinal nodeId) const {
279  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds:
280  stridingInfo not valid: stridingInfo.size() = 0?"); std::vector<GlobalOrdinal> dofs; if(stridedBlockId_ > -1) {
281  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_[stridedBlockId_] == 0, Exceptions::RuntimeError,
282  "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo[stridedBlockId] = 0?");
283 
284  // determine nStridedOffset
285  size_t nStridedOffset = 0;
286  for(int j=0; j<stridedBlockId_; j++) {
287  nStridedOffset += stridingInfo_[j];
288  }
289 
290  for(size_t i = 0; i<stridingInfo_[stridedBlockId_]; i++) {
291  GlobalOrdinal gid =
292  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
293  offset_ +
294  Teuchos::as<GlobalOrdinal>(nStridedOffset) +
295  Teuchos::as<GlobalOrdinal>(i);
296  dofs.push_back(gid);
297  }
298  } else {
299  for(size_t i = 0; i<getFixedBlockSize(); i++) {
300  GlobalOrdinal gid =
301  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
302  offset_ +
303  Teuchos::as<GlobalOrdinal>(i);
304  dofs.push_back(gid);
305  }
306  }
307  return dofs;
308  }*/
310 
311 
312  private:
313 
314 
315  virtual bool CheckConsistency();
316 
317 
318  private:
319 
320 
321  RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> map_;
322 
323  std::vector<size_t> stridingInfo_;
324  LocalOrdinal stridedBlockId_;
325  // stridedBlock == -1: the full map (with all strided block dofs)
326  // stridedBlock > -1: only dofs of strided block with index "stridedBlockId" are
327  // stored in this map
328  GlobalOrdinal offset_;
329  GlobalOrdinal indexBase_;
330 
331 
332  public:
333 
334 
336 
337 
340 
341 
343  size_t getNodeNumElements() const;
344 
345 
347  GlobalOrdinal getIndexBase() const;
348 
349 
351  LocalOrdinal getMinLocalIndex() const;
352 
353 
355  LocalOrdinal getMaxLocalIndex() const;
356 
357 
359  GlobalOrdinal getMinGlobalIndex() const;
360 
361 
363  GlobalOrdinal getMaxGlobalIndex() const;
364 
365 
367  GlobalOrdinal getMinAllGlobalIndex() const;
368 
369 
371  GlobalOrdinal getMaxAllGlobalIndex() const;
372 
373 
375  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const;
376 
377 
379  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const;
380 
381 
383  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
384  const Teuchos::ArrayView<int>& nodeIDList,
385  const Teuchos::ArrayView<LocalOrdinal>& LIDList) const;
386 
387 
389  LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
390  const Teuchos::ArrayView<int>& nodeIDList) const;
391 
392 
394  Teuchos::ArrayView<const GlobalOrdinal> getNodeElementList() const;
395 
396 
398  bool isNodeLocalElement(LocalOrdinal localIndex) const;
399 
400 
402  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const;
403 
404 
406  bool isContiguous() const;
407 
408 
410  bool isDistributed() const;
411 
413 
415  bool isCompatible(const Map& map) const;
416 
417 
419  bool isSameAs(const Map& map) const;
420 
421 
423  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const;
424 
425 
426 
427 
428  RCP<const Map> removeEmptyProcesses() const;
429 
430 
431  RCP<const Map> replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int>>& newComm) const;
432 
433 
435  std::string description() const;
436 
437 
439  void describe(Teuchos::FancyOStream& out,
440  const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
441 
442 
444  UnderlyingLib lib() const;
445 
446 
447 }; // StridedMap class
448 
449 
450 
451 } // namespace Xpetra
452 
453 #define XPETRA_STRIDEDMAP_SHORT
454 #endif // XPETRA_STRIDEDMAP_DECL_HPP
455 
456 
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
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
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.
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.
virtual ~StridedMap()
Destructor.
void setOffset(GlobalOrdinal offset)
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_