Xpetra_TpetraMap.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 #ifndef XPETRA_TPETRAMAP_HPP
47 #define XPETRA_TPETRAMAP_HPP
48 
49 /* this file is automatically generated - do not edit (see script/tpetra.py) */
50 
52 
53 #include <Tpetra_Map.hpp>
54 
55 #include "Xpetra_Map.hpp"
56 #include "Xpetra_Utils.hpp"
57 
58 #include "Xpetra_Exceptions.hpp"
59 
60 namespace Xpetra {
61 
62  // TODO: move that elsewhere
63  template <class LocalOrdinal, class GlobalOrdinal, class Node>
64  const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node>& toTpetra(const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>&);
65 
66  template <class LocalOrdinal, class GlobalOrdinal, class Node>
67  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node > > toTpetra(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >&);
68 
69  template <class LocalOrdinal, class GlobalOrdinal, class Node>
70  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node > > toXpetra(const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >&);
71 
72  template <class LocalOrdinal, class GlobalOrdinal, class Node>
73  const RCP<Map<LocalOrdinal,GlobalOrdinal,Node > > toXpetraNonConst(const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >&);
74  //
75 
76  template <class LocalOrdinal = Map<>::local_ordinal_type,
77  class GlobalOrdinal = typename Map<LocalOrdinal>::global_ordinal_type,
78  class Node = typename Map<LocalOrdinal, GlobalOrdinal>::node_type>
79  class TpetraMap
80  : public virtual Map<LocalOrdinal,GlobalOrdinal,Node> {
81 
82  public:
83 
85  // Workaround function for a deferred visual studio bug
86  // http://connect.microsoft.com/VisualStudio/feedback/details/719847/erroneous-error-c2783-could-not-deduce-template-argument
87  // Use this function for default arguments rather than calling
88  // what is the return value below. Also helps in reducing
89  // duplication in various constructors.
90  return KokkosClassic::Details::getNode<Node>();
91  }
92 
94 
95 
97  TpetraMap (global_size_t numGlobalElements,
98  GlobalOrdinal indexBase,
99  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
101  const Teuchos::RCP< Node > &node = defaultArgNode())
102  : map_ (Teuchos::rcp (new Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > (numGlobalElements,
103  indexBase, comm,
104  toTpetra(lg), node)))
105  {}
106 
108  TpetraMap (global_size_t numGlobalElements,
109  size_t numLocalElements,
110  GlobalOrdinal indexBase,
111  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
112  const Teuchos::RCP< Node > &node = defaultArgNode())
113  : map_ (Teuchos::rcp (new Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > (numGlobalElements,
114  numLocalElements,
115  indexBase, comm,
116  node)))
117  {}
118 
120  TpetraMap (global_size_t numGlobalElements,
122  GlobalOrdinal indexBase,
123  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
124  const Teuchos::RCP< Node > &node = defaultArgNode())
125  : map_(Teuchos::rcp(new Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node >(numGlobalElements,
126  elementList, indexBase,
127  comm, node)))
128  {}
129 
132 
134 
136 
137 
139  global_size_t getGlobalNumElements() const { XPETRA_MONITOR("TpetraMap::getGlobalNumElements"); return map_->getGlobalNumElements(); }
140 
142  size_t getNodeNumElements() const { XPETRA_MONITOR("TpetraMap::getNodeNumElements"); return map_->getNodeNumElements(); }
143 
145  GlobalOrdinal getIndexBase() const { XPETRA_MONITOR("TpetraMap::getIndexBase"); return map_->getIndexBase(); }
146 
148  LocalOrdinal getMinLocalIndex() const { XPETRA_MONITOR("TpetraMap::getMinLocalIndex"); return map_->getMinLocalIndex(); }
149 
151  LocalOrdinal getMaxLocalIndex() const { XPETRA_MONITOR("TpetraMap::getMaxLocalIndex"); return map_->getMaxLocalIndex(); }
152 
154  GlobalOrdinal getMinGlobalIndex() const { XPETRA_MONITOR("TpetraMap::getMinGlobalIndex"); return map_->getMinGlobalIndex(); }
155 
157  GlobalOrdinal getMaxGlobalIndex() const { XPETRA_MONITOR("TpetraMap::getMaxGlobalIndex"); return map_->getMaxGlobalIndex(); }
158 
160  GlobalOrdinal getMinAllGlobalIndex() const { XPETRA_MONITOR("TpetraMap::getMinAllGlobalIndex"); return map_->getMinAllGlobalIndex(); }
161 
163  GlobalOrdinal getMaxAllGlobalIndex() const { XPETRA_MONITOR("TpetraMap::getMaxAllGlobalIndex"); return map_->getMaxAllGlobalIndex(); }
164 
166  LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("TpetraMap::getLocalElement"); return map_->getLocalElement(globalIndex); }
167 
169  GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const { XPETRA_MONITOR("TpetraMap::getGlobalElement"); return map_->getGlobalElement(localIndex); }
170 
172  LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const { XPETRA_MONITOR("TpetraMap::getRemoteIndexList"); return toXpetra(map_->getRemoteIndexList(GIDList, nodeIDList, LIDList)); }
173 
175  LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const { XPETRA_MONITOR("TpetraMap::getRemoteIndexList"); return toXpetra(map_->getRemoteIndexList(GIDList, nodeIDList)); }
176 
178  Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const { XPETRA_MONITOR("TpetraMap::getNodeElementList"); return map_->getNodeElementList(); }
179 
181 
183 
184 
186  bool isNodeLocalElement(LocalOrdinal localIndex) const { XPETRA_MONITOR("TpetraMap::isNodeLocalElement"); return map_->isNodeLocalElement(localIndex); }
187 
189  bool isNodeGlobalElement(GlobalOrdinal globalIndex) const { XPETRA_MONITOR("TpetraMap::isNodeGlobalElement"); return map_->isNodeGlobalElement(globalIndex); }
190 
192  bool isContiguous() const { XPETRA_MONITOR("TpetraMap::isContiguous"); return map_->isContiguous(); }
193 
195  bool isDistributed() const { XPETRA_MONITOR("TpetraMap::isDistributed"); return map_->isDistributed(); }
196 
198  bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("TpetraMap::isCompatible"); return map_->isCompatible(toTpetra(map)); }
199 
201  bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const { XPETRA_MONITOR("TpetraMap::isSameAs"); return map_->isSameAs(toTpetra(map)); }
202 
204 
206 
207 
209  Teuchos::RCP< const Teuchos::Comm< int > > getComm() const { XPETRA_MONITOR("TpetraMap::getComm"); return map_->getComm(); }
210 
212  Teuchos::RCP< Node > getNode() const { XPETRA_MONITOR("TpetraMap::getNode"); return map_->getNode(); }
213 
215 
217 
218 
220  std::string description() const { XPETRA_MONITOR("TpetraMap::description"); return map_->description(); }
221 
223  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const { XPETRA_MONITOR("TpetraMap::describe"); map_->describe(out, verbLevel); }
224 
226  return toXpetra(map_->removeEmptyProcesses());
227  }
229  return toXpetra(map_->replaceCommWithSubset(newComm));
230  }
231 
232  template<class Node2>
234  return toXpetraNonConst(map_->clone(node2));
235  }
236 
238 
240 
241 
243  TpetraMap(const Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node > > &map)
244  : map_(map) { }
245 
247  UnderlyingLib lib() const { return UseTpetra; }
248 
251 
253 
254  protected:
255 
257 
258  }; // TpetraMap class
259 
260  // TODO: move that elsewhere
261  template <class LocalOrdinal, class GlobalOrdinal, class Node>
262  const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> & toTpetra(const Map<LocalOrdinal,GlobalOrdinal,Node> &map) {
263  // TODO: throw exception
264  const TpetraMap<LocalOrdinal,GlobalOrdinal,Node> & tpetraMap = dynamic_cast<const TpetraMap<LocalOrdinal,GlobalOrdinal,Node> &>(*map.getMap());
265  return *tpetraMap.getTpetra_Map();
266  }
267 
268  template <class LocalOrdinal, class GlobalOrdinal, class Node>
270  typedef TpetraMap<LocalOrdinal, GlobalOrdinal, Node> TpetraMapClass;
271  if (map != Teuchos::null) {
272  XPETRA_RCP_DYNAMIC_CAST(const TpetraMapClass, map->getMap(), tpetraMap, "toTpetra");
273  return tpetraMap->getTpetra_Map();
274  }
275  return Teuchos::null;
276  }
277 
278  // In some cases (for instance, in MueLu adapter to Tpetra operator), we need to return a reference. This is only possible if
279  // we assume that the map argument is nonzero
280  template <class LocalOrdinal, class GlobalOrdinal, class Node>
282  TEUCHOS_TEST_FOR_EXCEPTION(map.is_null(), std::invalid_argument, "map must be nonzero");
283  typedef TpetraMap<LocalOrdinal, GlobalOrdinal, Node> TpetraMapClass;
284  XPETRA_RCP_DYNAMIC_CAST(const TpetraMapClass, map->getMap(), tpetraMap, "toTpetra");
285  return tpetraMap->getTpetra_Map();
286  }
287 
288  template <class LocalOrdinal, class GlobalOrdinal, class Node>
289  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > toXpetra(const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& map) {
290  if (!map.is_null())
292 
293  return Teuchos::null;
294  }
295 
296  template <class LocalOrdinal, class GlobalOrdinal, class Node>
297  const RCP<Map<LocalOrdinal,GlobalOrdinal,Node> > toXpetraNonConst(const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >& map) {
298  if (!map.is_null())
300 
301  return Teuchos::null;
302  }
303 
304  // TODO: removed (but currently used in unit test)
305  namespace useTpetra {
306 
308  template <class LocalOrdinal, class GlobalOrdinal, class Node>
310  createLocalMapWithNode(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node) {
311  XPETRA_MONITOR("useTpetra::createLocalMapWithNode");
312 
313  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, comm, node)));
314  }
315 
317  template <class LocalOrdinal, class GlobalOrdinal>
319  createContigMap(global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm) {
320  XPETRA_MONITOR("useTpetra::createContigMap");
321 
322  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal>(Tpetra::createContigMap<LocalOrdinal,GlobalOrdinal>(numElements, localNumElements, comm)));
323  }
324 
326  template <class LocalOrdinal, class GlobalOrdinal, class Node>
328  createContigMapWithNode(global_size_t numElements, size_t localNumElements,
329  const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node) {
330  XPETRA_MONITOR("useTpetra::createContigMap");
331  return rcp(new TpetraMap<LocalOrdinal,GlobalOrdinal,Node>(Tpetra::createContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements, localNumElements, comm, node)));
332  }
333  } // useTpetra namespace
334 
335 } // Xpetra namespace
336 
337 // TODO: remove?
339 template <class LocalOrdinal, class GlobalOrdinal, class Node>
341  XPETRA_MONITOR("TpetraMap==TpetraMap");
342  return map1.isSameAs(map2);
343 }
344 
346 template <class LocalOrdinal, class GlobalOrdinal, class Node>
348  XPETRA_MONITOR("TpetraMap!=TpetraMap");
349  return !map1.isSameAs(map2);
350 }
351 
352 #define XPETRA_TPETRAMAP_SHORT
353 #endif // XPETRA_TPETRAMAP_HPP
Teuchos::RCP< const TpetraMap< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
Non-member function to create a locally replicated Map with a specified node.
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map&#39;s communicator with a subset communicator.
bool operator!=(const Xpetra::TpetraMap< LocalOrdinal, GlobalOrdinal, Node > &map1, const Xpetra::TpetraMap< LocalOrdinal, GlobalOrdinal, Node > &map2)
Returns true if map is not identical to this map. Implemented in TpetraMap::isSameAs().
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this node.
const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & toTpetraNonZero(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
std::string description() const
Return a simple one-line description of this object.
RCP< Map< LocalOrdinal, GlobalOrdinal, Node2 > > clone(const RCP< Node2 > &node2) const
Teuchos::RCP< const TpetraMap< LocalOrdinal, GlobalOrdinal > > createContigMap(global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Non-member function to create a (potentially) non-uniform, contiguous Map with the default node...
GlobalOrdinal global_ordinal_type
Definition: Xpetra_Map.hpp:71
Teuchos::RCP< const TpetraMap< LocalOrdinal, GlobalOrdinal, Node > > createContigMapWithNode(global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
Non-member function to create a (potentially) non-uniform, contiguous Map with a user-specified node...
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
Node node_type
Definition: Xpetra_Map.hpp:72
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TpetraMap(global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=defaultArgNode())
Constructor with user-defined arbitrary (possibly noncontiguous) distribution.
Xpetra namespace
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
bool isNodeLocalElement(LocalOrdinal localIndex) const
True if the local index is valid for this Map on this node, else false.
virtual RCP< const Map > getMap() const
Definition: Xpetra_Map.hpp:196
TpetraMap(global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=GloballyDistributed, const Teuchos::RCP< Node > &node=defaultArgNode())
Constructor with Tpetra-defined contiguous uniform distribution.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity level to the given FancyOStream.
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.
RCP< const CrsGraph< int, GlobalOrdinal > > toXpetra(const Epetra_CrsGraph &g)
const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getTpetra_Map() const
Get the underlying Tpetra map.
LocalOrdinal getMinLocalIndex() const
The minimum local index.
~TpetraMap()
Destructor.
TpetraMap(global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=defaultArgNode())
Constructor with a user-defined contiguous distribution.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TpetraMap(const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
TpetraMap constructor to wrap a Tpetra::Map object.
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList) const
Return the process IDs for the given global IDs.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
const RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > toXpetraNonConst(const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &)
bool isContiguous() const
True if this Map is distributed contiguously, else false.
size_t global_size_t
Global size_t object.
static const EVerbosityLevel verbLevel_default
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
GlobalOrdinal getIndexBase() const
The index base for this Map.
bool operator==(const Xpetra::TpetraMap< LocalOrdinal, GlobalOrdinal, Node > &map1, const Xpetra::TpetraMap< LocalOrdinal, GlobalOrdinal, Node > &map2)
Returns true if map is identical to this map. Implemented in TpetraMap::isSameAs().
#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
size_t getNodeNumElements() const
The number of elements belonging to the calling node.
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
Teuchos::RCP< Node > getNode() const
Get this Map&#39;s Node object.
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > map_
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
True if the global index is found in this Map on this node, else false.
#define XPETRA_MONITOR(funcName)
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
static Teuchos::RCP< Node > defaultArgNode()
GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.