80 const ParameterList& pL = GetParameterList();
81 RCP<const Matrix> A = Get<RCP<Matrix> >(currentLevel,
"A");
83 RCP<const LWGraph> graph;
84 bool use_color_graph = pL.get<
bool>(
"aggregation: coloring: use color graph");
86 graph = Get<RCP<LWGraph> >(currentLevel,
"Coloring Graph");
88 graph = Get<RCP<LWGraph> >(currentLevel,
"Graph");
93 ArrayRCP<LO> myColors;
96 RCP<LocalOrdinalVector> fc_splitting;
97 std::string coloringAlgo = pL.get<std::string>(
"aggregation: coloring algorithm");
100#ifdef HAVE_MUELU_ZOLTAN2
101 int numProcs = A->getRowMap()->getComm()->getSize();
102 if (coloringAlgo !=
"file" && numProcs > 1 && graph->GetDomainMap()->lib() == Xpetra::UseTpetra)
103 coloringAlgo =
"Zoltan2";
109 int rank = graph->GetDomainMap()->getComm()->getRank();
111 printf(
"[%d,%d] graph local size = %dx%d\n", rank, currentLevel.
GetLevelID(), (
int)graph->GetDomainMap()->getLocalNumElements(), (
int)graph->GetImportMap()->getLocalNumElements());
113 std::ofstream ofs(std::string(
"m_dropped_graph_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
"_") + std::to_string(rank) + std::string(
".dat"), std::ofstream::out);
114 RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(ofs));
115 graph->print(*fancy,
Debug);
118 A->getRowMap()->getComm()->barrier();
124 if (coloringAlgo !=
"file" && graph->GetDomainMap()->lib() == Xpetra::UseEpetra)
125 coloringAlgo =
"MIS";
127 if (coloringAlgo ==
"file") {
130 std::string map_file = std::string(
"map_fcsplitting_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
".m");
131 std::string color_file = std::string(
"fcsplitting_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
".m");
133 FILE* mapfile = fopen(map_file.c_str(),
"r");
134 using real_type =
typename Teuchos::ScalarTraits<SC>::magnitudeType;
135 using RealValuedMultiVector =
typename Xpetra::MultiVector<real_type, LO, GO, NO>;
136 RCP<RealValuedMultiVector> mv;
138 GetOStream(
Statistics1) <<
"Reading FC splitting from " << color_file <<
", using map file " << map_file <<
". On rank " << A->getRowMap()->getComm()->getRank() <<
" local size is " << A->getRowMap()->getLocalNumElements() << std::endl;
141 RCP<const Map> colorMap = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ReadMap(map_file, A->getRowMap()->lib(), A->getRowMap()->getComm());
142 TEUCHOS_TEST_FOR_EXCEPTION(!colorMap->isCompatible(*A->getRowMap()), std::invalid_argument,
"Coloring on disk has incompatible map with A");
144 mv = Xpetra::IO<real_type, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(color_file, colorMap);
147 mv = Xpetra::IO<real_type, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(color_file, A->getRowMap());
149 TEUCHOS_TEST_FOR_EXCEPTION(mv.is_null(), std::invalid_argument,
"Coloring on disk cannot be read");
150 fc_splitting = LocalOrdinalVectorFactory::Build(A->getRowMap());
151 TEUCHOS_TEST_FOR_EXCEPTION(mv->getLocalLength() != fc_splitting->getLocalLength(), std::invalid_argument,
"Coloring map mismatch");
154 auto boundaryNodes = graph->GetBoundaryNodeMap();
155 ArrayRCP<const real_type> mv_data = mv->getData(0);
156 ArrayRCP<LO> fc_data = fc_splitting->getDataNonConst(0);
157 for (LO i = 0; i < (LO)fc_data.size(); i++) {
158 if (boundaryNodes[i])
159 fc_data[i] = DIRICHLET_PT;
161 fc_data[i] = Teuchos::as<LO>(mv_data[i]);
164#ifdef HAVE_MUELU_ZOLTAN2
165 else if (coloringAlgo.find(
"Zoltan2") != std::string::npos && graph->GetDomainMap()->lib() == Xpetra::UseTpetra) {
167 DoDistributedGraphColoring(graph, myColors, numColors);
170 else if (coloringAlgo ==
"MIS" || graph->GetDomainMap()->lib() == Xpetra::UseTpetra) {
172 TEUCHOS_TEST_FOR_EXCEPTION(A->getRowMap()->getComm()->getSize() != 1, std::invalid_argument,
"MIS on more than 1 MPI rank is not supported");
173 DoMISNaive(*graph, myColors, numColors);
176 TEUCHOS_TEST_FOR_EXCEPTION(A->getRowMap()->getComm()->getSize() != 1, std::invalid_argument,
"KokkosKernels graph coloring on more than 1 MPI rank is not supported");
177 DoGraphColoring(*graph, myColors, numColors);
182 int rank = graph->GetDomainMap()->getComm()->getRank();
184 printf(
"[%d,%d] num colors %d\n", rank, currentLevel.
GetLevelID(), numColors);
186 std::ofstream ofs(std::string(
"m_colors_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
"_") + std::to_string(rank) + std::string(
".dat"), std::ofstream::out);
187 RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(ofs));
188 *fancy << myColors();
191 A->getRowMap()->getComm()->barrier();
199 LO num_c_points = 0, num_d_points = 0, num_f_points = 0;
200 if (fc_splitting.is_null()) {
202 auto boundaryNodes = graph->GetBoundaryNodeMap();
203 fc_splitting = LocalOrdinalVectorFactory::Build(A->getRowMap());
204 ArrayRCP<LO> myPointType = fc_splitting->getDataNonConst(0);
205 for (LO i = 0; i < (LO)myColors.size(); i++) {
206 if (boundaryNodes[i]) {
207 myPointType[i] = DIRICHLET_PT;
209 }
else if ((LO)myColors[i] == 1) {
210 myPointType[i] = C_PT;
213 myPointType[i] = F_PT;
215 num_f_points = (LO)myColors.size() - num_d_points - num_c_points;
218 ArrayRCP<LO> myPointType = fc_splitting->getDataNonConst(0);
220 for (LO i = 0; i < (LO)myPointType.size(); i++) {
221 if (myPointType[i] == DIRICHLET_PT)
223 else if (myPointType[i] == C_PT)
226 num_f_points = (LO)myPointType.size() - num_d_points - num_c_points;
232 GO l_counts[] = {(GO)num_c_points, (GO)num_f_points, (GO)num_d_points};
235 RCP<const Teuchos::Comm<int> > comm = A->getRowMap()->getComm();
236 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 3, l_counts, g_counts);
237 GetOStream(
Statistics1) <<
"ClassicalMapFactory(" << coloringAlgo <<
"): C/F/D = " << g_counts[0] <<
"/" << g_counts[1] <<
"/" << g_counts[2] << std::endl;
241 RCP<const Map> coarseMap;
244 GenerateCoarseMap(*A->getRowMap(), num_c_points, coarseMap);
247 Set(currentLevel,
"FC Splitting", fc_splitting);
248 Set(currentLevel,
"CoarseMap", coarseMap);
273 const ParameterList& pL = GetParameterList();
275 using KernelHandle = KokkosKernels::Experimental::
276 KokkosKernelsHandle<
typename graph_t::row_map_type::value_type,
277 typename graph_t::entries_type::value_type,
278 typename graph_t::entries_type::value_type,
279 typename graph_t::device_type::execution_space,
280 typename graph_t::device_type::memory_space,
281 typename graph_t::device_type::memory_space>;
285 kh.create_graph_coloring_handle();
288 auto coloringHandle = kh.get_graph_coloring_handle();
291 if (pL.get<
bool>(
"aggregation: deterministic") ==
true) {
292 coloringHandle->set_algorithm(KokkosGraph::COLORING_SERIAL);
294 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"serial") {
295 coloringHandle->set_algorithm(KokkosGraph::COLORING_SERIAL);
297 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based") {
298 coloringHandle->set_algorithm(KokkosGraph::COLORING_VB);
300 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based bit array") {
301 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBBIT);
303 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based color set") {
304 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBCS);
306 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based deterministic") {
307 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBD);
308 if (IsPrint(
Statistics1)) GetOStream(
Statistics1) <<
" algorithm: vertex based deterministic" << std::endl;
309 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based deterministic bit array") {
310 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBDBIT);
311 if (IsPrint(
Statistics1)) GetOStream(
Statistics1) <<
" algorithm: vertex based deterministic bit array" << std::endl;
312 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"edge based") {
313 coloringHandle->set_algorithm(KokkosGraph::COLORING_EB);
316 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
"Unrecognized distance 1 coloring algorithm");
322 auto graphLW =
dynamic_cast<const LWGraph*
>(&graph);
323 TEUCHOS_TEST_FOR_EXCEPTION(!graphLW, std::invalid_argument,
"Graph is not a LWGraph object");
336 auto rowptrs = graphLW->getRowPtrs();
337 auto entries = graphLW->getEntries();
338 KokkosGraph::Experimental::graph_color(&kh,
347 auto myColors_d = coloringHandle->get_vertex_colors();
348 numColors =
static_cast<LO
>(coloringHandle->get_num_colors());
351 auto myColors_h = Kokkos::create_mirror_view(myColors_d);
352 myColors_out.resize(myColors_h.size());
353 Kokkos::View<LO*, Kokkos::LayoutLeft, Kokkos::HostSpace> myColors_v(&myColors_out[0], myColors_h.size());
354 Kokkos::deep_copy(myColors_v, myColors_h);
357 kh.destroy_graph_coloring_handle();