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>
61 
62 #include "MueLu_BaseClass.hpp"
63 
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  typedef LocalOrdinal local_ordinal_type;
110  typedef GlobalOrdinal global_ordinal_type;
111  typedef typename DeviceType::execution_space execution_space;
113  typedef Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> node_type;
114  typedef DeviceType device_type;
115 
116  typedef Kokkos::View<LocalOrdinal*, DeviceType> aggregates_sizes_type;
118 
119  private:
120  // For compatibility
121  typedef node_type Node;
122 #undef MUELU_AGGREGATES_KOKKOS_SHORT
124 
125  public:
126 
127  public:
128 
136  Aggregates_kokkos(LWGraph_kokkos graph);
137 
143  Aggregates_kokkos(const RCP<const Map>& map);
144 
148  virtual ~Aggregates_kokkos() { }
149 
151  KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const {
152  return numAggregates_;
153  }
154 
159  void SetNumAggregates(LO nAggregates) { numAggregates_ = nAggregates; }
160 
165  RCP<IndexManager_kokkos>& GetIndexManager() { return geoData_; }
166 
171  void SetIndexManager(RCP<IndexManager_kokkos> & geoData) { geoData_ = geoData; }
172 
174  KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool& flag) {
175  aggregatesIncludeGhosts_ = flag;
176  }
177 
182  KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const {
183  return aggregatesIncludeGhosts_;
184  }
185 
190  RCP<LOVector>& GetVertex2AggIdNonConst() { return vertex2AggId_; }
191 
196  RCP<LOVector>& GetProcWinnerNonConst() { return procWinner_; }
201  const RCP<LOVector>& GetVertex2AggId() const { return vertex2AggId_; }
202 
207  const RCP<LOVector>& GetProcWinner() const { return procWinner_; }
208 
210  KOKKOS_INLINE_FUNCTION
211  bool IsRoot(LO i) const { return isRoot_(i); }
212 
217  KOKKOS_INLINE_FUNCTION
218  void SetIsRoot(LO i, bool value = true) { isRoot_(i) = value; }
219 
220  const RCP<const Map> GetMap() const;
221 
231  typename aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute = false) const;
232 
233  local_graph_type GetGraph() const;
234 
236 
237 
239  std::string description() const;
240 
242  //using MueLu::Describable::describe; // overloading, not hiding
243  void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const;
244 
245  private:
246  LO numAggregates_;
247 
252  RCP<LOVector> vertex2AggId_;
253 
258  RCP<LOVector> procWinner_;
259 
263  RCP<IndexManager_kokkos> geoData_;
264 
266 
268  bool aggregatesIncludeGhosts_;
269 
271  mutable
272  aggregates_sizes_type aggregateSizes_;
273 
275  mutable
276  local_graph_type graph_;
277 
279  // 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.
280  GO GetNumGlobalAggregates() const;
281  };
282 
283 } //namespace MueLu
284 
285 #endif // HAVE_MUELU_KOKKOS_REFACTOR
286 
287 #define MUELU_AGGREGATES_KOKKOS_SHORT
288 #endif // MUELU_AGGREGATES_KOKKOS_DECL_HPP
GlobalOrdinal GO
LocalOrdinal LO