46 #ifndef MUELU_LOCALAGGREGATIONALGORITHM_DEF_HPP
47 #define MUELU_LOCALAGGREGATIONALGORITHM_DEF_HPP
49 #include <Teuchos_Comm.hpp>
50 #include <Teuchos_CommHelpers.hpp>
56 #include "MueLu_Aggregates.hpp"
61 #include "MueLu_Utilities.hpp"
65 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 : ordering_(
"natural"), minNodesPerAggregate_(1), maxNeighAlreadySelected_(0)
70 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 Monitor m(*
this,
"Coarsen Uncoupled");
74 GetOStream(
Runtime1) <<
"Ordering: " << ordering_ << std::endl;
75 GetOStream(
Runtime1) <<
"Min nodes per aggregate: " << minNodesPerAggregate_ << std::endl;
76 GetOStream(
Runtime1) <<
"Max nbrs already selected: " << maxNeighAlreadySelected_ << std::endl;
89 if (nRows > 0) aggStat = Teuchos::arcp<CANodeState>(nRows);
106 if ( ordering_ ==
"random" )
110 randomVector = Teuchos::arcp<LO>(nRows);
111 for (
my_size_t i = 0; i < nRows; ++i) randomVector[i] = i;
112 RandomReorder(randomVector);
114 else if ( ordering_ ==
"graph" )
127 while (iNode2 < nRows)
134 if ( ordering_ ==
"natural" ) iNode = iNode2++;
135 else if ( ordering_ ==
"random" ) iNode = randomVector[iNode2++];
136 else if ( ordering_ ==
"graph" )
140 for (
int jNode = 0; jNode < nRows; ++jNode )
144 nodeList->
Add(jNode);
149 if ( nodeList->
IsEmpty() )
break;
151 iNode = nodeList->
Pop();
169 supernode->
list = Teuchos::arcp<int>(length+1);
170 }
catch (std::bad_alloc&) {
174 supernode->maxLength = length;
175 supernode->length = 1;
176 supernode->list[0] = iNode;
192 supernode->list[supernode->length++] = index;
204 if ( count > GetMaxNeighAlreadySelected() ) selectFlag = 0;
213 if (selectFlag != 1 ||
214 supernode->length <= GetMinNodesPerAggregate())
218 if ( ordering_ ==
"graph" )
223 if ( index < nRows && aggStat[index] ==
CA_READY )
225 nodeList->
Add(index);
233 for (
int j = 0; j < supernode->length; ++j )
235 int jNode = supernode->list[j];
237 vertex2AggId[jNode] = nAggregates;
238 if ( ordering_ ==
"graph" )
246 if ( index < nRows && aggStat[index] ==
CA_READY )
248 nodeList->
Add(index);
253 supernode->next = NULL;
254 supernode->index = nAggregates;
255 if ( nAggregates == 0 )
258 aggCurrent = supernode;
262 aggCurrent->
next = supernode;
263 aggCurrent = supernode;
275 nodeList = Teuchos::null;
285 GO localReady=0, globalReady;
289 if (aggStat[i] ==
CA_READY) localReady++;
295 GetOStream(
Warnings0) << globalReady <<
" CA_READY nodes left" << std::endl;
310 GetOStream(
Statistics1) <<
"Nodes aggregated = " << globalSelected <<
" (" << globalNRows <<
")" << std::endl;
314 GO nAggregatesGlobal;
MueLu_sumAll(comm, (
GO)nAggregates, nAggregatesGlobal);
315 GetOStream(
Statistics1) <<
"Total aggregates = " << nAggregatesGlobal << std::endl;
324 aggCurrent = aggHead;
325 while ( aggCurrent != NULL )
327 supernode = aggCurrent;
328 aggCurrent = aggCurrent->
next;
334 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
338 for(
int i=0; i<n-1; i++) {
339 std::swap(list[i], list[RandomOrdinal(i,n-1)]);
343 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
345 return min + Teuchos::as<int>((max-min+1) * (static_cast<double>(std::rand()) / (RAND_MAX + 1.0)));
350 #endif // MUELU_LOCALAGGREGATIONALGORITHM_DEF_HPP
Important warning messages (one line)
#define MueLu_sumAll(rcpComm, in, out)
Container class for aggregation information.
void CoarsenUncoupled(GraphBase const &graph, Aggregates &aggregates) const
Local aggregation.
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)
const_pointer const_iterator
void RandomReorder(Teuchos::ArrayRCP< LO > list) const
Utility to take a list of integers and reorder them randomly (by using a local permutation).
void SetIsRoot(LO i, bool value=true)
Set root node information.
LocalAggregationAlgorithm()
Constructor.
Teuchos::ArrayRCP< int > list
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int RandomOrdinal(int min, int max) const
Generate a random number in the range [min, max].
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.
struct MueLu::MueLu_SuperNode_Struct MueLu_SuperNode
struct MueLu_SuperNode_Struct * next
Timer to be used in non-factories.
Exception throws to report errors in the internal logical of the program.
Description of what is happening (more verbose)
virtual Teuchos::ArrayView< const LocalOrdinal > getNeighborVertices(LocalOrdinal v) const =0
Return the list of vertices adjacent to the vertex 'v'.
std::string toString(const T &t)
void SetNumAggregates(LO nAggregates)
Set number of local aggregates on current processor.