88 Kokkos::View<unsigned*, typename LWGraph_kokkos::device_type>& aggStat,
89 LO& numNonAggregatedNodes)
const {
91 const LO numRows = graph.GetNodeNumVertices();
92 const int myRank = graph.GetComm()->getRank();
94 auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
95 auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
96 auto colors = aggregates.GetGraphColors();
97 const LO numColors = aggregates.GetGraphNumColors();
98 const LO numLocalAggregates = aggregates.GetNumAggregates();
100 auto lclLWGraph = graph.getLocalLWGraph();
102 const LO defaultConnectWeight = 100;
103 const LO penaltyConnectWeight = 10;
105 Kokkos::View<LO*, device_type> aggWeight (
"aggWeight", numLocalAggregates);
106 Kokkos::View<LO*, device_type> connectWeight(
"connectWeight", numRows);
107 Kokkos::View<LO*, device_type> aggPenalties (
"aggPenalties", numLocalAggregates);
109 Kokkos::deep_copy(connectWeight, defaultConnectWeight);
119 int maxNodesPerAggregate = params.get<
int>(
"aggregation: max agg size");
120 if(maxNodesPerAggregate == std::numeric_limits<int>::max()) {maxIters = 1;}
121 for (
int iter = 0; iter < maxIters; ++iter) {
122 for(LO color = 1; color <= numColors; ++color) {
123 Kokkos::deep_copy(aggWeight, 0);
127 LO numAggregated = 0;
128 Kokkos::parallel_reduce(
"Aggregation Phase 2b: aggregates expansion",
129 Kokkos::RangePolicy<execution_space>(0, numRows),
130 KOKKOS_LAMBDA (
const LO i, LO& tmpNumAggregated) {
131 if (aggStat(i) !=
READY || colors(i) != color)
134 auto neighOfINode = lclLWGraph.getNeighborVertices(i);
135 for (
int j = 0; j < neighOfINode.length; j++) {
136 LO neigh = neighOfINode(j);
140 if (lclLWGraph.isLocalNeighborVertex(neigh) &&
142 Kokkos::atomic_add(&aggWeight(vertex2AggId(neigh, 0)),
143 connectWeight(neigh));
146 int bestScore = -100000;
148 int bestConnect = -1;
150 for (
int j = 0; j < neighOfINode.length; j++) {
151 LO neigh = neighOfINode(j);
153 if (lclLWGraph.isLocalNeighborVertex(neigh) &&
155 auto aggId = vertex2AggId(neigh, 0);
156 int score = aggWeight(aggId) - aggPenalties(aggId);
158 if (score > bestScore) {
161 bestConnect = connectWeight(neigh);
163 }
else if (aggId == bestAggId &&
164 connectWeight(neigh) > bestConnect) {
165 bestConnect = connectWeight(neigh);
169 if (bestScore >= 0) {
171 vertex2AggId(i, 0) = bestAggId;
172 procWinner(i, 0) = myRank;
174 Kokkos::atomic_add(&aggPenalties(bestAggId), 1);
175 connectWeight(i) = bestConnect - penaltyConnectWeight;
179 numNonAggregatedNodes -= numAggregated;
192 Kokkos::View<unsigned*, typename LWGraph_kokkos::device_type>& aggStat,
193 LO& numNonAggregatedNodes)
const {
195 const LO numRows = graph.GetNodeNumVertices();
196 const int myRank = graph.GetComm()->getRank();
198 auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
199 auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
200 auto colors = aggregates.GetGraphColors();
201 const LO numColors = aggregates.GetGraphNumColors();
202 LO numLocalAggregates = aggregates.GetNumAggregates();
204 auto lclLWGraph = graph.getLocalLWGraph();
206 const int defaultConnectWeight = 100;
207 const int penaltyConnectWeight = 10;
209 Kokkos::View<int*, device_type> connectWeight (
"connectWeight", numRows);
210 Kokkos::View<int*, device_type> aggWeight (
"aggWeight", numLocalAggregates);
211 Kokkos::View<int*, device_type> aggPenaltyUpdates(
"aggPenaltyUpdates", numLocalAggregates);
212 Kokkos::View<int*, device_type> aggPenalties (
"aggPenalties", numLocalAggregates);
214 Kokkos::deep_copy(connectWeight, defaultConnectWeight);
223 int maxNodesPerAggregate = params.get<
int>(
"aggregation: max agg size");
224 if(maxNodesPerAggregate == std::numeric_limits<int>::max()) {maxIters = 1;}
225 for (
int iter = 0; iter < maxIters; ++iter) {
226 for(LO color = 1; color <= numColors; color++) {
227 Kokkos::deep_copy(aggWeight, 0);
231 LO numAggregated = 0;
232 Kokkos::parallel_for(
"Aggregation Phase 2b: updating agg weights",
233 Kokkos::RangePolicy<execution_space>(0, numRows),
234 KOKKOS_LAMBDA (
const LO i)
236 if (aggStat(i) !=
READY || colors(i) != color)
238 auto neighOfINode = lclLWGraph.getNeighborVertices(i);
239 for (
int j = 0; j < neighOfINode.length; j++) {
240 LO neigh = neighOfINode(j);
243 if (lclLWGraph.isLocalNeighborVertex(neigh) &&
245 Kokkos::atomic_add(&aggWeight(vertex2AggId(neigh, 0)),
246 connectWeight(neigh));
250 Kokkos::parallel_reduce(
"Aggregation Phase 2b: aggregates expansion",
251 Kokkos::RangePolicy<execution_space>(0, numRows),
252 KOKKOS_LAMBDA (
const LO i, LO& tmpNumAggregated)
254 if (aggStat(i) !=
READY || colors(i) != color)
256 int bestScore = -100000;
258 int bestConnect = -1;
260 auto neighOfINode = lclLWGraph.getNeighborVertices(i);
261 for (
int j = 0; j < neighOfINode.length; j++) {
262 LO neigh = neighOfINode(j);
264 if (lclLWGraph.isLocalNeighborVertex(neigh) &&
266 auto aggId = vertex2AggId(neigh, 0);
267 int score = aggWeight(aggId) - aggPenalties(aggId);
269 if (score > bestScore) {
272 bestConnect = connectWeight(neigh);
274 }
else if (aggId == bestAggId &&
275 connectWeight(neigh) > bestConnect) {
276 bestConnect = connectWeight(neigh);
280 if (bestScore >= 0) {
282 vertex2AggId(i, 0) = bestAggId;
283 procWinner(i, 0) = myRank;
285 Kokkos::atomic_add(&aggPenaltyUpdates(bestAggId), 1);
286 connectWeight(i) = bestConnect - penaltyConnectWeight;
291 Kokkos::parallel_for(
"Aggregation Phase 2b: updating agg penalties",
292 Kokkos::RangePolicy<execution_space>(0, numLocalAggregates),
293 KOKKOS_LAMBDA (
const LO agg)
295 aggPenalties(agg) += aggPenaltyUpdates(agg);
296 aggPenaltyUpdates(agg) = 0;
298 numNonAggregatedNodes -= numAggregated;