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();
123 if (coloringAlgo ==
"file") {
126 std::string map_file = std::string(
"map_fcsplitting_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
".m");
127 std::string color_file = std::string(
"fcsplitting_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
".m");
129 FILE* mapfile = fopen(map_file.c_str(),
"r");
130 using real_type =
typename Teuchos::ScalarTraits<SC>::magnitudeType;
131 using RealValuedMultiVector =
typename Xpetra::MultiVector<real_type, LO, GO, NO>;
132 RCP<RealValuedMultiVector> mv;
134 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;
137 RCP<const Map> colorMap = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ReadMap(map_file, A->getRowMap()->lib(), A->getRowMap()->getComm());
138 TEUCHOS_TEST_FOR_EXCEPTION(!colorMap->isCompatible(*A->getRowMap()), std::invalid_argument,
"Coloring on disk has incompatible map with A");
140 mv = Xpetra::IO<real_type, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(color_file, colorMap);
143 mv = Xpetra::IO<real_type, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(color_file, A->getRowMap());
145 TEUCHOS_TEST_FOR_EXCEPTION(mv.is_null(), std::invalid_argument,
"Coloring on disk cannot be read");
146 fc_splitting = LocalOrdinalVectorFactory::Build(A->getRowMap());
147 TEUCHOS_TEST_FOR_EXCEPTION(mv->getLocalLength() != fc_splitting->getLocalLength(), std::invalid_argument,
"Coloring map mismatch");
150 auto boundaryNodes = graph->GetBoundaryNodeMap();
151 ArrayRCP<const real_type> mv_data = mv->getData(0);
152 ArrayRCP<LO> fc_data = fc_splitting->getDataNonConst(0);
153 for (LO i = 0; i < (LO)fc_data.size(); i++) {
154 if (boundaryNodes[i])
155 fc_data[i] = DIRICHLET_PT;
157 fc_data[i] = Teuchos::as<LO>(mv_data[i]);
160#ifdef HAVE_MUELU_ZOLTAN2
161 else if (coloringAlgo.find(
"Zoltan2") != std::string::npos && graph->GetDomainMap()->lib() == Xpetra::UseTpetra) {
163 DoDistributedGraphColoring(graph, myColors, numColors);
166 else if (coloringAlgo ==
"MIS" || graph->GetDomainMap()->lib() == Xpetra::UseTpetra) {
168 TEUCHOS_TEST_FOR_EXCEPTION(A->getRowMap()->getComm()->getSize() != 1, std::invalid_argument,
"MIS on more than 1 MPI rank is not supported");
169 DoMISNaive(*graph, myColors, numColors);
172 TEUCHOS_TEST_FOR_EXCEPTION(A->getRowMap()->getComm()->getSize() != 1, std::invalid_argument,
"KokkosKernels graph coloring on more than 1 MPI rank is not supported");
173 DoGraphColoring(*graph, myColors, numColors);
178 int rank = graph->GetDomainMap()->getComm()->getRank();
180 printf(
"[%d,%d] num colors %d\n", rank, currentLevel.
GetLevelID(), numColors);
182 std::ofstream ofs(std::string(
"m_colors_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
"_") + std::to_string(rank) + std::string(
".dat"), std::ofstream::out);
183 RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(ofs));
184 *fancy << myColors();
187 A->getRowMap()->getComm()->barrier();
195 LO num_c_points = 0, num_d_points = 0, num_f_points = 0;
196 if (fc_splitting.is_null()) {
198 auto boundaryNodes = graph->GetBoundaryNodeMap();
199 fc_splitting = LocalOrdinalVectorFactory::Build(A->getRowMap());
200 ArrayRCP<LO> myPointType = fc_splitting->getDataNonConst(0);
201 for (LO i = 0; i < (LO)myColors.size(); i++) {
202 if (boundaryNodes[i]) {
203 myPointType[i] = DIRICHLET_PT;
205 }
else if ((LO)myColors[i] == 1) {
206 myPointType[i] = C_PT;
209 myPointType[i] = F_PT;
211 num_f_points = (LO)myColors.size() - num_d_points - num_c_points;
214 ArrayRCP<LO> myPointType = fc_splitting->getDataNonConst(0);
216 for (LO i = 0; i < (LO)myPointType.size(); i++) {
217 if (myPointType[i] == DIRICHLET_PT)
219 else if (myPointType[i] == C_PT)
222 num_f_points = (LO)myPointType.size() - num_d_points - num_c_points;
228 GO l_counts[] = {(GO)num_c_points, (GO)num_f_points, (GO)num_d_points};
231 RCP<const Teuchos::Comm<int> > comm = A->getRowMap()->getComm();
232 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 3, l_counts, g_counts);
233 GetOStream(
Statistics1) <<
"ClassicalMapFactory(" << coloringAlgo <<
"): C/F/D = " << g_counts[0] <<
"/" << g_counts[1] <<
"/" << g_counts[2] << std::endl;
237 RCP<const Map> coarseMap;
240 GenerateCoarseMap(*A->getRowMap(), num_c_points, coarseMap);
243 Set(currentLevel,
"FC Splitting", fc_splitting);
244 Set(currentLevel,
"CoarseMap", coarseMap);
269 const ParameterList& pL = GetParameterList();
271 using KernelHandle = KokkosKernels::Experimental::
272 KokkosKernelsHandle<
typename graph_t::row_map_type::value_type,
273 typename graph_t::entries_type::value_type,
274 typename graph_t::entries_type::value_type,
275 typename graph_t::device_type::execution_space,
276 typename graph_t::device_type::memory_space,
277 typename graph_t::device_type::memory_space>;
281 kh.create_graph_coloring_handle();
284 auto coloringHandle = kh.get_graph_coloring_handle();
287 if (pL.get<
bool>(
"aggregation: deterministic") ==
true) {
288 coloringHandle->set_algorithm(KokkosGraph::COLORING_SERIAL);
290 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"serial") {
291 coloringHandle->set_algorithm(KokkosGraph::COLORING_SERIAL);
293 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based") {
294 coloringHandle->set_algorithm(KokkosGraph::COLORING_VB);
296 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based bit array") {
297 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBBIT);
299 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based color set") {
300 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBCS);
302 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based deterministic") {
303 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBD);
304 if (IsPrint(
Statistics1)) GetOStream(
Statistics1) <<
" algorithm: vertex based deterministic" << std::endl;
305 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based deterministic bit array") {
306 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBDBIT);
307 if (IsPrint(
Statistics1)) GetOStream(
Statistics1) <<
" algorithm: vertex based deterministic bit array" << std::endl;
308 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"edge based") {
309 coloringHandle->set_algorithm(KokkosGraph::COLORING_EB);
312 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
"Unrecognized distance 1 coloring algorithm");
318 auto graphLW =
dynamic_cast<const LWGraph*
>(&graph);
319 TEUCHOS_TEST_FOR_EXCEPTION(!graphLW, std::invalid_argument,
"Graph is not a LWGraph object");
332 auto rowptrs = graphLW->getRowPtrs();
333 auto entries = graphLW->getEntries();
334 KokkosGraph::Experimental::graph_color(&kh,
343 auto myColors_d = coloringHandle->get_vertex_colors();
344 numColors =
static_cast<LO
>(coloringHandle->get_num_colors());
347 auto myColors_h = Kokkos::create_mirror_view(myColors_d);
348 myColors_out.resize(myColors_h.size());
349 Kokkos::View<LO*, Kokkos::LayoutLeft, Kokkos::HostSpace> myColors_v(&myColors_out[0], myColors_h.size());
350 Kokkos::deep_copy(myColors_v, myColors_h);
353 kh.destroy_graph_coloring_handle();