46 #ifndef MUELU_AGGREGATIONPHASE2BALGORITHM_KOKKOS_DEF_HPP
47 #define MUELU_AGGREGATIONPHASE2BALGORITHM_KOKKOS_DEF_HPP
49 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
51 #include <Teuchos_Comm.hpp>
52 #include <Teuchos_CommHelpers.hpp>
58 #include "MueLu_Aggregates_kokkos.hpp"
60 #include "MueLu_LWGraph_kokkos.hpp"
67 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 void AggregationPhase2bAlgorithm_kokkos<LocalOrdinal, GlobalOrdinal, Node>::BuildAggregates(
const ParameterList& ,
const LWGraph_kokkos& graph, Aggregates_kokkos& aggregates, std::vector<unsigned>& aggStat,
LO& numNonAggregatedNodes)
const {
69 Monitor m(*
this,
"BuildAggregates");
71 const LO numRows = graph.GetNodeNumVertices();
72 const int myRank = graph.GetComm()->getRank();
74 ArrayRCP<LO> vertex2AggId = aggregates.GetVertex2AggId()->getDataNonConst(0);
75 ArrayRCP<LO> procWinner = aggregates.GetProcWinner() ->getDataNonConst(0);
77 LO numLocalAggregates = aggregates.GetNumAggregates();
79 const int defaultConnectWeight = 100;
80 const int penaltyConnectWeight = 10;
82 std::vector<int> aggWeight (numLocalAggregates, 0);
83 std::vector<int> connectWeight(numRows, defaultConnectWeight);
84 std::vector<int> aggPenalties (numRows, 0);
92 for (
int k = 0; k < 2; k++) {
93 for (
LO i = 0; i < numRows; i++) {
94 if (aggStat[i] !=
READY)
97 auto neighOfINode = graph.getNeighborVertices(i);
99 for (
int j = 0; j < as<int>(neighOfINode.length); j++) {
100 LO neigh = neighOfINode(j);
103 if (graph.isLocalNeighborVertex(neigh) && aggStat[neigh] ==
AGGREGATED)
104 aggWeight[vertex2AggId[neigh]] += connectWeight[neigh];
107 int bestScore = -100000;
109 int bestConnect = -1;
111 for (
int j = 0; j < as<int>(neighOfINode.length); j++) {
112 LO neigh = neighOfINode(j);
114 if (graph.isLocalNeighborVertex(neigh) && aggStat[neigh] ==
AGGREGATED) {
115 int aggId = vertex2AggId[neigh];
116 int score = aggWeight[aggId] - aggPenalties[aggId];
118 if (score > bestScore) {
121 bestConnect = connectWeight[neigh];
123 }
else if (aggId == bestAggId && connectWeight[neigh] > bestConnect) {
124 bestConnect = connectWeight[neigh];
128 aggWeight[aggId] = 0;
132 if (bestScore >= 0) {
134 vertex2AggId[i] = bestAggId;
135 procWinner [i] = myRank;
137 numNonAggregatedNodes--;
139 aggPenalties[bestAggId]++;
140 connectWeight[i] = bestConnect - penaltyConnectWeight;
148 #endif // HAVE_MUELU_KOKKOS_REFACTOR
149 #endif // MUELU_AGGREGATIONPHASE2BALGORITHM_KOKKOS_DEF_HPP