All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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.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 
135 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
136  TPETRA_DEPRECATED
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, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
143  GlobalOrdinal offset,
144  LocalGlobal lg,
145  const Teuchos::RCP<Node>& /* node */);
146 #endif // #ifdef TPETRA_ENABLE_DEPRECATED_CODE
147 
148 
150  global_size_t numGlobalElements,
151  GlobalOrdinal indexBase,
152  std::vector<size_t>& stridingInfo,
153  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
154  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
155  GlobalOrdinal offset = 0,
157 
158 
160 
180 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
181  TPETRA_DEPRECATED
183  global_size_t numGlobalElements,
184  size_t numLocalElements,
185  GlobalOrdinal indexBase,
186  std::vector<size_t>& stridingInfo,
187  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
188  LocalOrdinal stridedBlockId,
189  GlobalOrdinal offset,
190  const Teuchos::RCP<Node>& /* node */);
191 #endif // TPETRA_ENABLE_DEPRECATED_CODE
192 
193 
195  global_size_t numGlobalElements,
196  size_t numLocalElements,
197  GlobalOrdinal indexBase,
198  std::vector<size_t>& stridingInfo,
199  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
200  LocalOrdinal stridedBlockId = -1,
201  GlobalOrdinal offset = 0);
202 
203 
214 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
215  TPETRA_DEPRECATED
217  global_size_t numGlobalElements,
218  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
219  GlobalOrdinal indexBase,
220  std::vector<size_t>& stridingInfo,
221  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
222  LocalOrdinal stridedBlockId,
223  const Teuchos::RCP<Node>& /* node */);
224 #endif // TPETRA_ENABLE_DEPRECATED_CODE
225 
226 
228  global_size_t numGlobalElements,
229  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
230  GlobalOrdinal indexBase,
231  std::vector<size_t>& stridingInfo,
232  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
233  LocalOrdinal stridedBlockId = -1);
234 
235 
236  StridedMap(const RCP<const Map>& map,
237  std::vector<size_t>& stridingInfo,
238  GlobalOrdinal /* indexBase */,
239  LocalOrdinal stridedBlockId = -1,
240  GlobalOrdinal offset = 0);
241 
242 
244  virtual ~StridedMap();
245 
247 
249 
250 
251 
252  std::vector<size_t> getStridingData() const;
253 
254 
255  void setStridingData(std::vector<size_t> stridingInfo);
256 
257 
258  size_t getFixedBlockSize() const;
259 
260 
263  LocalOrdinal getStridedBlockId() const;
264 
265 
267  bool isStrided() const;
268 
269 
272  bool isBlocked() const;
273 
274 
275  GlobalOrdinal getOffset() const;
276 
277 
278  void setOffset(GlobalOrdinal offset);
279 
280 
281  // returns number of strided block id which gid belongs to.
282  size_t GID2StridingBlockId(GlobalOrdinal gid) const;
283 
284 
286 
287 
288 
290 
291 
292 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
293  #ifdef HAVE_XPETRA_TPETRA
295 
297  local_map_type getLocalMap() const
298  {
299  return map_->getLocalMap();
300  }
301  #else // HAVE_XPETRA_TPETRA
302  #ifdef __GNUC__
303  #warning \
304  "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
305  #endif // __GNUC__
306  #endif // HAVE_XPETRA_TPETRA ELSE
307 #endif // HAVE_XPETRA_KOKKOS_REFACTOR
308 
309 
311 
312  /* // function currently not needed but maybe useful
313  std::vector<GlobalOrdinal> NodeId2GlobalDofIds(GlobalOrdinal nodeId) const {
314  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds:
315  stridingInfo not valid: stridingInfo.size() = 0?"); std::vector<GlobalOrdinal> dofs; if(stridedBlockId_ > -1) {
316  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_[stridedBlockId_] == 0, Exceptions::RuntimeError,
317  "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo[stridedBlockId] = 0?");
318 
319  // determine nStridedOffset
320  size_t nStridedOffset = 0;
321  for(int j=0; j<stridedBlockId_; j++) {
322  nStridedOffset += stridingInfo_[j];
323  }
324 
325  for(size_t i = 0; i<stridingInfo_[stridedBlockId_]; i++) {
326  GlobalOrdinal gid =
327  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
328  offset_ +
329  Teuchos::as<GlobalOrdinal>(nStridedOffset) +
330  Teuchos::as<GlobalOrdinal>(i);
331  dofs.push_back(gid);
332  }
333  } else {
334  for(size_t i = 0; i<getFixedBlockSize(); i++) {
335  GlobalOrdinal gid =
336  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
337  offset_ +
338  Teuchos::as<GlobalOrdinal>(i);
339  dofs.push_back(gid);
340  }
341  }
342  return dofs;
343  }*/
345 
346 
347  private:
348 
349 
350  virtual bool CheckConsistency();
351 
352 
353  private:
354 
355 
357 
358  std::vector<size_t> stridingInfo_;
359  LocalOrdinal stridedBlockId_;
360  // stridedBlock == -1: the full map (with all strided block dofs)
361  // stridedBlock > -1: only dofs of strided block with index "stridedBlockId" are
362  // stored in this map
363  GlobalOrdinal offset_;
364  GlobalOrdinal indexBase_;
365 
366 
367  public:
368 
369 
371 
372 
375 
376 
378  size_t getNodeNumElements() const;
379 
380 
382  GlobalOrdinal getIndexBase() const;
383 
384 
386  LocalOrdinal getMinLocalIndex() const;
387 
388 
390  LocalOrdinal getMaxLocalIndex() const;
391 
392 
394  GlobalOrdinal getMinGlobalIndex() const;
395 
396 
398  GlobalOrdinal getMaxGlobalIndex() const;
399 
400 
402  GlobalOrdinal getMinAllGlobalIndex() const;
403 
404 
406  GlobalOrdinal getMaxAllGlobalIndex() const;
407 
408 
410  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const;
411 
412 
414  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const;
415 
416 
419  const Teuchos::ArrayView<int>& nodeIDList,
420  const Teuchos::ArrayView<LocalOrdinal>& LIDList) const;
421 
422 
425  const Teuchos::ArrayView<int>& nodeIDList) const;
426 
427 
430 
431 
433  bool isNodeLocalElement(LocalOrdinal localIndex) const;
434 
435 
437  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const;
438 
439 
441  bool isContiguous() const;
442 
443 
445  bool isDistributed() const;
446 
448 
450  bool isCompatible(const Map& map) const;
451 
452 
454  bool isSameAs(const Map& map) const;
455 
456 
459 
460 
461 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
462  Teuchos::RCP<Node> getNode() const;
464 #endif // TPETRA_ENABLE_DEPRECATED_CODE
465 
466 
468 
469 
471 
472 
474  std::string description() const;
475 
476 
480 
481 
483  UnderlyingLib lib() const;
484 
485 
486 }; // StridedMap class
487 
488 
489 
490 } // namespace Xpetra
491 
492 #define XPETRA_STRIDEDMAP_SHORT
493 #endif // XPETRA_STRIDEDMAP_DECL_HPP
494 
495 
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.
static const EVerbosityLevel verbLevel_default
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_