MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_Aggregates_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
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 MUELU_AGGREGATES_DECL_HPP
47 #define MUELU_AGGREGATES_DECL_HPP
48 
49 #include "MueLu_ConfigDefs.hpp"
50 
51 #include <Kokkos_StaticCrsGraph.hpp>
52 
53 #include "MueLu_Aggregates_fwd.hpp"
54 
55 #include <Xpetra_Map_fwd.hpp>
56 #include <Xpetra_Vector_fwd.hpp>
59 
60 #include "MueLu_BaseClass.hpp"
61 
62 #include "MueLu_LWGraph_kokkos.hpp"
63 
64 #include "MueLu_LWGraph.hpp"
65 #include "MueLu_IndexManager.hpp"
66 #include "MueLu_IndexManager_kokkos.hpp"
67 
68 #define MUELU_UNAGGREGATED -1 /* indicates that a node is unassigned to */
69  /* any aggregate. */
70 
71 #define MUELU_UNASSIGNED -1 /* indicates a vertex is not yet claimed */
72  /* by a processor during aggregation. */
73  /* Note, it is possible at */
74  /* this stage that some processors may have*/
75  /* claimed their copy of a vertex for one */
76  /* of their aggregates. However, some */
77  /* arbitration still needs to occur. */
78  /* The corresponding procWinner[]'s remain */
79  /* as MUELU_UNASSIGNED until */
80  /* ArbitrateAndCommunicate() is */
81  /* invoked to arbitrate. */
82 
83 /*****************************************************************************
84 
85 ****************************************************************************/
86 
87 namespace MueLu {
88 
104 template <class LocalOrdinal, class GlobalOrdinal, class Node>
105 class Aggregates : public BaseClass {
106  public:
109  using execution_space = typename Node::execution_space;
110  using node_type = Node;
111  using device_type = typename Node::device_type;
112  using range_type = Kokkos::RangePolicy<local_ordinal_type, execution_space>;
113  using LO_view = Kokkos::View<local_ordinal_type*, device_type>;
114 
115  using aggregates_sizes_type = Kokkos::View<LocalOrdinal*, device_type>;
116 
117  private:
118 #undef MUELU_AGGREGATES_SHORT
120 
121  public:
122  // Defining types that require the short names included above
124  using colors_view_type = Kokkos::View<typename local_graph_type::entries_type::data_type,
125  typename local_graph_type::device_type::memory_space>;
126 
134  Aggregates(const LWGraph& graph);
135 
143  Aggregates(LWGraph_kokkos graph);
144 
150  Aggregates(const RCP<const Map>& map);
151 
155  virtual ~Aggregates() {}
156 
158 
159 
164 
168  void SetIndexManagerKokkos(RCP<IndexManager_kokkos>& geoDataKokkos) { geoDataKokkos_ = geoDataKokkos; }
169 
174 
178  void SetIndexManager(RCP<IndexManager>& geoData) { geoData_ = geoData; }
179 
184 
188  void SetGraphColors(colors_view_type graphColors) { graphColors_ = graphColors; }
189 
193 
196  void SetGraphNumColors(const LO graphNumColors) { graphNumColors_ = graphNumColors; }
197 
199 
204  void SetNumAggregates(LO nAggregates) { numAggregates_ = nAggregates; }
205 
210  void SetNumGlobalAggregates(GO nGlobalAggregates) { numGlobalAggregates_ = nGlobalAggregates; }
211 
213  KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const {
214  return numAggregates_;
215  }
216 
218  KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool& flag) {
220  }
221 
226  KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const {
228  }
229 
235 
246 
251  const RCP<LOVector>& GetProcWinner() const { return procWinner_; }
252 
254  inline bool IsRoot(LO i) const { return isRoot_[i]; }
255 
260  inline void SetIsRoot(LO i, bool value = true) { isRoot_[i] = value; }
261 
262  const RCP<const Map> GetMap() const;
263 
273  typename aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute = false) const;
274 
284  Teuchos::ArrayRCP<LocalOrdinal> ComputeAggregateSizesArrayRCP(bool forceRecompute = false) const;
285 
286  local_graph_type GetGraph() const;
287 
292  void ComputeNodesInAggregate(LO_view& aggPtr, LO_view& aggNodes, LO_view& unaggregated) const;
293 
295  // If # of global aggregates is unknown, this method does coummunication and internally record the value
297 
299 
300 
302  std::string description() const;
303 
305  // using MueLu::Describable::describe; // overloading, not hiding
306  void print(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const;
307 
308  private:
311 
317 
323 
328 
333 
338 
343 
346 
349 
352 
357  mutable
358  typename aggregates_sizes_type::HostMirror aggregateSizesHost_;
359 
362 };
363 
364 } // namespace MueLu
365 
366 #define MUELU_AGGREGATES_SHORT
367 #endif // MUELU_AGGREGATES_DECL_HPP
Kokkos::View< LocalOrdinal *, device_type > aggregates_sizes_type
virtual ~Aggregates()
Destructor.
MueLu::DefaultLocalOrdinal LocalOrdinal
void SetIndexManagerKokkos(RCP< IndexManager_kokkos > &geoDataKokkos)
Set the index manager used by structured aggregation algorithms. This has to be done by the aggregati...
typename Node::execution_space execution_space
typename Node::device_type device_type
Lightweight MueLu representation of a compressed row storage graph.
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
RCP< IndexManager > geoData_
void SetGraphNumColors(const LO graphNumColors)
Set the number of colors needed by the distance 2 coloring.
Container class for aggregation information.
RCP< IndexManager > & GetIndexManager()
Get the index manager used by various aggregation algorithms. This has to be done by the aggregation ...
bool aggregatesIncludeGhosts_
Set to false iff aggregates do not include any DOFs belong to other processes.
KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const
typename std::conditional< OnHost, typename local_graph_device_type::HostMirror, local_graph_device_type >::type local_graph_type
GlobalOrdinal GO
const RCP< const Map > GetMap() const
returns (overlapping) map of aggregate/node distribution
LocalOrdinal LO
colors_view_type graphColors_
void SetIndexManager(RCP< IndexManager > &geoData)
Set the index manager used by various aggregation algorithms. This has to be done by the aggregation ...
MueLu::DefaultNode Node
void SetIsRoot(LO i, bool value=true)
Set root node information.
GlobalOrdinal global_ordinal_type
RCP< LOMultiVector > & GetVertex2AggIdNonConst()
Returns a nonconstant vector that maps local node IDs to local aggregates IDs.
LO GetGraphNumColors()
Get the number of colors needed by the distance 2 coloring.
MueLu::DefaultGlobalOrdinal GlobalOrdinal
LO numAggregates_
Number of aggregates on this processor.
colors_view_type & GetGraphColors()
Get a distance 2 coloring of the underlying graph. The coloring is computed and set during Phase1 of ...
aggregates_sizes_type::HostMirror aggregateSizesHost_
RCP< IndexManager_kokkos > geoDataKokkos_
typename LWGraph_kokkos::local_graph_type local_graph_type
RCP< LOVector > & GetProcWinnerNonConst()
Returns nonconstant vector that maps local node IDs to owning processor IDs.
void ComputeNodesInAggregate(LO_view &aggPtr, LO_view &aggNodes, LO_view &unaggregated) const
Generates a compressed list of nodes in each aggregate, where the entries in aggNodes[aggPtr[i]] up t...
void SetGraphColors(colors_view_type graphColors)
Set a distance 2 coloring of the underlying graph. The coloring is computed and set during Phase1 of ...
GO GetNumGlobalAggregatesComputeIfNeeded()
Get global number of aggregates.
Teuchos::ArrayRCP< LocalOrdinal > ComputeAggregateSizesArrayRCP(bool forceRecompute=false) const
Compute sizes of aggregates.
Teuchos::ArrayRCP< bool > isRoot_
An ArrayRCP of booleans specifying if a local entry is an aggregate root.
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
aggregates_sizes_type aggregateSizes_
Array of sizes of each local aggregate.
Kokkos::RangePolicy< local_ordinal_type, execution_space > range_type
Kokkos::View< typename local_graph_type::entries_type::data_type, typename local_graph_type::device_type::memory_space > colors_view_type
void SetNumGlobalAggregates(GO nGlobalAggregates)
Set number of global aggregates on current processor.
static const EVerbosityLevel verbLevel_default
Base class for MueLu classes.
RCP< LOMultiVector > vertex2AggId_
Kokkos::View< local_ordinal_type *, device_type > LO_view
GO numGlobalAggregates_
Number of global aggregates.
Lightweight MueLu representation of a compressed row storage graph.
bool IsRoot(LO i) const
Returns true if node with given local node id is marked to be a root node.
Aggregates(const LWGraph &graph)
Standard constructor for Aggregates structure.
KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool &flag)
Record whether aggregates include DOFs from other processes.
void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
std::string description() const
Return a simple one-line description of this object.
local_graph_type GetGraph() const
KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const
Return false if and only if no aggregates include DOFs from other processes.
aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute=false) const
Compute sizes of aggregates.
local_graph_type graph_
Aggregates represented as Kokkos graph type.
void SetNumAggregates(LO nAggregates)
Set number of local aggregates on current processor.
RCP< IndexManager_kokkos > & GetIndexManagerKokkos()
Get the index manager used by structured aggregation algorithms. This has to be done by the aggregati...