46 #ifndef MUELU_AGGREGATIONPHASE1ALGORITHM_DEF_HPP_ 47 #define MUELU_AGGREGATIONPHASE1ALGORITHM_DEF_HPP_ 51 #include <Teuchos_Comm.hpp> 52 #include <Teuchos_CommHelpers.hpp> 54 #include <Xpetra_Vector.hpp> 59 #include "MueLu_Aggregates.hpp" 65 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
68 LO& numNonAggregatedNodes)
const {
69 Monitor m(*
this,
"BuildAggregates");
71 std::string ordering = params.get<std::string>(
"aggregation: ordering");
72 int maxNeighAlreadySelected = params.get<
int> (
"aggregation: max selected neighbors");
73 int minNodesPerAggregate = params.get<
int> (
"aggregation: min agg size");
74 int maxNodesPerAggregate = params.get<
int> (
"aggregation: max agg size");
77 "MueLu::UncoupledAggregationAlgorithm::BuildAggregates: minNodesPerAggregate must be smaller or equal to MaxNodePerAggregate!");
80 const int myRank = graph.
GetComm()->getRank();
82 ArrayRCP<LO> vertex2AggId = aggregates.
GetVertex2AggId()->getDataNonConst(0);
83 ArrayRCP<LO> procWinner = aggregates.
GetProcWinner() ->getDataNonConst(0);
87 ArrayRCP<LO> randomVector;
88 if (ordering ==
"random") {
89 randomVector = arcp<LO>(numRows);
90 for (LO i = 0; i < numRows; i++)
92 RandomReorder(randomVector);
99 std::queue<LO> graphOrderQueue;
102 for (LO i = 0; i < numRows; i++) {
104 LO rootCandidate = 0;
105 if (ordering ==
"natural") rootCandidate = i;
106 else if (ordering ==
"random") rootCandidate = randomVector[i];
107 else if (ordering ==
"graph") {
109 if (graphOrderQueue.size() == 0) {
111 for (LO jnode = 0; jnode < numRows; jnode++)
112 if (aggStat[jnode] ==
READY) {
113 graphOrderQueue.push(jnode);
117 if (graphOrderQueue.size() == 0) {
121 rootCandidate = graphOrderQueue.front();
122 graphOrderQueue.pop();
125 if (aggStat[rootCandidate] !=
READY)
130 aggList[aggSize++] = rootCandidate;
138 if ((ordering ==
"natural" || ordering ==
"random") &&
139 neighOfINode.size() < minNodesPerAggregate) {
143 LO numAggregatedNeighbours = 0;
145 for (
int j = 0; j < neighOfINode.size(); j++) {
146 LO neigh = neighOfINode[j];
150 if (aggStat[neigh] ==
READY || aggStat[neigh] ==
NOTSEL) {
159 if (aggSize < as<size_t>(maxNodesPerAggregate))
160 aggList[aggSize++] = neigh;
163 numAggregatedNeighbours++;
169 if ((numAggregatedNeighbours <= maxNeighAlreadySelected) &&
170 (aggSize >= as<size_t>(minNodesPerAggregate))) {
174 aggIndex = numLocalAggregates++;
176 for (
size_t k = 0; k < aggSize; k++) {
178 vertex2AggId[aggList[k]] = aggIndex;
179 procWinner [aggList[k]] = myRank;
182 numNonAggregatedNodes -= aggSize;
186 aggStat[rootCandidate] =
NOTSEL;
193 if (ordering ==
"graph") {
198 for (
size_t k = 0; k < aggSize; k++) {
201 for (
int j = 0; j < neighOfJNode.size(); j++) {
202 LO neigh = neighOfJNode[j];
205 graphOrderQueue.push(neigh);
213 for (LO i = 0; i < numRows; i++)
221 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
225 for(
int i = 0; i < n-1; i++)
226 std::swap(list[i], list[RandomOrdinal(i,n-1)]);
229 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
231 return min + as<int>((max-min+1) * (static_cast<double>(std::rand()) / (RAND_MAX + 1.0)));
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
Container class for aggregation information.
virtual size_t getNodeMaxNumRowEntries() const =0
virtual size_t GetNodeNumVertices() const =0
Return number of vertices owned by the calling node.
Namespace for MueLu classes and methods.
const RCP< LOVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
void SetIsRoot(LO i, bool value=true)
Set root node information.
LO GetNumAggregates() const
returns the number of aggregates of the current processor. Note: could/should be renamed to GetNumLoc...
virtual bool isLocalNeighborVertex(LocalOrdinal v) const =0
Return true if vertex with local id 'v' is on current process.
void RandomReorder(ArrayRCP< LO > list) const
Utility to take a list of integers and reorder them randomly (by using a local permutation).
virtual const RCP< const Teuchos::Comm< int > > GetComm() const =0
MueLu representation of a graph.
void BuildAggregates(const ParameterList ¶ms, const GraphBase &graph, Aggregates &aggregates, std::vector< unsigned > &aggStat, LO &numNonAggregatedNodes) const
Local aggregation.
Timer to be used in non-factories.
Exception throws to report errors in the internal logical of the program.
int RandomOrdinal(int min, int max) const
Generate a random number in the range [min, max].
virtual Teuchos::ArrayView< const LocalOrdinal > getNeighborVertices(LocalOrdinal v) const =0
Return the list of vertices adjacent to the vertex 'v'.
void SetNumAggregates(LO nAggregates)
Set number of local aggregates on current processor.