46 #ifndef MUELU_AGGREGATIONPHASE1ALGORITHM_DEF_HPP_
47 #define MUELU_AGGREGATIONPHASE1ALGORITHM_DEF_HPP_
51 #include <Teuchos_Comm.hpp>
52 #include <Teuchos_CommHelpers.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 orderingStr = 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!");
85 if (orderingStr ==
"natural") ordering = O_NATURAL;
86 if (orderingStr ==
"random" ) ordering = O_RANDOM;
87 if (orderingStr ==
"graph" ) ordering = O_GRAPH;
90 const int myRank = graph.
GetComm()->getRank();
98 if (ordering == O_RANDOM) {
99 randomVector = arcp<LO>(numRows);
100 for (
LO i = 0; i < numRows; i++)
102 RandomReorder(randomVector);
109 std::queue<LO> graphOrderQueue;
112 for (
LO i = 0; i < numRows; i++) {
114 LO rootCandidate = 0;
115 if (ordering == O_NATURAL) rootCandidate = i;
116 else if (ordering == O_RANDOM) rootCandidate = randomVector[i];
117 else if (ordering == O_GRAPH) {
119 if (graphOrderQueue.size() == 0) {
121 for (
LO jnode = 0; jnode < numRows; jnode++)
122 if (aggStat[jnode] ==
READY) {
123 graphOrderQueue.push(jnode);
127 if (graphOrderQueue.size() == 0) {
131 rootCandidate = graphOrderQueue.front();
132 graphOrderQueue.pop();
135 if (aggStat[rootCandidate] !=
READY)
140 aggList[aggSize++] = rootCandidate;
148 if ((ordering == O_NATURAL || ordering == O_RANDOM) &&
149 neighOfINode.
size() < minNodesPerAggregate) {
153 LO numAggregatedNeighbours = 0;
155 for (
int j = 0; j < neighOfINode.
size(); j++) {
156 LO neigh = neighOfINode[j];
160 if (aggStat[neigh] ==
READY || aggStat[neigh] ==
NOTSEL) {
169 if (aggSize < as<size_t>(maxNodesPerAggregate))
170 aggList[aggSize++] = neigh;
173 numAggregatedNeighbours++;
179 if ((numAggregatedNeighbours <= maxNeighAlreadySelected) &&
180 (aggSize >= as<size_t>(minNodesPerAggregate))) {
184 aggIndex = numLocalAggregates++;
186 for (
size_t k = 0; k < aggSize; k++) {
188 vertex2AggId[aggList[k]] = aggIndex;
189 procWinner [aggList[k]] = myRank;
192 numNonAggregatedNodes -= aggSize;
196 aggStat[rootCandidate] =
NOTSEL;
203 if (ordering == O_GRAPH) {
208 for (
size_t k = 0; k < aggSize; k++) {
211 for (
int j = 0; j < neighOfJNode.
size(); j++) {
212 LO neigh = neighOfJNode[j];
215 graphOrderQueue.push(neigh);
223 for (
LO i = 0; i < numRows; i++)
231 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
235 for(
int i = 0; i < n-1; i++)
236 std::swap(list[i], list[RandomOrdinal(i,n-1)]);
239 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
241 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
T & get(const std::string &name, T def_value)
virtual size_t GetNodeNumVertices() const =0
Return number of vertices owned by the calling node.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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).
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
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.