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 #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 
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>
103  class Aggregates_kokkos;
104 
105  template <class LocalOrdinal, class GlobalOrdinal, class DeviceType>
106  class Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> > : public BaseClass {
107  public:
108  typedef LocalOrdinal local_ordinal_type;
109  typedef GlobalOrdinal global_ordinal_type;
110  typedef typename DeviceType::execution_space execution_space;
111  typedef Kokkos::RangePolicy<local_ordinal_type, execution_space> range_type;
112  typedef Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> node_type;
113  typedef DeviceType device_type;
114 
115  typedef Kokkos::View<LocalOrdinal*, DeviceType> aggregates_sizes_type;
116  typedef Kokkos::StaticCrsGraph<LocalOrdinal, Kokkos::LayoutLeft, execution_space> local_graph_type;
117 
118  private:
119  // For compatibility
120  typedef node_type Node;
121 #undef MUELU_AGGREGATES_KOKKOS_SHORT
123 
124  public:
125 
126  public:
127 
135  Aggregates_kokkos(LWGraph_kokkos graph);
136 
142  Aggregates_kokkos(const RCP<const Map>& map);
143 
147  virtual ~Aggregates_kokkos() { }
148 
150  KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const {
151  return numAggregates_;
152  }
153 
158  void SetNumAggregates(LO nAggregates) { numAggregates_ = nAggregates; }
159 
161  KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool& flag) {
162  aggregatesIncludeGhosts_ = flag;
163  }
164 
169  KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const {
170  return aggregatesIncludeGhosts_;
171  }
172 
177  RCP<LOVector>& GetVertex2AggIdNonConst() { return vertex2AggId_; }
178 
183  RCP<LOVector>& GetProcWinnerNonConst() { return procWinner_; }
188  const RCP<LOVector>& GetVertex2AggId() const { return vertex2AggId_; }
189 
194  const RCP<LOVector>& GetProcWinner() const { return procWinner_; }
195 
197  KOKKOS_INLINE_FUNCTION
198  bool IsRoot(LO i) const { return isRoot_(i); }
199 
204  KOKKOS_INLINE_FUNCTION
205  void SetIsRoot(LO i, bool value = true) { isRoot_(i) = value; }
206 
207  const RCP<const Map> GetMap() const;
208 
218  typename aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute = false) const;
219 
220  local_graph_type GetGraph() const;
221 
223 
224 
226  std::string description() const;
227 
229  //using MueLu::Describable::describe; // overloading, not hiding
230  void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const;
231 
232  private:
233  LO numAggregates_;
234 
239  RCP<LOVector> vertex2AggId_;
240 
245  RCP<LOVector> procWinner_;
246 
247  Kokkos::View<bool*, DeviceType> isRoot_;
248 
250  bool aggregatesIncludeGhosts_;
251 
253  mutable
254  aggregates_sizes_type aggregateSizes_;
255 
257  mutable
258  local_graph_type graph_;
259 
261  // 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.
262  GO GetNumGlobalAggregates() const;
263  };
264 
265 } //namespace MueLu
266 
267 #endif // HAVE_MUELU_KOKKOS_REFACTOR
268 
269 #define MUELU_AGGREGATES_KOKKOS_SHORT
270 #endif // MUELU_AGGREGATES_KOKKOS_DECL_HPP
Namespace for MueLu classes and methods.
::Kokkos::Compat::KokkosDeviceWrapperNode< execution_space > node_type