MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
52 
53 #include <Kokkos_StaticCrsGraph.hpp>
54 #include <KokkosCompat_ClassicNodeAPI_Wrapper.hpp>
55 
57 
58 #include <Xpetra_Map_fwd.hpp>
59 #include <Xpetra_Vector_fwd.hpp>
60 #include <Xpetra_VectorFactory_fwd.hpp>
61 
62 #include "MueLu_BaseClass.hpp"
63 
64 #include "MueLu_LWGraph_kokkos.hpp"
65 #include "MueLu_IndexManager_kokkos.hpp"
66 
67 #define MUELU_UNAGGREGATED -1 /* indicates that a node is unassigned to */
68  /* any aggregate. */
69 
70 #define MUELU_UNASSIGNED -1 /* indicates a vertex is not yet claimed */
71  /* by a processor during aggregation. */
72  /* Note, it is possible at */
73  /* this stage that some processors may have*/
74  /* claimed their copy of a vertex for one */
75  /* of their aggregates. However, some */
76  /* arbitration still needs to occur. */
77  /* The corresponding procWinner[]'s remain */
78  /* as MUELU_UNASSIGNED until */
79  /* ArbitrateAndCommunicate() is */
80  /* invoked to arbitrate. */
81 
82 /*****************************************************************************
83 
84 ****************************************************************************/
85 
86 namespace MueLu {
87 
103  template <class LocalOrdinal, class GlobalOrdinal, class Node>
104  class Aggregates_kokkos;
105 
106  template <class LocalOrdinal, class GlobalOrdinal, class DeviceType>
107  class Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> > : public BaseClass {
108  public:
109  // For some reason we seem intent on having these declared before pulling the short names in
110  // I am not sure why but I will keep things as it is for now
111  // If you need to define a type that depend on a short name please do it further down after
112  // the header has been included!
113  using local_ordinal_type = LocalOrdinal;
114  using global_ordinal_type = GlobalOrdinal;
115  using execution_space = typename DeviceType::execution_space;
116  using node_type = Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>;
117  using device_type = DeviceType;
119 
120  using aggregates_sizes_type = Kokkos::View<LocalOrdinal*, DeviceType>;
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 
142  Aggregates_kokkos(LWGraph_kokkos graph);
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 
196  KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const {
197  return numAggregates_;
198  }
199 
201  KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool& flag) {
202  aggregatesIncludeGhosts_ = flag;
203  }
204 
209  KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const {
210  return aggregatesIncludeGhosts_;
211  }
212 
217  RCP<LOVector>& GetVertex2AggIdNonConst() { return vertex2AggId_; }
218 
223  RCP<LOVector>& GetProcWinnerNonConst() { return procWinner_; }
228  const RCP<LOVector>& GetVertex2AggId() const { return vertex2AggId_; }
229 
234  const RCP<LOVector>& GetProcWinner() const { return procWinner_; }
235 
237  KOKKOS_INLINE_FUNCTION
238  bool IsRoot(LO i) const { return isRoot_(i); }
239 
244  KOKKOS_INLINE_FUNCTION
245  void SetIsRoot(LO i, bool value = true) { isRoot_(i) = value; }
246 
247  const RCP<const Map> GetMap() const;
248 
258  typename aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute = false) const;
259 
260  local_graph_type GetGraph() const;
261 
263 
264 
266  std::string description() const;
267 
269  //using MueLu::Describable::describe; // overloading, not hiding
270  void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const;
271 
272  private:
273  LO numAggregates_;
274 
279  RCP<LOVector> vertex2AggId_;
280 
285  RCP<LOVector> procWinner_;
286 
290  RCP<IndexManager_kokkos> geoData_;
291 
295  colors_view_type graphColors_;
296 
300  LO graphNumColors_;
301 
303 
305  bool aggregatesIncludeGhosts_;
306 
308  mutable
309  aggregates_sizes_type aggregateSizes_;
310 
312  mutable
313  local_graph_type graph_;
314 
316  // This method is private because it is used only for printing and because with the current implementation, communication occurs each time this method is called.
317  GO GetNumGlobalAggregates() const;
318  };
319 
320 } //namespace MueLu
321 
322 #endif // HAVE_MUELU_KOKKOS_REFACTOR
323 
324 #define MUELU_AGGREGATES_KOKKOS_SHORT
325 #endif // MUELU_AGGREGATES_KOKKOS_DECL_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultNode Node
MueLu::DefaultGlobalOrdinal GlobalOrdinal