78 const ParameterList& pL = GetParameterList();
79 RCP<const Matrix> A = Get<RCP<Matrix> >(currentLevel,
"A");
81 RCP<const LWGraph> graph;
82 bool use_color_graph = pL.get<
bool>(
"aggregation: coloring: use color graph");
84 graph = Get<RCP<LWGraph> >(currentLevel,
"Coloring Graph");
86 graph = Get<RCP<LWGraph> >(currentLevel,
"Graph");
91 ArrayRCP<LO> myColors;
94 RCP<LocalOrdinalVector> fc_splitting;
95 std::string coloringAlgo = pL.get<std::string>(
"aggregation: coloring algorithm");
98#ifdef HAVE_MUELU_ZOLTAN2
99 int numProcs = A->getRowMap()->getComm()->getSize();
100 if (coloringAlgo !=
"file" && numProcs > 1 && graph->GetDomainMap()->lib() == Xpetra::UseTpetra)
101 coloringAlgo =
"Zoltan2";
107 int rank = graph->GetDomainMap()->getComm()->getRank();
109 printf(
"[%d,%d] graph local size = %dx%d\n", rank, currentLevel.
GetLevelID(), (
int)graph->GetDomainMap()->getLocalNumElements(), (
int)graph->GetImportMap()->getLocalNumElements());
111 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);
112 RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(ofs));
113 graph->print(*fancy,
Debug);
116 A->getRowMap()->getComm()->barrier();
121 if (coloringAlgo ==
"file") {
124 std::string map_file = std::string(
"map_fcsplitting_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
".m");
125 std::string color_file = std::string(
"fcsplitting_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
".m");
127 FILE* mapfile = fopen(map_file.c_str(),
"r");
128 using real_type =
typename Teuchos::ScalarTraits<SC>::magnitudeType;
129 using RealValuedMultiVector =
typename Xpetra::MultiVector<real_type, LO, GO, NO>;
130 RCP<RealValuedMultiVector> mv;
132 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;
135 RCP<const Map> colorMap = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::ReadMap(map_file, A->getRowMap()->lib(), A->getRowMap()->getComm());
136 TEUCHOS_TEST_FOR_EXCEPTION(!colorMap->isCompatible(*A->getRowMap()), std::invalid_argument,
"Coloring on disk has incompatible map with A");
138 mv = Xpetra::IO<real_type, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(color_file, colorMap);
141 mv = Xpetra::IO<real_type, LocalOrdinal, GlobalOrdinal, Node>::ReadMultiVector(color_file, A->getRowMap());
143 TEUCHOS_TEST_FOR_EXCEPTION(mv.is_null(), std::invalid_argument,
"Coloring on disk cannot be read");
144 fc_splitting = LocalOrdinalVectorFactory::Build(A->getRowMap());
145 TEUCHOS_TEST_FOR_EXCEPTION(mv->getLocalLength() != fc_splitting->getLocalLength(), std::invalid_argument,
"Coloring map mismatch");
148 auto boundaryNodes = graph->GetBoundaryNodeMap();
149 ArrayRCP<const real_type> mv_data = mv->getData(0);
150 ArrayRCP<LO> fc_data = fc_splitting->getDataNonConst(0);
151 for (LO i = 0; i < (LO)fc_data.size(); i++) {
152 if (boundaryNodes[i])
153 fc_data[i] = DIRICHLET_PT;
155 fc_data[i] = Teuchos::as<LO>(mv_data[i]);
158#ifdef HAVE_MUELU_ZOLTAN2
159 else if (coloringAlgo.find(
"Zoltan2") != std::string::npos && graph->GetDomainMap()->lib() == Xpetra::UseTpetra) {
161 DoDistributedGraphColoring(graph, myColors, numColors);
164 else if (coloringAlgo ==
"MIS" || graph->GetDomainMap()->lib() == Xpetra::UseTpetra) {
166 TEUCHOS_TEST_FOR_EXCEPTION(A->getRowMap()->getComm()->getSize() != 1, std::invalid_argument,
"MIS on more than 1 MPI rank is not supported");
167 DoMISNaive(*graph, myColors, numColors);
170 TEUCHOS_TEST_FOR_EXCEPTION(A->getRowMap()->getComm()->getSize() != 1, std::invalid_argument,
"KokkosKernels graph coloring on more than 1 MPI rank is not supported");
171 DoGraphColoring(*graph, myColors, numColors);
176 int rank = graph->GetDomainMap()->getComm()->getRank();
178 printf(
"[%d,%d] num colors %d\n", rank, currentLevel.
GetLevelID(), numColors);
180 std::ofstream ofs(std::string(
"m_colors_") + std::to_string(currentLevel.
GetLevelID()) + std::string(
"_") + std::to_string(rank) + std::string(
".dat"), std::ofstream::out);
181 RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(ofs));
182 *fancy << myColors();
185 A->getRowMap()->getComm()->barrier();
193 LO num_c_points = 0, num_d_points = 0, num_f_points = 0;
194 if (fc_splitting.is_null()) {
196 auto boundaryNodes = graph->GetBoundaryNodeMap();
197 fc_splitting = LocalOrdinalVectorFactory::Build(A->getRowMap());
198 ArrayRCP<LO> myPointType = fc_splitting->getDataNonConst(0);
199 for (LO i = 0; i < (LO)myColors.size(); i++) {
200 if (boundaryNodes[i]) {
201 myPointType[i] = DIRICHLET_PT;
203 }
else if ((LO)myColors[i] == 1) {
204 myPointType[i] = C_PT;
207 myPointType[i] = F_PT;
209 num_f_points = (LO)myColors.size() - num_d_points - num_c_points;
212 ArrayRCP<LO> myPointType = fc_splitting->getDataNonConst(0);
214 for (LO i = 0; i < (LO)myPointType.size(); i++) {
215 if (myPointType[i] == DIRICHLET_PT)
217 else if (myPointType[i] == C_PT)
220 num_f_points = (LO)myPointType.size() - num_d_points - num_c_points;
226 GO l_counts[] = {(GO)num_c_points, (GO)num_f_points, (GO)num_d_points};
229 RCP<const Teuchos::Comm<int> > comm = A->getRowMap()->getComm();
230 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 3, l_counts, g_counts);
231 GetOStream(
Statistics1) <<
"ClassicalMapFactory(" << coloringAlgo <<
"): C/F/D = " << g_counts[0] <<
"/" << g_counts[1] <<
"/" << g_counts[2] << std::endl;
235 RCP<const Map> coarseMap;
238 GenerateCoarseMap(*A->getRowMap(), num_c_points, coarseMap);
241 Set(currentLevel,
"FC Splitting", fc_splitting);
242 Set(currentLevel,
"CoarseMap", coarseMap);
267 const ParameterList& pL = GetParameterList();
269 using KernelHandle = KokkosKernels::Experimental::
270 KokkosKernelsHandle<
typename graph_t::row_map_type::value_type,
271 typename graph_t::entries_type::value_type,
272 typename graph_t::entries_type::value_type,
273 typename graph_t::device_type::execution_space,
274 typename graph_t::device_type::memory_space,
275 typename graph_t::device_type::memory_space>;
279 kh.create_graph_coloring_handle();
282 auto coloringHandle = kh.get_graph_coloring_handle();
285 if (pL.get<
bool>(
"aggregation: deterministic") ==
true) {
286 coloringHandle->set_algorithm(KokkosGraph::COLORING_SERIAL);
288 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"serial") {
289 coloringHandle->set_algorithm(KokkosGraph::COLORING_SERIAL);
291 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based") {
292 coloringHandle->set_algorithm(KokkosGraph::COLORING_VB);
294 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based bit array") {
295 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBBIT);
297 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based color set") {
298 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBCS);
300 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based deterministic") {
301 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBD);
302 if (IsPrint(
Statistics1)) GetOStream(
Statistics1) <<
" algorithm: vertex based deterministic" << std::endl;
303 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"vertex based deterministic bit array") {
304 coloringHandle->set_algorithm(KokkosGraph::COLORING_VBDBIT);
305 if (IsPrint(
Statistics1)) GetOStream(
Statistics1) <<
" algorithm: vertex based deterministic bit array" << std::endl;
306 }
else if (pL.get<std::string>(
"aggregation: coloring algorithm") ==
"edge based") {
307 coloringHandle->set_algorithm(KokkosGraph::COLORING_EB);
310 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
"Unrecognized distance 1 coloring algorithm");
316 auto graphLW =
dynamic_cast<const LWGraph*
>(&graph);
317 TEUCHOS_TEST_FOR_EXCEPTION(!graphLW, std::invalid_argument,
"Graph is not a LWGraph object");
330 auto rowptrs = graphLW->getRowPtrs();
331 auto entries = graphLW->getEntries();
332 KokkosGraph::Experimental::graph_color(&kh,
341 auto myColors_d = coloringHandle->get_vertex_colors();
342 numColors =
static_cast<LO
>(coloringHandle->get_num_colors());
345 auto myColors_h = Kokkos::create_mirror_view(myColors_d);
346 myColors_out.resize(myColors_h.size());
347 Kokkos::View<LO*, Kokkos::LayoutLeft, Kokkos::HostSpace> myColors_v(&myColors_out[0], myColors_h.size());
348 Kokkos::deep_copy(myColors_v, myColors_h);
351 kh.destroy_graph_coloring_handle();