MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_LWGraph_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 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_LWGRAPH_KOKKOS_DECL_HPP
47 #define MUELU_LWGRAPH_KOKKOS_DECL_HPP
48 
49 #include "MueLu_ConfigDefs.hpp"
50 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
51 
52 #include <Kokkos_StaticCrsGraph.hpp>
53 #include <KokkosCompat_ClassicNodeAPI_Wrapper.hpp>
54 
55 #include <Xpetra_ConfigDefs.hpp> // global_size_t
56 #include <Xpetra_Map.hpp>
57 
59 
60 #include "MueLu_Exceptions.hpp"
61 
62 namespace MueLu {
63 
71  template<class LocalOrdinal, class GlobalOrdinal, class Node>
72  class LWGraph_kokkos;
73 
74  // Partial specialization for DeviceType
75  template<class LocalOrdinal, class GlobalOrdinal, class DeviceType>
76  class LWGraph_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>> {
77  public:
78  typedef LocalOrdinal local_ordinal_type;
79  typedef GlobalOrdinal global_ordinal_type;
80  typedef typename DeviceType::execution_space execution_space;
82  typedef Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> node_type;
83  typedef size_t size_type;
84 
87  typedef Kokkos::View<const bool*, DeviceType> boundary_nodes_type;
89 
90  private:
91  // For compatibility
92  typedef node_type Node;
93 #undef MUELU_LWGRAPH_KOKKOS_SHORT
95 
96  public:
97 
99 
100 
102  //
103  // @param[in] graph: local graph of type Kokkos::CsrStaticGraph containing CSR data
104  // @param[in] domainMap: non-overlapping (domain) map for graph. Usually provided by AmalgamationFactory stored in UnAmalgamationInfo container
105  // @param[in] importMap: overlapping map for graph. Usually provided by AmalgamationFactory stored in UnAmalgamationInfo container
106  // @param[in] objectLabel: label string
107  LWGraph_kokkos(const local_graph_type& graph,
108  const RCP<const map_type>& domainMap,
109  const RCP<const map_type>& importMap,
110  const std::string& objectLabel = "");
111 
112  ~LWGraph_kokkos() { }
114 
115  const RCP<const Teuchos::Comm<int> > GetComm() const {
116  return domainMap_->getComm();
117  }
118  const RCP<const Map> GetDomainMap() const {
119  return domainMap_;
120  }
122  const RCP<const Map> GetImportMap() const {
123  return importMap_;
124  }
125 
127  KOKKOS_INLINE_FUNCTION size_type GetNodeNumVertices() const {
128  return graph_.numRows();
129  }
131  KOKKOS_INLINE_FUNCTION size_type GetNodeNumEdges() const {
132  return graph_.row_map(GetNodeNumVertices());
133  }
134 
136  // Unfortunately, C++11 does not support the following:
137  // auto getNeighborVertices(LO i) const -> decltype(rowView)
138  // auto return with decltype was only introduced in C++14
139  KOKKOS_INLINE_FUNCTION
140  Kokkos::GraphRowViewConst<local_graph_type> getNeighborVertices(LO i) const {
141  auto rowView = graph_.rowConst(i);
142 
143  return rowView;
144  }
145 
147  KOKKOS_INLINE_FUNCTION bool isLocalNeighborVertex(LO i) const {
148  return i >= minLocalIndex_ && i <= maxLocalIndex_;
149  }
150 
152  KOKKOS_INLINE_FUNCTION void SetBoundaryNodeMap(const boundary_nodes_type bndry) {
153  dirichletBoundaries_ = bndry;
154  }
155 
157  KOKKOS_INLINE_FUNCTION size_type getNodeMaxNumRowEntries () const {
158  return maxNumRowEntries_;
159  }
160 
162  KOKKOS_INLINE_FUNCTION const boundary_nodes_type GetBoundaryNodeMap() const {
163  return dirichletBoundaries_;
164  }
165 
167  std::string description() const {
168  return "LWGraph (" + objectLabel_ + ")";
169  }
170 
172  // void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel = Default) const;
173 
174  private:
175 
177  const local_graph_type graph_;
178 
180  const RCP<const map_type> domainMap_;
181  const RCP<const map_type> importMap_;
182 
184  boundary_nodes_type dirichletBoundaries_;
185 
187  LO minLocalIndex_, maxLocalIndex_;
188  size_type maxNumRowEntries_;
189 
191  const std::string& objectLabel_;
192  };
193 
194 }
195 
196 #define MUELU_LWGRAPH_KOKKOS_SHORT
197 #endif // HAVE_MUELU_KOKKOS_REFACTOR
198 #endif // MUELU_LWGRAPH_KOKKOS_DECL_HPP
LocalOrdinal LO