31 Monitor m(*
this,
"BuildAggregatesNonKokkos");
32 bool matchMLbehavior = params.get<
bool>(
"aggregation: match ML phase2b");
35 const int myRank = graph.
GetComm()->getRank();
37 ArrayRCP<LO> vertex2AggId = aggregates.
GetVertex2AggId()->getDataNonConst(0);
38 ArrayRCP<LO> procWinner = aggregates.
GetProcWinner()->getDataNonConst(0);
42 const LO defaultConnectWeight = 100;
43 const LO penaltyConnectWeight = 10;
45 std::vector<LO> aggWeight(numLocalAggregates, 0);
46 std::vector<LO> connectWeight(numRows, defaultConnectWeight);
47 std::vector<LO> aggPenalties(numRows, 0);
55 for (
int k = 0; k < 2; k++) {
56 for (LO i = 0; i < numRows; i++) {
57 if (aggStat[i] !=
READY)
62 for (
int j = 0; j < neighOfINode.length; j++) {
63 LO neigh = neighOfINode(j);
67 aggWeight[vertex2AggId[neigh]] += connectWeight[neigh];
70 int bestScore = -100000;
74 for (
int j = 0; j < neighOfINode.length; j++) {
75 LO neigh = neighOfINode(j);
76 int aggId = vertex2AggId[neigh];
80 int score = aggWeight[aggId] - aggPenalties[aggId];
82 if (score > bestScore) {
85 bestConnect = connectWeight[neigh];
87 }
else if (aggId == bestAggId && connectWeight[neigh] > bestConnect) {
88 bestConnect = connectWeight[neigh];
98 vertex2AggId[i] = bestAggId;
99 procWinner[i] = myRank;
101 numNonAggregatedNodes--;
103 aggPenalties[bestAggId]++;
104 connectWeight[i] = bestConnect - penaltyConnectWeight;
257 LO& numNonAggregatedNodes)
const {
261 bool matchMLbehavior = params.get<
bool>(
"aggregation: match ML phase2b");
264 const int myRank = graph.
GetComm()->getRank();
266 auto vertex2AggId = aggregates.
GetVertex2AggId()->getLocalViewDevice(Tpetra::Access::ReadWrite);
267 auto procWinner = aggregates.
GetProcWinner()->getLocalViewDevice(Tpetra::Access::ReadWrite);
272 const LO defaultConnectWeight = 100;
273 const LO penaltyConnectWeight = 10;
275 Kokkos::View<LO*, device_type> connectWeight(Kokkos::ViewAllocateWithoutInitializing(
"connectWeight"), numRows);
276 Kokkos::View<LO*, device_type> aggPenalties(
"aggPenalties", numLocalAggregates);
277 Kokkos::View<LO*, device_type> aggPenaltyUpdates;
279 aggPenaltyUpdates = Kokkos::View<LO*, device_type>(
"aggPenaltyUpdates", numLocalAggregates);
281 Kokkos::deep_copy(connectWeight, defaultConnectWeight);
291 int maxNodesPerAggregate = params.get<
int>(
"aggregation: max agg size");
292 if (maxNodesPerAggregate == std::numeric_limits<int>::max()) {
296 Kokkos::View<LO*, Kokkos::HostSpace> numUnaggregatedNodesPerColor(
"numUnaggregatedNodesPerColor", numColors);
297 for (
int iter = 0; iter < maxIters; ++iter) {
300 Kokkos::parallel_reduce(
301 "Aggregation Phase 2b: count unaggregated nodes per color",
302 Kokkos::RangePolicy<execution_space>(0, numRows),
304 numUnaggregatedNodesPerColor);
306 for (LO color = 1; color <= numColors; ++color) {
307 if (numUnaggregatedNodesPerColor(color - 1) == 0)
312 LO numAggregated = 0;
314 if constexpr (deterministic) {
315 if (matchMLbehavior) {
316 auto functor =
ExpansionFunctor<decltype(aggStat), decltype(procWinner), decltype(vertex2AggId), decltype(colors), decltype(graph), decltype(aggPenalties), LO, true, true>(aggStat, procWinner, vertex2AggId, colors, graph, aggPenalties, aggPenaltyUpdates, connectWeight, penaltyConnectWeight, color, myRank);
318 Kokkos::parallel_reduce(
"Aggregation Phase 2b: aggregates expansion",
319 Kokkos::RangePolicy<execution_space>(0, numRows),
323 auto functor =
ExpansionFunctor<decltype(aggStat), decltype(procWinner), decltype(vertex2AggId), decltype(colors), decltype(graph), decltype(aggPenalties), LO, true, false>(aggStat, procWinner, vertex2AggId, colors, graph, aggPenalties, aggPenaltyUpdates, connectWeight, penaltyConnectWeight, color, myRank);
325 Kokkos::parallel_reduce(
"Aggregation Phase 2b: aggregates expansion",
326 Kokkos::RangePolicy<execution_space>(0, numRows),
331 if (matchMLbehavior) {
332 auto functor =
ExpansionFunctor<decltype(aggStat), decltype(procWinner), decltype(vertex2AggId), decltype(colors), decltype(graph), decltype(aggPenalties), LO, false, true>(aggStat, procWinner, vertex2AggId, colors, graph, aggPenalties, connectWeight, penaltyConnectWeight, color, myRank);
334 Kokkos::parallel_reduce(
"Aggregation Phase 2b: aggregates expansion",
335 Kokkos::RangePolicy<execution_space>(0, numRows),
339 auto functor =
ExpansionFunctor<decltype(aggStat), decltype(procWinner), decltype(vertex2AggId), decltype(colors), decltype(graph), decltype(aggPenalties), LO, false, false>(aggStat, procWinner, vertex2AggId, colors, graph, aggPenalties, connectWeight, penaltyConnectWeight, color, myRank);
341 Kokkos::parallel_reduce(
"Aggregation Phase 2b: aggregates expansion",
342 Kokkos::RangePolicy<execution_space>(0, numRows),
348 numNonAggregatedNodes -= numAggregated;
350 if (numNonAggregatedNodes == 0)
353 if constexpr (deterministic) {
354 Kokkos::parallel_for(
355 "Aggregation Phase 2b: updating agg penalties",
356 Kokkos::RangePolicy<execution_space>(0, numLocalAggregates),
357 KOKKOS_LAMBDA(
const LO agg) {
358 aggPenalties(agg) += aggPenaltyUpdates(agg);
359 aggPenaltyUpdates(agg) = 0;
ExpansionFunctor(AggStatType &aggStat_, ProcWinnerType &procWinner_, Vertex2AggType &vertex2AggId_, ColorsType &colors_, LocalGraphType &lclLWGraph_, AggPenaltyType &aggPenalties_, AggPenaltyType &connectWeight_, LO penaltyConnectWeight_, LO color_, LO rank_)
ExpansionFunctor(AggStatType &aggStat_, ProcWinnerType &procWinner_, Vertex2AggType &vertex2AggId_, ColorsType &colors_, LocalGraphType &lclLWGraph_, AggPenaltyType &aggPenalties_, AggPenaltyType &aggPenaltyUpdates_, AggPenaltyType &connectWeight_, LO penaltyConnectWeight_, LO color_, LO rank_)