Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_BlockedMap_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 // Tobias Wiesner (tawiesn@sandia.gov)
42 // Ray Tuminaro (rstumin@sandia.gov)
43 //
44 // ***********************************************************************
45 //
46 // @HEADER
47 #ifndef PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DECL_HPP_
48 #define PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DECL_HPP_
49 
50 #include "Xpetra_ConfigDefs.hpp"
51 
52 #include "Xpetra_Import.hpp"
53 #include "Xpetra_Map_decl.hpp"
54 
55 namespace Xpetra {
56 
57 template <class LocalOrdinal,
58  class GlobalOrdinal,
59  class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
60 class BlockedMap : public Map<LocalOrdinal, GlobalOrdinal, Node> {
61  public:
62  typedef LocalOrdinal local_ordinal_type;
63  typedef GlobalOrdinal global_ordinal_type;
64  typedef Node node_type;
66 
67  private:
68 #undef XPETRA_BLOCKEDMAP_SHORT
70 
71  public:
73 
74 
76 
78  BlockedMap();
79 
97  BlockedMap(const RCP<const Map>& fullmap, const std::vector<RCP<const Map>>& maps, bool bThyraMode = false);
98 
100  BlockedMap(const std::vector<RCP<const Map>>& maps, const std::vector<RCP<const Map>>& thyramaps);
101 
103  BlockedMap(const BlockedMap& input);
104 
106  virtual ~BlockedMap();
107 
109 
110 
112  virtual global_size_t getGlobalNumElements() const;
113 
115  virtual size_t getLocalNumElements() const;
116 
118  virtual GlobalOrdinal getIndexBase() const;
119 
121  virtual LocalOrdinal getMinLocalIndex() const;
122 
124  virtual LocalOrdinal getMaxLocalIndex() const;
125 
127  virtual GlobalOrdinal getMinGlobalIndex() const;
128 
130  virtual GlobalOrdinal getMaxGlobalIndex() const;
131 
133  virtual GlobalOrdinal getMinAllGlobalIndex() const;
134 
136  virtual GlobalOrdinal getMaxAllGlobalIndex() const;
137 
139  virtual LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const;
140 
142  virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const;
143 
145  virtual LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& /* GIDList */,
146  const Teuchos::ArrayView<int>& /* nodeIDList */,
147  const Teuchos::ArrayView<LocalOrdinal>& /* LIDList */) const;
148 
150  virtual LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& /* GIDList */,
151  const Teuchos::ArrayView<int>& /* nodeIDList */) const;
152 
154  virtual Teuchos::ArrayView<const GlobalOrdinal> getLocalElementList() const;
155 
158 
160 
162 
163 
165  virtual bool isNodeLocalElement(LocalOrdinal localIndex) const;
166 
168  virtual bool isNodeGlobalElement(GlobalOrdinal globalIndex) const;
169 
171  virtual bool isContiguous() const;
172 
174  virtual bool isDistributed() const;
175 
177  virtual bool isCompatible(const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>& map) const;
178 
180  virtual bool isSameAs(const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>& map) const;
181 
183 
185 
186 
188  virtual Teuchos::RCP<const Teuchos::Comm<int>> getComm() const;
189 
191 
200 
202 
204 
205  /*virtual size_t getLocalLength() const {
207  throw Xpetra::Exceptions::RuntimeError("BlockedMap::getLocalLength: routine not implemented.");
208  return 0;
209  }*/
210 
212  /*virtual global_size_t getGlobalLength() const {
213  throw Xpetra::Exceptions::RuntimeError("BlockedMap::getGlobalLength: routine not implemented.");
214  return 0;
215  }*/
216 
218  virtual bool getThyraMode() const;
219 
221 
223 
224 
226  virtual RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> removeEmptyProcesses() const;
227 
229  virtual RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
230  replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int>>& /* newComm */) const;
231 
233 
235 
236 
238  virtual UnderlyingLib lib() const;
239 
240  // TODO: find a better solution for this hack
241  // The problem is that EpetraMap, TpetraMap and StridedMap all inherit Map. To have proper toEpetra() we
242  // need to understand the type of underlying matrix. But in src/Map we have no knowledge of StridedMaps, so
243  // we cannot check for it by casting. This function allows us to avoid the restriction, as StridedMap redefines
244  // it to return the base map.
245  virtual RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
246  getMap() const;
247 
249 
251  size_t getNumMaps() const;
252 
257  const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
258  getMap(size_t i, bool bThyraMode = false) const;
259 
261  const RCP<Xpetra::Import<LocalOrdinal, GlobalOrdinal, Node>>
262  getImporter(size_t i) const;
263 
265  const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
266  getFullMap() const;
267 
269  size_t getMapIndexForGID(GlobalOrdinal gid) const;
270 
271 #ifdef HAVE_XPETRA_TPETRA
273 
275  local_map_type getLocalMap() const { return fullmap_->getLocalMap(); }
276 
277 #else // HAVE_XPETRA_TPETRA
278 #ifdef __GNUC__
279 #warning "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 // #else !HAVE_XPETRA_TPETRA
282 
284 
286 
287 
289  virtual std::string description() const;
290 
292  virtual void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
293 
295 
296  protected:
299  virtual void assign(const BlockedMap& input);
300 
315  static Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
316  concatenateMaps(const std::vector<Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>>& subMaps);
317 
318  private:
319  bool CheckConsistency() const;
320 
321  private:
322  RCP<const Map> fullmap_;
323  std::vector<RCP<const Map>> maps_;
324  std::vector<RCP<Import>> importers_;
325  bool bThyraMode_; //< boolean flag: use Thyra numbering for local sub-block maps. default = false (for Xpetra mode)
326  std::vector<RCP<const Map>> thyraMaps_; //< store Thyra-style numbering maps here in Thyra mode. In Xpetra mode this vector is empty.
327 }; // BlockedMap class
328 
329 } // namespace Xpetra
330 
331 #define XPETRA_BLOCKEDMAP_SHORT
332 
333 #endif /* PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DECL_HPP_ */
virtual GlobalOrdinal getIndexBase() const
The index base for this Map.
virtual std::string description() const
A simple one-line description of this object.
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
Map< LocalOrdinal, GlobalOrdinal, Node >::global_indices_array_device_type global_indices_array_device_type
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get this Map&#39;s Comm object.
virtual ~BlockedMap()
Destructor.
std::vector< RCP< const Map > > maps_
virtual bool isCompatible(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getFullMap() const
the full map
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
virtual global_size_t getGlobalNumElements() const
The number of elements in this Map.
virtual GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
virtual bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
const RCP< Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > > getImporter(size_t i) const
get the importer between full map and partial map
virtual RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int >> &) const
Replace this Map&#39;s communicator with a subset communicator.
virtual void assign(const BlockedMap &input)
Implementation of the assignment operator (operator=); does a deep copy.
local_map_type getLocalMap() const
Get the local Map for Kokkos kernels.
virtual global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process.
virtual LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &, const Teuchos::ArrayView< int > &, const Teuchos::ArrayView< LocalOrdinal > &) const
Return the process ranks and corresponding local indices for the given global indices.
virtual bool isSameAs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
virtual LocalOrdinal getMinLocalIndex() const
The minimum local index.
size_t getNumMaps() const
number of partial maps
virtual GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
virtual LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
virtual bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
BlockedMap< LocalOrdinal, GlobalOrdinal, Node > & operator=(const BlockedMap &rhs)
Assignment operator: Does a deep copy.
size_t global_size_t
Global size_t object.
Kokkos::View< const global_ordinal_type *, typename Node::device_type > global_indices_array_device_type
static Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > concatenateMaps(const std::vector< Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node >>> &subMaps)
Helper function to concatenate several maps.
virtual UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
virtual GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
std::vector< RCP< Import > > importers_
typename Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node >::local_map_type local_map_type
virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
virtual LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
virtual bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
virtual bool isContiguous() const
True if this Map is distributed contiguously, else false.
virtual size_t getLocalNumElements() const
The number of elements belonging to the calling process.
virtual GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
size_t getMapIndexForGID(GlobalOrdinal gid) const
returns map index in map extractor which contains GID
std::vector< RCP< const Map > > thyraMaps_
virtual bool getThyraMode() const
Local number of rows on the calling process.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
virtual Teuchos::ArrayView< const GlobalOrdinal > getLocalElementList() const
Return a view of the global indices owned by this process.