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 
56 
57 namespace Xpetra {
58 
59 
60 
61 template<class LocalOrdinal,
62  class GlobalOrdinal,
64 class BlockedMap : public Map<LocalOrdinal, GlobalOrdinal, Node>
65 {
66  public:
67 
68  typedef LocalOrdinal local_ordinal_type;
69  typedef GlobalOrdinal global_ordinal_type;
70  typedef Node node_type;
71 
72  private:
73 
74 #undef XPETRA_BLOCKEDMAP_SHORT
76 
77  public:
78 
80 
81 
83 
85  BlockedMap();
86 
87 
105  BlockedMap(const RCP<const Map>& fullmap, const std::vector<RCP<const Map>>& maps, bool bThyraMode = false);
106 
107 
109  BlockedMap(const std::vector<RCP<const Map>>& maps, const std::vector<RCP<const Map>>& thyramaps);
110 
111 
113  BlockedMap(const BlockedMap& input);
114 
115 
117  virtual ~BlockedMap();
118 
119 
121 
122 
124  virtual global_size_t getGlobalNumElements() const;
125 
126 
128  virtual size_t getNodeNumElements() const;
129 
130 
132  virtual GlobalOrdinal getIndexBase() const;
133 
134 
136  virtual LocalOrdinal getMinLocalIndex() const;
137 
138 
140  virtual LocalOrdinal getMaxLocalIndex() const;
141 
142 
144  virtual GlobalOrdinal getMinGlobalIndex() const;
145 
146 
148  virtual GlobalOrdinal getMaxGlobalIndex() const;
149 
150 
152  virtual GlobalOrdinal getMinAllGlobalIndex() const;
153 
154 
156  virtual GlobalOrdinal getMaxAllGlobalIndex() const;
157 
158 
160  virtual LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const;
161 
162 
164  virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const;
165 
166 
168  virtual LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& /* GIDList */,
169  const Teuchos::ArrayView<int>& /* nodeIDList */,
170  const Teuchos::ArrayView<LocalOrdinal>& /* LIDList */) const;
171 
172 
174  virtual LookupStatus getRemoteIndexList(const Teuchos::ArrayView<const GlobalOrdinal>& /* GIDList */,
175  const Teuchos::ArrayView<int>& /* nodeIDList */) const;
176 
177 
179  virtual Teuchos::ArrayView<const GlobalOrdinal> getNodeElementList() const;
180 
181 
183 
184 
186 
187 
189  virtual bool isNodeLocalElement(LocalOrdinal localIndex) const;
190 
192  virtual bool isNodeGlobalElement(GlobalOrdinal globalIndex) const;
193 
195  virtual bool isContiguous() const;
196 
197 
199  virtual bool isDistributed() const;
200 
201 
203  virtual bool isCompatible(const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>& map) const;
204 
205 
207  virtual bool isSameAs(const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>& map) const;
208 
209 
211 
213 
214 
216  virtual Teuchos::RCP<const Teuchos::Comm<int>> getComm() const;
217 
218 
219 
220 
222 
223 
232 
233 
235 
236 
238 
239  /*virtual size_t getLocalLength() const {
241  throw Xpetra::Exceptions::RuntimeError("BlockedMap::getLocalLength: routine not implemented.");
242  return 0;
243  }*/
244 
246  /*virtual global_size_t getGlobalLength() const {
247  throw Xpetra::Exceptions::RuntimeError("BlockedMap::getGlobalLength: routine not implemented.");
248  return 0;
249  }*/
250 
251 
253  virtual bool getThyraMode() const;
254 
255 
257 
258 
260 
261 
262 
264  virtual RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> removeEmptyProcesses() const;
265 
266 
268  virtual RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
269  replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int>>& /* newComm */) const;
270 
271 
273 
274 
276 
277 
279  virtual UnderlyingLib lib() const;
280 
281 
282  // TODO: find a better solution for this hack
283  // The problem is that EpetraMap, TpetraMap and StridedMap all inherit Map. To have proper toEpetra() we
284  // need to understand the type of underlying matrix. But in src/Map we have no knowledge of StridedMaps, so
285  // we cannot check for it by casting. This function allows us to avoid the restriction, as StridedMap redefines
286  // it to return the base map.
287  virtual RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
288  getMap() const;
289 
290 
292 
293 
295  size_t getNumMaps() const;
296 
297 
302  const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>>
303  getMap(size_t i, bool bThyraMode = false) const;
304 
305 
307  const RCP<Xpetra::Import<LocalOrdinal,GlobalOrdinal,Node>>
308  getImporter(size_t i) const;
309 
310 
312  const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>>
313  getFullMap() const;
314 
315 
317  size_t getMapIndexForGID(GlobalOrdinal gid) const;
318 
319 
320 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
321  #ifdef HAVE_XPETRA_TPETRA
323 
325  local_map_type getLocalMap() const { return fullmap_->getLocalMap(); }
326 
327  #else // HAVE_XPETRA_TPETRA
328  #ifdef __GNUC__
329  #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."
330  #endif // __GNUC__
331  #endif // #else !HAVE_XPETRA_TPETRA
332 #endif // HAVE_XPETRA_KOKKOS_REFACTOR
333 
334 
336 
337 
339 
340 
341 
343  virtual std::string description() const;
344 
346  virtual void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
347 
348 
350 
351 
352  protected:
353 
354 
357  virtual void assign(const BlockedMap& input);
358 
359 
374  static Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
375  concatenateMaps(const std::vector<Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>>& subMaps);
376 
377 
378  private:
379 
380 
381  bool CheckConsistency() const;
382 
383 
384  private:
385 
386 
387  RCP<const Map> fullmap_;
388  std::vector<RCP<const Map>> maps_;
389  std::vector<RCP<Import>> importers_;
390  bool bThyraMode_; //< boolean flag: use Thyra numbering for local sub-block maps. default = false (for Xpetra mode)
391  std::vector<RCP<const Map>> thyraMaps_; //< store Thyra-style numbering maps here in Thyra mode. In Xpetra mode this vector is empty.
392 }; // BlockedMap class
393 
394 } // namespace Xpetra
395 
396 #define XPETRA_BLOCKEDMAP_SHORT
397 
398 #endif /* PACKAGES_XPETRA_SUP_BLOCKEDMAP_XPETRA_BLOCKEDMAP_DECL_HPP_ */
virtual GlobalOrdinal getIndexBase() const
The index base for this Map.
virtual Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
virtual std::string description() const
A simple one-line description of this object.
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 size_t getNodeNumElements() const
The number of elements belonging to the calling process.
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.
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.
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_
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 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.