46 #ifndef MUELU_LWGRAPHBASE_DECL_HPP
47 #define MUELU_LWGRAPHBASE_DECL_HPP
49 #include "Kokkos_Bitset.hpp"
52 #include <Kokkos_StaticCrsGraph.hpp>
53 #include <Tpetra_KokkosCompat_ClassicNodeAPI_Wrapper.hpp>
54 #include <KokkosCompat_View.hpp>
60 #include <type_traits>
71 template <
class LocalOrdinal,
class RowType>
72 class MaxNumRowEntriesFunctor {
74 MaxNumRowEntriesFunctor(RowType rowPointers)
77 KOKKOS_INLINE_FUNCTION
78 void operator()(
const LocalOrdinal i,
size_t& maxLength)
const {
81 maxLength = (d > maxLength ? d : maxLength);
84 KOKKOS_INLINE_FUNCTION
85 void join(
volatile size_t& dest,
const volatile size_t& src) {
86 dest = (dest > src ? dest : src);
89 KOKKOS_INLINE_FUNCTION
90 void init(
size_t& initValue) {
107 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
bool OnHost>
116 using device_type =
typename std::conditional<OnHost,
117 Kokkos::Device<Kokkos::Serial, Kokkos::HostSpace>,
118 typename Node::device_type>::type;
124 typename Node::device_type,
126 using local_graph_type =
typename std::conditional<OnHost, typename local_graph_device_type::HostMirror, local_graph_device_type>::type;
128 using row_type =
typename local_graph_type::row_map_type;
132 #undef MUELU_LWGRAPHBASE_SHORT
142 const std::string& objectLabel) {
143 using range_type = Kokkos::RangePolicy<local_ordinal_type, execution_space>;
153 MaxNumRowEntriesFunctor<LO, typename local_graph_type::row_map_type> maxNumRowEntriesFunctor(
graph_.row_map);
154 Kokkos::parallel_reduce(
"MueLu:LocalLWGraph:LWGraph:maxnonzeros", range_type(0,
graph_.numRows()), maxNumRowEntriesFunctor,
maxNumRowEntries_);
167 const std::string& objectLabel =
"") {
168 setup(graph, domainMap, importMap, objectLabel);
172 const std::string& objectLabel =
"") {
173 if constexpr (OnHost) {
176 typename crs_graph_type::local_graph_type>::value)
182 auto lclGraphDevice = graph->getLocalGraphDevice();
183 auto rows =
typename local_graph_type::row_map_type::non_const_type(
"rows", lclGraphDevice.numRows() + 1);
184 auto columns =
typename local_graph_type::entries_type::non_const_type(
"columns", lclGraphDevice.entries.extent(0));
185 Kokkos::deep_copy(
rows, lclGraphDevice.row_map);
186 Kokkos::deep_copy(columns, lclGraphDevice.entries);
200 const std::string& objectLabel =
"") {
202 setup(graph, domainMap, importMap, objectLabel);
243 auto rowView =
graph_.rowConst(i);
249 return Kokkos::Compat::getArrayView(Kokkos::subview(
graph_.entries,
250 Kokkos::make_pair(
graph_.row_map(i),
286 if (verbLevel &
Debug) {
289 int mypid = col_map->getComm()->getRank();
292 std::ostringstream ss;
293 ss <<
"[pid " << mypid <<
"] num entries=" << graph.entries.size();
294 out << ss.str() << std::endl;
297 const size_t numRows = graph.numRows();
298 auto rowPtrs = graph.row_map;
299 auto columns = graph.entries;
300 auto rowPtrs_h = Kokkos::create_mirror_view(rowPtrs);
301 auto columns_h = Kokkos::create_mirror_view(columns);
302 Kokkos::deep_copy(rowPtrs_h, rowPtrs);
303 Kokkos::deep_copy(columns_h, columns);
304 for (
size_t i = 0; i < numRows; ++i) {
305 std::ostringstream ss;
307 ss <<
" (numEntries=" << rowPtrs_h(i + 1) - rowPtrs_h(i) <<
")";
309 for (
size_t jj = rowPtrs_h(i); jj < rowPtrs_h(i + 1); jj++) {
310 ss <<
" " << col_map->getGlobalElement(columns_h(jj));
312 out << ss.str() << std::endl;
324 typename crs_graph_type::local_graph_type>::value)
327 auto rows =
typename crs_graph_type::local_graph_type::row_map_type::non_const_type(
"rows",
graph_.numRows() + 1);
328 auto columns =
typename crs_graph_type::local_graph_type::entries_type::non_const_type(
"columns",
graph_.entries.extent(0));
330 Kokkos::deep_copy(columns,
graph_.entries);
331 typename crs_graph_type::local_graph_type lclGraph(columns,
rows);
358 #define MUELU_LWGRAPHBASE_SHORT
359 #endif // MUELU_LWGRAPHBASE_DECL_HPP
typename local_graph_type::row_map_type row_type
local_graph_type & getGraph() const
void setup(const local_graph_type &graph, const RCP< const map_type > &domainMap, const RCP< const map_type > &importMap, const std::string &objectLabel)
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const =0
MueLu::DefaultLocalOrdinal LocalOrdinal
size_type maxNumRowEntries_
virtual LocalOrdinal getMinLocalIndex() const =0
KOKKOS_INLINE_FUNCTION row_type getRowPtrs() const
Return the row pointers of the local graph.
KOKKOS_INLINE_FUNCTION void SetBoundaryNodeMap(const boundary_nodes_type bndry)
Set boolean array indicating which rows correspond to Dirichlet boundaries.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the Graph with some verbosity level to an FancyOStream object.
RCP< const map_type > importMap_
GlobalOrdinal global_ordinal_type
typename std::conditional< OnHost, typename local_graph_device_type::HostMirror, local_graph_device_type >::type local_graph_type
RCP< crs_graph_type > GetCrsGraph() const
static Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, ProfileType pftype=DynamicProfile)
std::string description() const
Return a simple one-line description of the Graph.
Print additional debugging information.
KOKKOS_INLINE_FUNCTION size_type GetNodeNumVertices() const
Return number of graph vertices.
KOKKOS_INLINE_FUNCTION size_type GetNodeNumEdges() const
Return number of graph edges.
KOKKOS_INLINE_FUNCTION const boundary_nodes_type GetBoundaryNodeMap() const
Returns map with global ids of boundary nodes.
typename device_type::execution_space execution_space
KOKKOS_INLINE_FUNCTION size_type getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Kokkos::GraphRowViewConst< local_graph_type > neighbor_vertices_type
Kokkos::View< bool *, memory_space > boundary_nodes_type
MueLu::DefaultGlobalOrdinal GlobalOrdinal
local_graph_type graph_
Underlying graph (with label)
LocalOrdinal local_ordinal_type
KOKKOS_INLINE_FUNCTION entries_type getEntries() const
Return the list entries in the local graph.
LWGraphBase(const row_type &rows, const entries_type &columns, const RCP< const map_type > &domainMap, const RCP< const map_type > &importMap, const std::string &objectLabel="")
KOKKOS_INLINE_FUNCTION bool isLocalNeighborVertex(LO i) const
Return true if vertex with local id 'v' is on current process.
virtual GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const =0
Kokkos::StaticCrsGraph< LocalOrdinal, Kokkos::LayoutLeft, typename Node::device_type, void, size_t > local_graph_device_type
virtual LocalOrdinal getMaxLocalIndex() const =0
KOKKOS_INLINE_FUNCTION neighbor_vertices_type getNeighborVertices(LO i) const
Return the list of vertices adjacent to the vertex 'v'.
const RCP< const Map > GetImportMap() const
Return overlapping import map (nodes).
typename local_graph_type::entries_type entries_type
boundary_nodes_type dirichletBoundaries_
Boolean array marking Dirichlet rows.
Xpetra::global_size_t GetGlobalNumEdges() const
Return global number of graph edges.
typename device_type::memory_space memory_space
const RCP< const Map > GetDomainMap() const
Teuchos::ArrayView< LO > getNeighborVertices_av(LO i) const
Return the list of vertices adjacent to the vertex 'v'.
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const =0
LWGraphBase(const local_graph_type &graph, const RCP< const map_type > &domainMap, const RCP< const map_type > &importMap, const std::string &objectLabel="")
LWGraph constructor.
RCP< const map_type > domainMap_
Graph maps.
typename std::conditional< OnHost, Kokkos::Device< Kokkos::Serial, Kokkos::HostSpace >, typename Node::device_type >::type device_type
std::string objectLabel_
Name of this graph.
const RCP< const Teuchos::Comm< int > > GetComm() const
LO minLocalIndex_
Local index boundaries (cached from domain map)
LWGraphBase(const RCP< const crs_graph_type > &graph, const std::string &objectLabel="")
virtual RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const =0