Xpetra  Version of the Day
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 
98 template<class LocalOrdinal,
99  class GlobalOrdinal,
101 class StridedMap : public virtual Map<LocalOrdinal, GlobalOrdinal, Node>
102 {
103 
104 
105  public:
106 
107 
108  typedef LocalOrdinal local_ordinal_type;
109  typedef GlobalOrdinal global_ordinal_type;
110  typedef Node node_type;
111 
112 
113  private:
114 
115 
116 #undef XPETRA_STRIDEDMAP_SHORT
118 
119 
120  public:
121 
122 
124 
125 
148  global_size_t numGlobalElements,
149  GlobalOrdinal indexBase,
150  std::vector<size_t>& stridingInfo,
151  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
152  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks for unsigned LocalOrdinal
153  GlobalOrdinal offset = 0,
155 
156 
158 
181  global_size_t numGlobalElements,
182  size_t numLocalElements,
183  GlobalOrdinal indexBase,
184  std::vector<size_t>& stridingInfo,
185  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
186  LocalOrdinal stridedBlockId = -1,
187  GlobalOrdinal offset = 0);
188 
189 
203  global_size_t numGlobalElements,
204  const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
205  GlobalOrdinal indexBase,
206  std::vector<size_t>& stridingInfo,
207  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
208  LocalOrdinal stridedBlockId = -1);
209 
210 
211  StridedMap(const RCP<const Map>& map,
212  std::vector<size_t>& stridingInfo,
213  GlobalOrdinal /* indexBase */,
214  LocalOrdinal stridedBlockId = -1,
215  GlobalOrdinal offset = 0);
216 
217 
219  virtual ~StridedMap();
220 
222 
224 
225 
226 
227  std::vector<size_t> getStridingData() const;
228 
229 
230  void setStridingData(std::vector<size_t> stridingInfo);
231 
232 
233  size_t getFixedBlockSize() const;
234 
235 
238  LocalOrdinal getStridedBlockId() const;
239 
240 
242  bool isStrided() const;
243 
244 
247  bool isBlocked() const;
248 
249 
250  GlobalOrdinal getOffset() const;
251 
252 
253  void setOffset(GlobalOrdinal offset);
254 
255 
256  // returns number of strided block id which gid belongs to.
257  size_t GID2StridingBlockId(GlobalOrdinal gid) const;
258 
259 
261 
262 
263 
265 
266 
267 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
268  #ifdef HAVE_XPETRA_TPETRA
270 
272  local_map_type getLocalMap() const
273  {
274  return map_->getLocalMap();
275  }
276  #else // HAVE_XPETRA_TPETRA
277  #ifdef __GNUC__
278  #warning \
279  "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
280  #endif // __GNUC__
281  #endif // HAVE_XPETRA_TPETRA ELSE
282 #endif // HAVE_XPETRA_KOKKOS_REFACTOR
283 
284 
286 
287  /* // function currently not needed but maybe useful
288  std::vector<GlobalOrdinal> NodeId2GlobalDofIds(GlobalOrdinal nodeId) const {
289  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds:
290  stridingInfo not valid: stridingInfo.size() = 0?"); std::vector<GlobalOrdinal> dofs; if(stridedBlockId_ > -1) {
291  TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_[stridedBlockId_] == 0, Exceptions::RuntimeError,
292  "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo[stridedBlockId] = 0?");
293 
294  // determine nStridedOffset
295  size_t nStridedOffset = 0;
296  for(int j=0; j<stridedBlockId_; j++) {
297  nStridedOffset += stridingInfo_[j];
298  }
299 
300  for(size_t i = 0; i<stridingInfo_[stridedBlockId_]; i++) {
301  GlobalOrdinal gid =
302  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
303  offset_ +
304  Teuchos::as<GlobalOrdinal>(nStridedOffset) +
305  Teuchos::as<GlobalOrdinal>(i);
306  dofs.push_back(gid);
307  }
308  } else {
309  for(size_t i = 0; i<getFixedBlockSize(); i++) {
310  GlobalOrdinal gid =
311  nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
312  offset_ +
313  Teuchos::as<GlobalOrdinal>(i);
314  dofs.push_back(gid);
315  }
316  }
317  return dofs;
318  }*/
320 
321 
322  private:
323 
324 
325  virtual bool CheckConsistency();
326 
327 
328  private:
329 
331 
333  std::vector<size_t> stridingInfo_;
334 
340  LocalOrdinal stridedBlockId_;
341 
343  GlobalOrdinal offset_;
344 
346  GlobalOrdinal indexBase_;
347 
348  public:
349 
350 
352 
353 
356 
357 
359  size_t getNodeNumElements() const;
360 
361 
363  GlobalOrdinal getIndexBase() const;
364 
365 
367  LocalOrdinal getMinLocalIndex() const;
368 
369 
371  LocalOrdinal getMaxLocalIndex() const;
372 
373 
375  GlobalOrdinal getMinGlobalIndex() const;
376 
377 
379  GlobalOrdinal getMaxGlobalIndex() const;
380 
381 
383  GlobalOrdinal getMinAllGlobalIndex() const;
384 
385 
387  GlobalOrdinal getMaxAllGlobalIndex() const;
388 
389 
391  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const;
392 
393 
395  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const;
396 
397 
400  const Teuchos::ArrayView<int>& nodeIDList,
401  const Teuchos::ArrayView<LocalOrdinal>& LIDList) const;
402 
403 
406  const Teuchos::ArrayView<int>& nodeIDList) const;
407 
408 
411 
412 
414  bool isNodeLocalElement(LocalOrdinal localIndex) const;
415 
416 
418  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const;
419 
420 
422  bool isContiguous() const;
423 
424 
426  bool isDistributed() const;
427 
429 
431  bool isCompatible(const Map& map) const;
432 
433 
435  bool isSameAs(const Map& map) const;
436 
437 
440 
441 
442 
443 
445 
446 
448 
449 
451  std::string description() const;
452 
453 
457 
458 
460  UnderlyingLib lib() const;
461 
462 
463 }; // StridedMap class
464 
465 } // namespace Xpetra
466 
467 #define XPETRA_STRIDEDMAP_SHORT
468 #endif // XPETRA_STRIDEDMAP_DECL_HPP
static const EVerbosityLevel verbLevel_default
Class that stores a strided map.
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
LocalOrdinal getMaxLocalIndex() const
Returns maximum local index.
std::vector< size_t > stridingInfo_
Vector with size of strided blocks (dofs)
GlobalOrdinal getMinAllGlobalIndex() const
Return the minimum global index over all nodes.
virtual ~StridedMap()
Destructor.
RCP< const Map > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int >> &newComm) const
bool isSameAs(const Map &map) const
Returns true if map is identical to 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.
size_t GID2StridingBlockId(GlobalOrdinal gid) const
GlobalOrdinal indexBase_
Index base for the strided map (default = 0)
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.
LocalOrdinal stridedBlockId_
Member variable denoting which dofs are stored in map.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index.
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
bool isDistributed() const
Returns true if this Map is distributed across more than one node; returns false otherwise.
LocalOrdinal getStridedBlockId() const
void setStridingData(std::vector< size_t > stridingInfo)
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.
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.
GlobalOrdinal getOffset() const
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
GlobalOrdinal getMaxAllGlobalIndex() const
Return the maximum global index over all nodes.
void setOffset(GlobalOrdinal offset)
GlobalOrdinal offset_
Offset for gids in map (default = 0)
GlobalOrdinal getMinGlobalIndex() const
Returns minimum global index owned by this node.
std::vector< size_t > getStridingData() const
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.
size_t getFixedBlockSize() const
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
bool isStrided() const
returns true, if this is a strided map (i.e. more than 1 strided blocks)
size_t getNodeNumElements() const
Returns the number of elements belonging to the calling node.
std::string description() const
Return a simple one-line description of this object.
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.
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_
LocalOrdinal getMinLocalIndex() const
Returns minimum local index.
GlobalOrdinal getMaxGlobalIndex() const
Returns maximum global index owned by this node.
RCP< const Map > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
Xpetra namespace
size_t global_size_t
Global size_t object.