88 Kokkos::View<unsigned*, typename LWGraph_kokkos::device_type>& aggStat,
89 LO& numNonAggregatedNodes)
const
91 const int minNodesPerAggregate = params.get<
int>(
"aggregation: min agg size");
92 const int maxNodesPerAggregate = params.get<
int>(
"aggregation: max agg size");
93 bool matchMLbehavior = params.get<
bool>(
"aggregation: match ML phase2a");
95 const LO numRows = graph.GetNodeNumVertices();
96 const int myRank = graph.GetComm()->getRank();
98 auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
99 auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
100 auto colors = aggregates.GetGraphColors();
101 const LO numColors = aggregates.GetGraphNumColors();
103 auto lclLWGraph = graph.getLocalLWGraph();
105 LO numLocalNodes = numRows;
106 LO numLocalAggregated = numLocalNodes - numNonAggregatedNodes;
108 const double aggFactor = 0.5;
109 double factor =
static_cast<double>(numLocalAggregated)/(numLocalNodes+1);
110 factor = pow(factor, aggFactor);
116 Kokkos::View<LO, device_type> numLocalAggregates(
"numLocalAggregates");
117 typename Kokkos::View<LO, device_type>::HostMirror h_numLocalAggregates =
118 Kokkos::create_mirror_view(numLocalAggregates);
119 h_numLocalAggregates() = aggregates.GetNumAggregates();
120 Kokkos::deep_copy(numLocalAggregates, h_numLocalAggregates);
124 for(
int color = 2; color < numColors + 1; ++color) {
125 LO tmpNumNonAggregatedNodes = 0;
126 Kokkos::parallel_reduce(
"Aggregation Phase 2a: loop over each individual color",
127 Kokkos::RangePolicy<execution_space>(0, numRows),
128 KOKKOS_LAMBDA (
const LO rootCandidate, LO& lNumNonAggregatedNodes) {
129 if(aggStat(rootCandidate) ==
READY &&
130 colors(rootCandidate) == color) {
134 if (matchMLbehavior) {
139 auto neighbors = lclLWGraph.getNeighborVertices(rootCandidate);
144 for(
int j = 0; j < neighbors.length; ++j) {
145 LO neigh = neighbors(j);
146 if(neigh != rootCandidate) {
147 if(lclLWGraph.isLocalNeighborVertex(neigh) &&
148 (aggStat(neigh) ==
READY) &&
149 (aggSize < maxNodesPerAggregate)) {
158 if(aggSize > minNodesPerAggregate &&
159 (aggSize > factor*numNeighbors)) {
162 LO aggIndex = Kokkos::
163 atomic_fetch_add(&numLocalAggregates(), 1);
165 LO numAggregated = 0;
167 if (matchMLbehavior) {
170 vertex2AggId(rootCandidate, 0) = aggIndex;
171 procWinner(rootCandidate, 0) = myRank;
173 --lNumNonAggregatedNodes;
176 for(
int neighIdx = 0; neighIdx < neighbors.length; ++neighIdx) {
177 LO neigh = neighbors(neighIdx);
178 if(neigh != rootCandidate) {
179 if(lclLWGraph.isLocalNeighborVertex(neigh) &&
180 (aggStat(neigh) ==
READY) &&
181 (numAggregated < aggSize)) {
183 vertex2AggId(neigh, 0) = aggIndex;
184 procWinner(neigh, 0) = myRank;
187 --lNumNonAggregatedNodes;
193 }, tmpNumNonAggregatedNodes);
194 numNonAggregatedNodes += tmpNumNonAggregatedNodes;
198 Kokkos::deep_copy(h_numLocalAggregates, numLocalAggregates);
199 aggregates.SetNumAggregates(h_numLocalAggregates());
207 Kokkos::View<unsigned*, typename LWGraph_kokkos::device_type>& aggStat,
208 LO& numNonAggregatedNodes)
const
210 const int minNodesPerAggregate = params.get<
int>(
"aggregation: min agg size");
211 const int maxNodesPerAggregate = params.get<
int>(
"aggregation: max agg size");
213 const LO numRows = graph.GetNodeNumVertices();
214 const int myRank = graph.GetComm()->getRank();
216 auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
217 auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
218 auto colors = aggregates.GetGraphColors();
219 const LO numColors = aggregates.GetGraphNumColors();
221 auto lclLWGraph = graph.getLocalLWGraph();
223 LO numLocalNodes = procWinner.size();
224 LO numLocalAggregated = numLocalNodes - numNonAggregatedNodes;
226 const double aggFactor = 0.5;
227 double factor = as<double>(numLocalAggregated)/(numLocalNodes+1);
228 factor = pow(factor, aggFactor);
230 Kokkos::View<LO, device_type> numLocalAggregates(
"numLocalAggregates");
231 typename Kokkos::View<LO, device_type>::HostMirror h_numLocalAggregates =
232 Kokkos::create_mirror_view(numLocalAggregates);
233 h_numLocalAggregates() = aggregates.GetNumAggregates();
234 Kokkos::deep_copy(numLocalAggregates, h_numLocalAggregates);
249 Kokkos::View<LO*, device_type> newRoots(
"New root LIDs", numNonAggregatedNodes);
250 Kokkos::View<LO, device_type> numNewRoots(
"Number of new aggregates of current color");
251 auto h_numNewRoots = Kokkos::create_mirror_view(numNewRoots);
252 for(
int color = 1; color < numColors + 1; ++color) {
254 Kokkos::deep_copy(numNewRoots, h_numNewRoots);
255 Kokkos::parallel_for(
"Aggregation Phase 2a: determining new roots of current color",
256 Kokkos::RangePolicy<execution_space>(0, numRows),
257 KOKKOS_LAMBDA(
const LO rootCandidate) {
258 if(aggStat(rootCandidate) ==
READY &&
259 colors(rootCandidate) == color) {
261 auto neighbors = lclLWGraph.getNeighborVertices(rootCandidate);
265 for(
int j = 0; j < neighbors.length; ++j) {
266 LO neigh = neighbors(j);
267 if(neigh != rootCandidate)
269 if(lclLWGraph.isLocalNeighborVertex(neigh) &&
270 aggStat(neigh) ==
READY &&
271 aggSize < maxNodesPerAggregate)
280 if(aggSize > minNodesPerAggregate && aggSize > factor*numNeighbors) {
281 LO newRootIndex = Kokkos::atomic_fetch_add(&numNewRoots(), 1);
282 newRoots(newRootIndex) = rootCandidate;
286 Kokkos::deep_copy(h_numNewRoots, numNewRoots);
288 if(h_numNewRoots() > 0) {
290 Kokkos::sort(newRoots, 0, h_numNewRoots());
292 LO tmpNumNonAggregatedNodes = 0;
294 Kokkos::parallel_reduce(
"Aggregation Phase 2a: create new aggregates",
295 Kokkos::RangePolicy<execution_space>(0, h_numNewRoots()),
296 KOKKOS_LAMBDA (
const LO newRootIndex, LO& lNumNonAggregatedNodes) {
297 LO root = newRoots(newRootIndex);
298 LO newAggID = numLocalAggregates() + newRootIndex;
299 auto neighbors = lclLWGraph.getNeighborVertices(root);
302 vertex2AggId(root, 0) = newAggID;
304 for(
int j = 0; j < neighbors.length; ++j) {
305 LO neigh = neighbors(j);
307 if(lclLWGraph.isLocalNeighborVertex(neigh) &&
308 aggStat(neigh) ==
READY &&
309 aggSize < maxNodesPerAggregate) {
311 vertex2AggId(neigh, 0) = newAggID;
312 procWinner(neigh, 0) = myRank;
317 lNumNonAggregatedNodes -= aggSize;
318 }, tmpNumNonAggregatedNodes);
319 numNonAggregatedNodes += tmpNumNonAggregatedNodes;
320 h_numLocalAggregates() += h_numNewRoots();
321 Kokkos::deep_copy(numLocalAggregates, h_numLocalAggregates);
324 aggregates.SetNumAggregates(h_numLocalAggregates());