12 #include "Teuchos_RCP.hpp"
13 #include "Teuchos_Comm.hpp"
15 #include "Tpetra_CrsGraph.hpp"
16 #include "Tpetra_CrsMatrix.hpp"
20 #include "KokkosKernels_Utils.hpp"
21 #include "KokkosSparse_Utils.hpp"
31 template <
typename LO,
typename GO,
typename NO,
typename list_of_colors_t>
34 const Tpetra::CrsGraph<LO, GO, NO> &graph,
35 const list_of_colors_t &list_of_colors)
37 typedef typename list_of_colors_t::execution_space execution_space;
39 Teuchos::RCP<const Teuchos::Comm<int>> comm = graph.getRowMap()->getComm();
40 const int rank = comm->getRank();
41 auto local_graph = graph.getLocalGraphDevice();
42 const size_t num_rows = graph.getLocalNumRows();
43 size_t num_conflict = 0;
45 Kokkos::parallel_reduce(
46 "check_coloring()", Kokkos::RangePolicy<execution_space>(0, num_rows),
47 KOKKOS_LAMBDA(
const size_t row,
size_t &lcl_conflict) {
48 const size_t entry_begin = local_graph.row_map(row);
49 const size_t entry_end = local_graph.row_map(row + 1);
50 for (
size_t entry = entry_begin; entry < entry_end; entry++)
52 const size_t col = local_graph.entries(entry);
53 for (
size_t entry2 = entry_begin; entry2 < entry_end; ++entry2)
55 const size_t col2 = local_graph.entries(entry2);
56 if (col != col2 && list_of_colors[col] == list_of_colors[col2])
60 "proc = %i : Invalid coloring! Local row %zu"
61 " and columns %zu, %zu have the same color %i\n",
62 rank, row, col, col2, list_of_colors[col]);
69 size_t global_num_conflict = 0;
70 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 1, &num_conflict,
71 &global_num_conflict);
73 return global_num_conflict == 0;
77 template <
typename LocalCrsGraphType>
80 const LocalCrsGraphType &local_graph,
81 const size_t num_cols)
83 using KokkosSparse::Impl::transpose_graph;
85 typedef LocalCrsGraphType graph_t;
86 typedef typename graph_t::row_map_type lno_view_t;
87 typedef typename graph_t::entries_type lno_nnz_view_t;
88 typedef typename lno_view_t::non_const_type trans_row_view_t;
89 typedef typename lno_nnz_view_t::non_const_type trans_nnz_view_t;
90 typedef typename lno_view_t::execution_space exec_t;
93 const size_t num_rows = local_graph.row_map.extent(0) - 1;
94 const size_t num_nnz = local_graph.entries.extent(0);
96 trans_row_view_t trans_row_map(
"trans_row_map", num_cols + 1);
97 trans_nnz_view_t trans_entries(
"trans_entries", num_nnz);
99 transpose_graph<lno_view_t, lno_nnz_view_t, trans_row_view_t,
100 trans_nnz_view_t, trans_row_view_t, exec_t>(
101 num_rows, num_cols, local_graph.row_map, local_graph.entries,
102 trans_row_map, trans_entries);
104 graph_t local_trans_graph(trans_entries, trans_row_map);
106 return local_trans_graph;
124 template <
typename LO,
typename GO,
typename NO>
125 Teuchos::RCP<Tpetra::CrsGraph<LO, GO, NO>>
131 typedef Tpetra::CrsGraph<LO, GO, NO> graph_t;
132 typedef typename graph_t::local_graph_device_type local_graph_t;
135 local_graph_t local_graph = graph.getLocalGraphDevice();
136 local_graph_t local_trans_graph =
138 graph.getLocalNumCols());
153 RCP<graph_t> trans_graph_shared = rcp(
new graph_t(
154 local_trans_graph, graph.getColMap(), graph.getRowMap(),
155 graph.getRangeMap(), graph.getRowMap()));
157 RCP<graph_t> trans_graph;
161 RCP<const Tpetra::Export<LO, GO, NO>> exporter =
162 trans_graph_shared->getExporter();
163 if (exporter == Teuchos::null)
164 trans_graph = trans_graph_shared;
167 RCP<const graph_t> trans_graph_shared_const = trans_graph_shared;
168 trans_graph = Tpetra::exportAndFillCompleteCrsGraph(
169 trans_graph_shared_const, *exporter,
170 Teuchos::null, Teuchos::null, Teuchos::null);
177 template <
typename SC,
typename LO,
typename GO,
typename NO>
178 Teuchos::RCP<Tpetra::CrsGraph<LO, GO, NO>>
185 template <
typename SC,
typename LO,
typename GO,
typename NO>
186 Teuchos::RCP<Tpetra::CrsGraph<LO, GO, NO>>
LocalCrsGraphType compute_local_transpose_graph(const LocalCrsGraphType &local_graph, const size_t num_cols)
Teuchos::RCP< Tpetra::CrsGraph< LO, GO, NO > > compute_transpose_graph(const Tpetra::CrsGraph< LO, GO, NO > &graph)
bool check_coloring(const Tpetra::CrsGraph< LO, GO, NO > &graph, const list_of_colors_t &list_of_colors)