3 #include "Teuchos_ArrayRCP.hpp"
4 #include "Teuchos_TestForException.hpp"
6 #include "TpetraExt_MatrixMatrix.hpp"
7 #include "Tpetra_CrsMatrix_decl.hpp"
8 #include "Tpetra_RowMatrixTransposer.hpp"
21 using graph_t =
typename matrix_t::crs_graph_type;
22 using node_t =
typename matrix_t::node_type;
26 using SC =
typename matrix_t::scalar_type;
27 using LO =
typename matrix_t::local_ordinal_type;
28 using GO =
typename matrix_t::global_ordinal_type;
29 using vector_t =
typename Tpetra::Vector<SC, LO, GO, node_t>;
33 : matrix(matrix_), graph(Impl::
get_graph(matrix_)),
34 colorVecLocal_(matrix_->getRowMap()),
35 colorVecGlobal_(matrix_->getColMap()) {}
41 auto inputMat = this->matrix;
43 const auto matrixType = coloring_params.get(
"matrixType",
"Jacobian");
44 const auto symmetric = coloring_params.get(
45 "symmetric", (matrixType ==
"Jacobian" ?
false :
true));
51 const auto nzpr = this->matrix->getGlobalMaxNumRowEntries();
54 Teuchos::rcp(
new CrsMatrixType(matrix->getRowMap(), nzpr * nzpr));
59 inputMat->fillComplete();
64 Z2Adapter_t z2_adapter(inputMat);
66 auto z2_params = coloring_params.sublist(
"Zoltan2");
69 z2_params.set(
"color_method",
"D2");
76 auto local_num_colors = z2_solution->getNumColors();
78 auto local_list_of_colors = z2_solution->getColorsRCP();
79 const auto len = local_list_of_colors.size();
82 auto comm = this->graph->getRowMap()->getComm();
83 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, 1, &local_num_colors,
90 colorVecLocal_.getLocalViewHost(Tpetra::Access::ReadWrite);
91 auto local_colors = Kokkos::subview(colors_mv, Kokkos::ALL(), 0);
93 TEUCHOS_TEST_FOR_EXCEPTION(
94 local_colors.extent(0) != list_of_colors_tmp.extent(0),
95 std::logic_error,
"Incorrect length of color list!");
97 for (
size_t i = 0; i < local_colors.extent(0); ++i) {
98 local_colors(i) = list_of_colors_tmp(i);
102 using Import_t =
Tpetra::Import<
typename matrix_t::local_ordinal_type,
103 typename matrix_t::global_ordinal_type,
104 typename matrix_t::node_type>;
107 Import_t importer(matrix->getRowMap(), matrix->getColMap());
109 colorVecGlobal_.doImport(colorVecLocal_, importer, Tpetra::INSERT);
113 colorVecGlobal_.getLocalViewHost(Tpetra::Access::ReadOnly);
114 auto local_colors = Kokkos::subview(colors_mv, Kokkos::ALL(), 0);
115 const auto num_cols = this->matrix->getLocalNumCols();
117 TEUCHOS_TEST_FOR_EXCEPTION(local_colors.extent(0) != num_cols,
119 "Incorrect length of color list!");
122 list_of_colors_host = Kokkos::create_mirror_view(list_of_colors);
124 Kokkos::deep_copy(list_of_colors_host, local_colors);
125 Kokkos::deep_copy(list_of_colors, list_of_colors_host);
130 const Teuchos::RCP<matrix_t> matrix;
131 const Teuchos::RCP<const graph_t> graph;
140 template <
typename SC,
typename LO,
typename GO,
typename NO>
143 typedef Tpetra::BlockCrsMatrix<SC, LO, GO, NO>
matrix_t;
144 typedef typename matrix_t::crs_graph_type
graph_t;
145 typedef typename matrix_t::node_type
node_t;
152 : matrix(matrix_), graph(Teuchos::rcp(&(matrix->getCrsGraph()), false)) {}
161 using point_matrix_t = Tpetra::CrsMatrix<SC, LO, GO, NO>;
162 Teuchos::RCP<point_matrix_t> point_matrix =
163 Teuchos::rcp(
new point_matrix_t(graph));
164 point_matrix->setAllToScalar(1.0);
165 point_matrix->fillComplete();
168 list_of_colors_host, list_of_colors);
172 const Teuchos::RCP<matrix_t> matrix;
173 const Teuchos::RCP<const graph_t> graph;
Tpetra::BlockCrsMatrix< SC, LO, GO, NO > matrix_t
typename node_t::device_type device_t
void computeColoring(Teuchos::ParameterList &coloring_params, int &num_colors, list_of_colors_host_t &list_of_colors_host, list_of_colors_t &list_of_colors)
list_of_colors_t::HostMirror list_of_colors_host_t
node_t::device_type device_t
ColoringProblem sets up coloring problems for the user.
Defines the ColoringProblem class.
matrix_t::node_type node_t
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
void solve(bool updateInputData=true)
Direct the problem to create a solution.
Tpetra::Import< z2TestLO, z2TestGO > Import
ColoringSolution< Adapter > * getSolution()
Get the solution to the problem.
Teuchos::RCP< const typename Tpetra::CrsMatrix< SC, LO, GO, NO >::crs_graph_type > get_graph(const Teuchos::RCP< Tpetra::CrsMatrix< SC, LO, GO, NO > > &matrix)
matrix_t::crs_graph_type graph_t
void computeColoring(Teuchos::ParameterList &coloring_params, int &num_colors, list_of_colors_host_t &list_of_colors_host, list_of_colors_t &list_of_colors)
typename Tpetra::Vector< SC, LO, GO, node_t > vector_t
typename matrix_t::crs_graph_type graph_t
Defines the XpetraCrsMatrixAdapter class.
typename matrix_t::node_type node_t
Kokkos::View< int *, device_t > list_of_colors_t
Zoltan2CrsColorer(const Teuchos::RCP< matrix_t > &matrix_)
Kokkos::View< int *, device_t > list_of_colors_t
typename matrix_t::local_ordinal_type LO
typename matrix_t::global_ordinal_type GO
Defines the ColoringSolution class.
typename list_of_colors_t::HostMirror list_of_colors_host_t
typename matrix_t::scalar_type SC
Zoltan2CrsColorer(const Teuchos::RCP< matrix_t > &matrix_)