46 #ifndef MUELU_UNCOUPLEDAGGREGATIONFACTORY_KOKKOS_DEF_HPP_ 47 #define MUELU_UNCOUPLEDAGGREGATIONFACTORY_KOKKOS_DEF_HPP_ 49 #ifdef HAVE_MUELU_KOKKOS_REFACTOR 59 #include "MueLu_OnePtAggregationAlgorithm_kokkos.hpp" 60 #include "MueLu_PreserveDirichletAggregationAlgorithm_kokkos.hpp" 61 #include "MueLu_IsolatedNodeAggregationAlgorithm_kokkos.hpp" 63 #include "MueLu_AggregationPhase1Algorithm_kokkos.hpp" 64 #include "MueLu_AggregationPhase2aAlgorithm_kokkos.hpp" 65 #include "MueLu_AggregationPhase2bAlgorithm_kokkos.hpp" 66 #include "MueLu_AggregationPhase3Algorithm_kokkos.hpp" 69 #include "MueLu_LWGraph_kokkos.hpp" 70 #include "MueLu_Aggregates_kokkos.hpp" 73 #include "MueLu_AmalgamationInfo.hpp" 74 #include "MueLu_Utilities.hpp" 78 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::UncoupledAggregationFactory_kokkos()
80 : bDefinitionPhase_(true)
83 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 RCP<const ParameterList> UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::GetValidParameterList()
const {
85 RCP<ParameterList> validParamList =
rcp(
new ParameterList());
91 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name)) 96 validParamList->getEntry(
"aggregation: ordering").setValidator(
97 rcp(
new validatorType(Teuchos::tuple<std::string>(
"natural",
"graph",
"random"),
"aggregation: ordering")));
104 #undef SET_VALID_ENTRY 107 validParamList->set< RCP<const FactoryBase> >(
"Graph", null,
"Generating factory of the graph");
108 validParamList->set< RCP<const FactoryBase> >(
"DofsPerNode", null,
"Generating factory for variable \'DofsPerNode\', usually the same as for \'Graph\'");
111 validParamList->set< std::string > (
"OnePt aggregate map name",
"",
"Name of input map for single node aggregates. (default='')");
112 validParamList->set< std::string > (
"OnePt aggregate map factory",
"",
"Generating factory of (DOF) map for single node aggregates.");
115 return validParamList;
118 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
119 void UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& currentLevel)
const {
120 Input(currentLevel,
"Graph");
121 Input(currentLevel,
"DofsPerNode");
123 const ParameterList& pL = GetParameterList();
126 std::string mapOnePtName = pL.get<std::string>(
"OnePt aggregate map name");
127 if (mapOnePtName.length() > 0) {
128 std::string mapOnePtFactName = pL.get<std::string>(
"OnePt aggregate map factory");
129 if (mapOnePtFactName ==
"" || mapOnePtFactName ==
"NoFactory") {
130 currentLevel.DeclareInput(mapOnePtName, NoFactory::get());
132 RCP<const FactoryBase> mapOnePtFact = GetFactory(mapOnePtFactName);
133 currentLevel.DeclareInput(mapOnePtName, mapOnePtFact.get());
138 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 void UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::Build(Level ¤tLevel)
const {
140 FactoryMonitor m(*
this,
"Build", currentLevel);
142 ParameterList pL = GetParameterList();
143 bDefinitionPhase_ =
false;
145 if (pL.get<
int>(
"aggregation: max agg size") == -1)
146 pL.set(
"aggregation: max agg size", INT_MAX);
149 RCP<const FactoryBase> graphFact = GetFactory(
"Graph");
153 algos_.push_back(
rcp(
new PreserveDirichletAggregationAlgorithm_kokkos(graphFact)));
154 if (pL.get<
bool>(
"aggregation: allow user-specified singletons") ==
true) algos_.push_back(
rcp(
new OnePtAggregationAlgorithm_kokkos (graphFact)));
155 if (pL.get<
bool>(
"aggregation: enable phase 1" ) ==
true) algos_.push_back(
rcp(
new AggregationPhase1Algorithm_kokkos (graphFact)));
156 if (pL.get<
bool>(
"aggregation: enable phase 2a") ==
true) algos_.push_back(
rcp(
new AggregationPhase2aAlgorithm_kokkos (graphFact)));
157 if (pL.get<
bool>(
"aggregation: enable phase 2b") ==
true) algos_.push_back(
rcp(
new AggregationPhase2bAlgorithm_kokkos (graphFact)));
158 if (pL.get<
bool>(
"aggregation: enable phase 3" ) ==
true) algos_.push_back(
rcp(
new AggregationPhase3Algorithm_kokkos (graphFact)));
160 std::string mapOnePtName = pL.get<std::string>(
"OnePt aggregate map name");
161 RCP<Map> OnePtMap = Teuchos::null;
162 if (mapOnePtName.length()) {
163 std::string mapOnePtFactName = pL.get<std::string>(
"OnePt aggregate map factory");
164 if (mapOnePtFactName ==
"" || mapOnePtFactName ==
"NoFactory") {
165 OnePtMap = currentLevel.Get<RCP<Map> >(mapOnePtName, NoFactory::get());
167 RCP<const FactoryBase> mapOnePtFact = GetFactory(mapOnePtFactName);
168 OnePtMap = currentLevel.Get<RCP<Map> >(mapOnePtName, mapOnePtFact.get());
172 RCP<const LWGraph_kokkos> graph = Get< RCP<LWGraph_kokkos> >(currentLevel,
"Graph");
175 RCP<Aggregates_kokkos> aggregates =
rcp(
new Aggregates_kokkos(*graph));
176 aggregates->setObjectLabel(
"UC");
178 const LO numRows = graph->GetNodeNumVertices();
181 std::vector<unsigned> aggStat(numRows,
READY);
185 ArrayRCP<const bool> dirichletBoundaryMap;
187 if (dirichletBoundaryMap != Teuchos::null)
188 for (
LO i = 0; i < numRows; i++)
189 if (dirichletBoundaryMap[i] ==
true)
192 LO nDofsPerNode = Get<LO>(currentLevel,
"DofsPerNode");
193 GO indexBase = graph->GetDomainMap()->getIndexBase();
194 if (OnePtMap != Teuchos::null) {
195 for (
LO i = 0; i < numRows; i++) {
197 GO grid = (graph->GetDomainMap()->getGlobalElement(i)-indexBase) * nDofsPerNode + indexBase;
199 for (
LO kr = 0; kr < nDofsPerNode; kr++)
200 if (OnePtMap->isNodeGlobalElement(grid + kr))
206 const RCP<const Teuchos::Comm<int> > comm = graph->GetComm();
207 GO numGlobalRows = 0;
211 LO numNonAggregatedNodes = numRows;
212 GO numGlobalAggregatedPrev = 0, numGlobalAggsPrev = 0;
213 for (
size_t a = 0; a < algos_.size(); a++) {
214 std::string phase = algos_[a]->description();
215 SubFactoryMonitor sfm(*
this,
"Algo \"" + phase +
"\"", currentLevel);
217 int oldRank = algos_[a]->SetProcRankVerbose(this->GetProcRankVerbose());
218 algos_[a]->BuildAggregates(pL, *graph, *aggregates, aggStat, numNonAggregatedNodes);
219 algos_[a]->SetProcRankVerbose(oldRank);
222 GO numLocalAggregated = numRows - numNonAggregatedNodes, numGlobalAggregated = 0;
223 GO numLocalAggs = aggregates->GetNumAggregates(), numGlobalAggs = 0;
224 MueLu_sumAll(comm, numLocalAggregated, numGlobalAggregated);
227 double aggPercent = 100*as<double>(numGlobalAggregated)/as<double>(numGlobalRows);
228 if (aggPercent > 99.99 && aggPercent < 100.00) {
235 GetOStream(
Statistics1) <<
" aggregated : " << (numGlobalAggregated - numGlobalAggregatedPrev) <<
" (phase), " << std::fixed
236 << std::setprecision(2) << numGlobalAggregated <<
"/" << numGlobalRows <<
" [" << aggPercent <<
"%] (total)\n" 237 <<
" remaining : " << numGlobalRows - numGlobalAggregated <<
"\n" 238 <<
" aggregates : " << numGlobalAggs-numGlobalAggsPrev <<
" (phase), " << numGlobalAggs <<
" (total)" << std::endl;
239 numGlobalAggregatedPrev = numGlobalAggregated;
240 numGlobalAggsPrev = numGlobalAggs;
244 TEUCHOS_TEST_FOR_EXCEPTION(numNonAggregatedNodes, Exceptions::RuntimeError,
"MueLu::UncoupledAggregationFactory::Build: Leftover nodes found! Error!");
246 aggregates->AggregatesCrossProcessors(
false);
248 Set(currentLevel,
"Aggregates", aggregates);
250 GetOStream(
Statistics1) << aggregates->description() << std::endl;
255 #endif // HAVE_MUELU_KOKKOS_REFACTOR #define MueLu_sumAll(rcpComm, in, out)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Namespace for MueLu classes and methods.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define SET_VALID_ENTRY(name)