MueLu  Version of the Day
MueLu_Aggregates_kokkos_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 // Tobias Wiesner (tawiesn@sandia.gov)
43 //
44 // ***********************************************************************
45 //
46 // @HEADER
47 #ifndef MUELU_AGGREGATES_KOKKOS_DECL_HPP
48 #define MUELU_AGGREGATES_KOKKOS_DECL_HPP
49 
50 #include "MueLu_ConfigDefs.hpp"
51 
52 #include <Kokkos_StaticCrsGraph.hpp>
53 #include <KokkosCompat_ClassicNodeAPI_Wrapper.hpp>
54 
56 
57 #include <Xpetra_Map_fwd.hpp>
58 #include <Xpetra_Vector_fwd.hpp>
59 #include <Xpetra_VectorFactory_fwd.hpp>
60 
61 #include "MueLu_BaseClass.hpp"
62 
63 #include "MueLu_LWGraph_kokkos.hpp"
64 #include "MueLu_IndexManager_kokkos.hpp"
65 
66 #define MUELU_UNAGGREGATED -1 /* indicates that a node is unassigned to */
67  /* any aggregate. */
68 
69 #define MUELU_UNASSIGNED -1 /* indicates a vertex is not yet claimed */
70  /* by a processor during aggregation. */
71  /* Note, it is possible at */
72  /* this stage that some processors may have*/
73  /* claimed their copy of a vertex for one */
74  /* of their aggregates. However, some */
75  /* arbitration still needs to occur. */
76  /* The corresponding procWinner[]'s remain */
77  /* as MUELU_UNASSIGNED until */
78  /* ArbitrateAndCommunicate() is */
79  /* invoked to arbitrate. */
80 
81 /*****************************************************************************
82 
83 ****************************************************************************/
84 
85 namespace MueLu {
86 
102  template <class LocalOrdinal, class GlobalOrdinal, class Node>
104 
105  template <class LocalOrdinal, class GlobalOrdinal, class DeviceType>
106  class Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> > : public BaseClass {
107  public:
108  // For some reason we seem intent on having these declared before pulling the short names in
109  // I am not sure why but I will keep things as it is for now
110  // If you need to define a type that depend on a short name please do it further down after
111  // the header has been included!
114  using execution_space = typename DeviceType::execution_space;
115  using node_type = Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>;
116  using device_type = DeviceType;
117  using range_type = Kokkos::RangePolicy<local_ordinal_type, execution_space>;
118  using LO_view = Kokkos::View<local_ordinal_type*, device_type>;
119 
120  using aggregates_sizes_type = Kokkos::View<LocalOrdinal*, device_type>;
121 
122  private:
123  // For compatibility
124  typedef node_type Node;
125 #undef MUELU_AGGREGATES_KOKKOS_SHORT
127 
128  public:
129 
130  // Defining types that require the short names included above
131  using local_graph_type = typename LWGraph_kokkos::local_graph_type;
132  using colors_view_type = Kokkos::View<typename local_graph_type::entries_type::data_type,
133  typename local_graph_type::device_type::memory_space>;
134 
143 
149  Aggregates_kokkos(const RCP<const Map>& map);
150 
154  virtual ~Aggregates_kokkos() { }
155 
157 
158 
162  RCP<IndexManager_kokkos>& GetIndexManager() { return geoData_; }
163 
167  void SetIndexManager(RCP<IndexManager_kokkos> & geoData) { geoData_ = geoData; }
168 
172  colors_view_type& GetGraphColors() { return graphColors_; }
173 
177  void SetGraphColors(colors_view_type graphColors) { graphColors_ = graphColors; }
178 
181  LO GetGraphNumColors() { return graphNumColors_; }
182 
185  void SetGraphNumColors(const LO graphNumColors) { graphNumColors_ = graphNumColors; }
186 
188 
193  void SetNumAggregates(LO nAggregates) { numAggregates_ = nAggregates; }
194 
199  void SetNumGlobalAggregates(GO nGlobalAggregates) { numGlobalAggregates_ = nGlobalAggregates; }
200 
202  KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const {
203  return numAggregates_;
204  }
205 
207  KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool& flag) {
208  aggregatesIncludeGhosts_ = flag;
209  }
210 
215  KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const {
216  return aggregatesIncludeGhosts_;
217  }
218 
223  RCP<LOVector>& GetVertex2AggIdNonConst() { return vertex2AggId_; }
224 
229  RCP<LOVector>& GetProcWinnerNonConst() { return procWinner_; }
234  const RCP<LOVector>& GetVertex2AggId() const { return vertex2AggId_; }
235 
240  const RCP<LOVector>& GetProcWinner() const { return procWinner_; }
241 
243  KOKKOS_INLINE_FUNCTION
244  bool IsRoot(LO i) const { return isRoot_(i); }
245 
250  KOKKOS_INLINE_FUNCTION
251  void SetIsRoot(LO i, bool value = true) { isRoot_(i) = value; }
252 
253  const RCP<const Map> GetMap() const;
254 
264  typename aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute = false) const;
265 
266  local_graph_type GetGraph() const;
267 
272  void ComputeNodesInAggregate(LO_view & aggPtr, LO_view & aggNodes, LO_view & unaggregated) const;
273 
275  // If # of global aggregates is unknown, this method does coummunication and internally record the value
276  GO GetNumGlobalAggregatesComputeIfNeeded();
277 
279 
280 
282  std::string description() const;
283 
285  //using MueLu::Describable::describe; // overloading, not hiding
286  void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const;
287 
288  private:
291 
296  RCP<LOVector> vertex2AggId_;
297 
302  RCP<LOVector> procWinner_;
303 
307  RCP<IndexManager_kokkos> geoData_;
308 
313 
318 
319  Kokkos::View<bool*, device_type> isRoot_;
320 
323 
325  mutable
327 
329  mutable
331  };
332 
333 } //namespace MueLu
334 
335 #define MUELU_AGGREGATES_KOKKOS_SHORT
336 #endif // MUELU_AGGREGATES_KOKKOS_DECL_HPP
void SetGraphNumColors(const LO graphNumColors)
Set the number of colors needed by the distance 2 coloring.
MueLu::DefaultLocalOrdinal LocalOrdinal
Lightweight MueLu representation of a compressed row storage graph.
RCP< LOVector > & GetVertex2AggIdNonConst()
Returns a nonconstant vector that maps local node IDs to local aggregates IDs.
RCP< IndexManager_kokkos > & GetIndexManager()
Get the index manager used by structured aggregation algorithms. This has to be done by the aggregati...
bool aggregatesIncludeGhosts_
Set to false iff aggregates do not include any DOFs belong to other processes.
Namespace for MueLu classes and methods.
const RCP< LOVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
void SetGraphColors(colors_view_type graphColors)
Set a distance 2 coloring of the underlying graph. The coloring is computed and set during Phase1 of ...
MueLu::DefaultGlobalOrdinal GlobalOrdinal
void SetIndexManager(RCP< IndexManager_kokkos > &geoData)
Set the index manager used by structured aggregation algorithms. This has to be done by the aggregati...
RCP< LOVector > & GetProcWinnerNonConst()
Returns nonconsant vector that maps local node IDs to owning processor IDs.
Base class for MueLu classes.
KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool &flag)
Record whether aggregates include DOFs from other processes.
Kokkos::View< typename local_graph_type::entries_type::data_type, typename local_graph_type::device_type::memory_space > colors_view_type
colors_view_type & GetGraphColors()
Get a distance 2 coloring of the underlying graph. The coloring is computed and set during Phase1 of ...
KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const
Return false if and only if no aggregates include DOFs from other processes.
void SetNumGlobalAggregates(GO nGlobalAggregates)
Set number of global aggregates on current processor.
KOKKOS_INLINE_FUNCTION bool IsRoot(LO i) const
Returns true if node with given local node id is marked to be a root node.