MueLu Version of the Day
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
60
61#include "MueLu_Exceptions.hpp"
62
63namespace MueLu {
64
72 template<class LocalOrdinal, class GlobalOrdinal, class Node>
73 class LWGraph_kokkos;
74
75 // Partial specialization for DeviceType
76 template<class LocalOrdinal, class GlobalOrdinal, class DeviceType>
77 class LWGraph_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>> {
78 public:
79 using local_ordinal_type = LocalOrdinal;
80 using global_ordinal_type = GlobalOrdinal;
81 using execution_space = typename DeviceType::execution_space;
82 using memory_space = typename DeviceType::memory_space;
83 using device_type = Kokkos::Device<execution_space, memory_space>;
85 using node_type = Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>;
86 using size_type = size_t;
87
88 using map_type = Xpetra::Map<LocalOrdinal, GlobalOrdinal, node_type>;
89 using local_graph_type = Kokkos::StaticCrsGraph<LocalOrdinal,
91 device_type, void, size_t>;
92 using boundary_nodes_type = Kokkos::View<const bool*, memory_space>;
94
95 private:
96 // For compatibility
97 typedef node_type Node;
98#undef MUELU_LWGRAPH_KOKKOS_SHORT
100
101 public:
102
104
105
107 //
108 // @param[in] graph: local graph of type Kokkos::StaticCrsGraph containing CRS data
109 // @param[in] domainMap: non-overlapping (domain) map for graph. Usually provided by AmalgamationFactory stored in UnAmalgamationInfo container
110 // @param[in] importMap: overlapping map for graph. Usually provided by AmalgamationFactory stored in UnAmalgamationInfo container
111 // @param[in] objectLabel: label string
112 LWGraph_kokkos(const local_graph_type& graph,
113 const RCP<const map_type>& domainMap,
114 const RCP<const map_type>& importMap,
115 const std::string& objectLabel = "");
116
117 ~LWGraph_kokkos() { }
119
120 const RCP<const Teuchos::Comm<int> > GetComm() const {
121 return domainMap_->getComm();
122 }
123 const RCP<const Map> GetDomainMap() const {
124 return domainMap_;
125 }
127 const RCP<const Map> GetImportMap() const {
128 return importMap_;
129 }
130
132 KOKKOS_INLINE_FUNCTION size_type GetNodeNumVertices() const {
133 return graph_.numRows();
134 }
136 KOKKOS_INLINE_FUNCTION size_type GetNodeNumEdges() const {
137 return graph_.row_map(GetNodeNumVertices());
138 }
139
141 KOKKOS_INLINE_FUNCTION size_type getNodeMaxNumRowEntries () const {
142 return maxNumRowEntries_;
143 }
144
146 KOKKOS_INLINE_FUNCTION typename local_graph_type::row_map_type getRowPtrs() const {
147 return graph_.row_map;
148 }
149
151 KOKKOS_INLINE_FUNCTION typename local_graph_type::entries_type getEntries() const {
152 return graph_.entries;
153 }
154
156 // Unfortunately, C++11 does not support the following:
157 // auto getNeighborVertices(LO i) const -> decltype(rowView)
158 // auto return with decltype was only introduced in C++14
159 KOKKOS_INLINE_FUNCTION
160 Kokkos::GraphRowViewConst<local_graph_type> getNeighborVertices(LO i) const {
161 auto rowView = graph_.rowConst(i);
162
163 return rowView;
164 }
165
167 KOKKOS_INLINE_FUNCTION bool isLocalNeighborVertex(LO i) const {
168 return i >= minLocalIndex_ && i <= maxLocalIndex_;
169 }
170
172 KOKKOS_INLINE_FUNCTION void SetBoundaryNodeMap(const boundary_nodes_type bndry) {
173 dirichletBoundaries_ = bndry;
174 }
175
177 KOKKOS_INLINE_FUNCTION const boundary_nodes_type GetBoundaryNodeMap() const {
178 return dirichletBoundaries_;
179 }
180
182 std::string description() const {
183 return "LWGraph (" + objectLabel_ + ")";
184 }
185
187 void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel = Default) const;
188
189 private:
190
192 const local_graph_type graph_;
193
195 const RCP<const map_type> domainMap_;
196 const RCP<const map_type> importMap_;
197
199 boundary_nodes_type dirichletBoundaries_;
200
202 LO minLocalIndex_, maxLocalIndex_;
203 size_type maxNumRowEntries_;
204
206 const std::string& objectLabel_;
207 };
208
209}
210
211#define MUELU_LWGRAPH_KOKKOS_SHORT
212#endif // HAVE_MUELU_KOKKOS_REFACTOR
213#endif // MUELU_LWGRAPH_KOKKOS_DECL_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultGlobalOrdinal GlobalOrdinal
MueLu::DefaultNode Node
Namespace for MueLu classes and methods.