Xpetra_StridedEpetraMap.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 // Jeremie Gaidamour (jngaida@sandia.gov)
40 // Jonathan Hu (jhu@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_STRIDEDEPETRAMAP_HPP
50 #define XPETRA_STRIDEDEPETRAMAP_HPP
51 
53 
54 #include "Xpetra_StridedMap.hpp"
55 #include "Xpetra_EpetraMap.hpp"
56 
57 //#include "Xpetra_Utils.hpp"
58 
59 #include "Xpetra_EpetraUtils.hpp"
60 #include "Xpetra_ConfigDefs.hpp"
61 
62 namespace Xpetra {
63 
64 
66  : public virtual EpetraMap, public virtual StridedMap<int, int>
67  {
68 
69  typedef int LocalOrdinal;
70  typedef int GlobalOrdinal;
72 
73  public:
74 
76 
77 
79  StridedEpetraMap(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, const Teuchos::RCP< Node > &node=Kokkos::DefaultNode::getDefaultNode());
80 
82  StridedEpetraMap(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, std::vector<size_t>& stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset = 0, const Teuchos::RCP< Node > &node=Kokkos::DefaultNode::getDefaultNode());
83 
85  StridedEpetraMap(global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, std::vector<size_t>& stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, const Teuchos::RCP< Node > &node=Kokkos::DefaultNode::getDefaultNode());
86 
89 
91 
93 
94 
97 
100 
102  GlobalOrdinal getIndexBase() const { return EpetraMap::getIndexBase(); }
103 
105  LocalOrdinal getMinLocalIndex() const { return EpetraMap::getMinLocalIndex(); }
106 
108  LocalOrdinal getMaxLocalIndex() const { return EpetraMap::getMaxLocalIndex(); }
109 
111  GlobalOrdinal getMinGlobalIndex() const { return EpetraMap::getMinGlobalIndex(); }
112 
114  GlobalOrdinal getMaxGlobalIndex() const { return EpetraMap::getMaxGlobalIndex(); }
115 
117  GlobalOrdinal getMinAllGlobalIndex() const { return EpetraMap::getMinAllGlobalIndex(); }
118 
120  GlobalOrdinal getMaxAllGlobalIndex() const { return EpetraMap::getMaxAllGlobalIndex(); }
121 
123  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { return EpetraMap::getLocalElement(globalIndex); }
124 
126  LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const { return EpetraMap::getRemoteIndexList(GIDList, nodeIDList, LIDList); }
127 
129  LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const { return EpetraMap::getRemoteIndexList(GIDList, nodeIDList); }
130 
132  Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const { return EpetraMap::getNodeElementList(); }
133 
135  bool isNodeLocalElement(LocalOrdinal localIndex) const { return EpetraMap::isNodeLocalElement(localIndex); }
136 
138  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { return EpetraMap::isNodeGlobalElement(globalIndex); }
139 
141  bool isContiguous() const { return EpetraMap::isContiguous(); }
142 
144  bool isDistributed() const { return EpetraMap::isDistributed(); }
145 
147 
149 
150 
152  const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { return EpetraMap::getComm(); }
153 
155  const Teuchos::RCP< Node > getNode() const { return EpetraMap::getNode(); }
156 
158 
159 
161 
162 
165 
168 
170 
172 
173 
175  std::string description() const;
176 
178  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
179 
181 
183  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const { return EpetraMap::getGlobalElement(localIndex); }
184 
186 
187 
189  StridedEpetraMap(const Teuchos::RCP<const Epetra_BlockMap> &map, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset = 0)
190  : EpetraMap(map), StridedMap<int, int>(stridingInfo, map->IndexBase(), stridedBlockId, offset) {
191  int nDofsPerNode = Teuchos::as<int>(getFixedBlockSize());
192  TEUCHOS_TEST_FOR_EXCEPTION(map_->NumMyPoints() % nDofsPerNode != 0, Exceptions::RuntimeError, "StridedEpetraMap::StridedEpetraMap: wrong distribution of dofs among processors.");
193  TEUCHOS_TEST_FOR_EXCEPTION(CheckConsistency() == false, Exceptions::RuntimeError, "StridedEpetraMap::StridedEpetraMap: CheckConsistency() == false");
194  }
195 
197  UnderlyingLib lib() const { return Xpetra::UseEpetra; }
198 
199  /*//! Get the underlying Epetra map
200  //const RCP< const Epetra_Map > & getEpetra_Map() const { return map_; }
201  const Epetra_BlockMap& getEpetra_BlockMap() const { return *map_; }
202  const Epetra_Map& getEpetra_Map() const { return (Epetra_Map &)*map_; } // Ugly, but the same is done in Epetra_CrsMatrix.h to get the map.*/
203 
205 
206  private:
207 
209  if(getStridedBlockId() == -1) {
210  //if(isContiguous() == false) return false;
211  if(getNodeNumElements() % getFixedBlockSize() != 0) return false;
212  if(getGlobalNumElements() % getFixedBlockSize() != 0) return false;
213  }
214  else {
215  Teuchos::ArrayView< const GlobalOrdinal > dofGids = getNodeElementList();
216  //std::sort(dofGids.begin(),dofGids.end());
217 
218  // determine nStridedOffset
219  size_t nStridedOffset = 0;
220  for(int j=0; j<stridedBlockId_; j++) {
221  nStridedOffset += stridingInfo_[j];
222  }
223  //size_t nDofsPerNode = stridingInfo_[stridedBlockId_];
224 
225  const GlobalOrdinal goStridedOffset = Teuchos::as<GlobalOrdinal>(nStridedOffset);
226  const GlobalOrdinal goZeroOffset = (dofGids[0] - nStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize());
227  /*printf("goZeroOffset: %i\n",goZeroOffset);
228  printf("dofGids[0]: %i \n",dofGids[0]);
229  printf("stridedOffset: %i\n",nStridedOffset);
230  printf("offset_: %i\n",offset_);
231  printf("goStridedOffset: %i\n",goStridedOffset);
232  printf("getFixedBlkSize: %i\n",getFixedBlockSize());*/
233 
234  GlobalOrdinal cnt = 0;
235  for(size_t i = 0; i<Teuchos::as<size_t>(dofGids.size())/stridingInfo_[stridedBlockId_]; i+=stridingInfo_[stridedBlockId_]) {
236 
237  for(size_t j=0; j<stridingInfo_[stridedBlockId_]; j++) {
238  const GlobalOrdinal gid = dofGids[i+j];
239  if((gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset - offset_ - indexBase_) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset - cnt != 0) {
240  //std::cout << "gid: " << gid << " GID: " << (gid - Teuchos::as<GlobalOrdinal>(j) - goStridedOffset) / Teuchos::as<GlobalOrdinal>(getFixedBlockSize()) - goZeroOffset - cnt << std::endl;
241  return false;
242  }
243  }
244  cnt++;
245  }
246 
247  }
248 
249  return true;
250  }
251 
252 
253  }; // StridedEpetraMap class
254 
255 } // Xpetra namespace
256 
257 #endif // XPETRA_STRIDEDEPETRAMAP_HPP
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
Return the local index for a given global index.
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...
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
GlobalOrdinal getIndexBase() const
Returns the index base for 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&#39;t...
bool isDistributed() const
Returns true if this Map is distributed across more than one node; returns false otherwise.
LocalOrdinal getMinLocalIndex() const
Returns minimum local index.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Return the process IDs and corresponding local IDs for the given global IDs.
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index. Note that this returns -1 if not found on this proce...
const Teuchos::RCP< Node > getNode() const
Get this Map&#39;s Node object.
GlobalOrdinal getMaxGlobalIndex() const
Returns maximum global index owned by this node.
StridedEpetraMap(const Teuchos::RCP< const Epetra_BlockMap > &map, std::vector< size_t > &stridingInfo, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
EpetraMap constructor to wrap a Epetra_Map object.
bool isContiguous() const
Returns true if this Map is distributed contiguously; returns false otherwise.
int indexBase_
index base for the strided map (default = 0)
Xpetra namespace
static Teuchos::RCP< DefaultNodeType > getDefaultNode()
Exception throws to report errors in the internal logical of the program.
Kokkos::DefaultNode::DefaultNodeType Node
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this node.
RCP< const Epetra_BlockMap > map_
int stridedBlockId_
member variable denoting which dofs are stored in map
GlobalOrdinal getMaxAllGlobalIndex() const
Return the maximum global index over all nodes.
size_t getNodeNumElements() const
Returns the number of elements belonging to the calling node.
size_t getNodeNumElements() const
The number of elements belonging to the calling node.
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
Returns true if map is identical to this Map.
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
std::vector< size_t > stridingInfo_
vector with size of strided blocks (dofs)
bool isNodeLocalElement(LocalOrdinal localIndex) const
True if the local index is valid for this Map on this node, else false.
UnderlyingLib lib() const
Get the library used by this object (Epetra or Epetra?)
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
std::string description() const
Return a simple one-line description of this object.
GlobalOrdinal getMinGlobalIndex() const
Returns minimum global index owned by this node.
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.
int offset_
offset for gids in map (default = 0)
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
Returns true if map is compatible with this Map.
size_t global_size_t
Global size_t object.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
True if the global index is found in this Map on this node, else false.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
Return the global index for a given local index. Note that this returns -1 if not found on this proce...
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
const Teuchos::RCP< Node > getNode() const
Get the Node object for this Map.
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const
Returns the node IDs for a given list of global indices.
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.
StridedEpetraMap(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, const Teuchos::RCP< Node > &node=Kokkos::DefaultNode::getDefaultNode())
Map constructor with Tpetra-defined contiguous uniform distribution. The elements are distributed amo...
LocalOrdinal getMinLocalIndex() const
The minimum local index.
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
GlobalOrdinal getMinAllGlobalIndex() const
Return the minimum global index over all nodes.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
GlobalOrdinal getIndexBase() const
The index base for this Map.
Class that stores a strided map.
LocalOrdinal getMaxLocalIndex() const
Returns maximum local index.