Xpetra Version of the Day
Loading...
Searching...
No Matches
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 <KokkosCompat_DefaultNode.hpp>
53#include <Teuchos_Describable.hpp>
54
55#include "Xpetra_ConfigDefs.hpp"
56#include "Xpetra_Map_decl.hpp"
57
58namespace Xpetra {
59
98template<class LocalOrdinal,
99 class GlobalOrdinal,
101class 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,
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_TPETRA
269
272 {
273 return map_->getLocalMap();
274 }
275 #else // HAVE_XPETRA_TPETRA
276 #ifdef __GNUC__
277 #warning \
278 "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
279 #endif // __GNUC__
280 #endif // HAVE_XPETRA_TPETRA ELSE
281
282
284
285 /* // function currently not needed but maybe useful
286 std::vector<GlobalOrdinal> NodeId2GlobalDofIds(GlobalOrdinal nodeId) const {
287 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() == 0, Exceptions::RuntimeError, "StridedMap::NodeId2GlobalDofIds:
288 stridingInfo not valid: stridingInfo.size() = 0?"); std::vector<GlobalOrdinal> dofs; if(stridedBlockId_ > -1) {
289 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_[stridedBlockId_] == 0, Exceptions::RuntimeError,
290 "StridedMap::NodeId2GlobalDofIds: stridingInfo not valid: stridingInfo[stridedBlockId] = 0?");
291
292 // determine nStridedOffset
293 size_t nStridedOffset = 0;
294 for(int j=0; j<stridedBlockId_; j++) {
295 nStridedOffset += stridingInfo_[j];
296 }
297
298 for(size_t i = 0; i<stridingInfo_[stridedBlockId_]; i++) {
299 GlobalOrdinal gid =
300 nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
301 offset_ +
302 Teuchos::as<GlobalOrdinal>(nStridedOffset) +
303 Teuchos::as<GlobalOrdinal>(i);
304 dofs.push_back(gid);
305 }
306 } else {
307 for(size_t i = 0; i<getFixedBlockSize(); i++) {
308 GlobalOrdinal gid =
309 nodeId * Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) +
310 offset_ +
311 Teuchos::as<GlobalOrdinal>(i);
312 dofs.push_back(gid);
313 }
314 }
315 return dofs;
316 }*/
318
319
320 private:
321
322
323 virtual bool CheckConsistency();
324
325
326 private:
327
329
331 std::vector<size_t> stridingInfo_;
332
338 LocalOrdinal stridedBlockId_;
339
341 GlobalOrdinal offset_;
342
344 GlobalOrdinal indexBase_;
345
346 public:
347
348
350
351
354
355
357 size_t getLocalNumElements() const;
358
359
361 GlobalOrdinal getIndexBase() const;
362
363
365 LocalOrdinal getMinLocalIndex() const;
366
367
369 LocalOrdinal getMaxLocalIndex() const;
370
371
373 GlobalOrdinal getMinGlobalIndex() const;
374
375
377 GlobalOrdinal getMaxGlobalIndex() const;
378
379
381 GlobalOrdinal getMinAllGlobalIndex() const;
382
383
385 GlobalOrdinal getMaxAllGlobalIndex() const;
386
387
389 LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const;
390
391
393 GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const;
394
395
398 const Teuchos::ArrayView<int>& nodeIDList,
399 const Teuchos::ArrayView<LocalOrdinal>& LIDList) const;
400
401
404 const Teuchos::ArrayView<int>& nodeIDList) const;
405
406
409
411 bool isNodeLocalElement(LocalOrdinal localIndex) const;
412
413
415 bool isNodeGlobalElement(GlobalOrdinal globalIndex) const;
416
417
419 bool isContiguous() const;
420
421
423 bool isDistributed() const;
424
426
428 bool isCompatible(const Map& map) const;
429
430
432 bool isSameAs(const Map& map) const;
433
434
437
438
439
440
442
443
445
446
448 std::string description() const;
449
450
454
455
457 UnderlyingLib lib() const;
458
459
460}; // StridedMap class
461
462} // namespace Xpetra
463
464#define XPETRA_STRIDEDMAP_SHORT
465#endif // XPETRA_STRIDEDMAP_DECL_HPP
static const EVerbosityLevel verbLevel_default
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
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.
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.
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.
size_t getLocalNumElements() const
Returns the number of elements belonging to the calling node.
GlobalOrdinal getOffset() const
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
typename Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
GlobalOrdinal getMaxAllGlobalIndex() const
Return the maximum global index over all nodes.
RCP< const Map > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map's communicator with a subset communicator.
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)
Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a list of the global indices owned by this 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.
local_map_type getLocalMap() const
Get the local Map for Kokkos kernels.
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.