46 #ifndef MUELU_UNCOUPLEDAGGREGATIONFACTORY_KOKKOS_DEF_HPP_ 47 #define MUELU_UNCOUPLEDAGGREGATIONFACTORY_KOKKOS_DEF_HPP_ 49 #ifdef HAVE_MUELU_KOKKOS_REFACTOR 53 #include <Xpetra_Map.hpp> 54 #include <Xpetra_Vector.hpp> 55 #include <Xpetra_MultiVectorFactory.hpp> 56 #include <Xpetra_VectorFactory.hpp> 60 #include "MueLu_OnePtAggregationAlgorithm_kokkos.hpp" 61 #include "MueLu_PreserveDirichletAggregationAlgorithm_kokkos.hpp" 62 #include "MueLu_IsolatedNodeAggregationAlgorithm_kokkos.hpp" 64 #include "MueLu_AggregationPhase1Algorithm_kokkos.hpp" 65 #include "MueLu_AggregationPhase2aAlgorithm_kokkos.hpp" 66 #include "MueLu_AggregationPhase2bAlgorithm_kokkos.hpp" 67 #include "MueLu_AggregationPhase3Algorithm_kokkos.hpp" 70 #include "MueLu_LWGraph_kokkos.hpp" 71 #include "MueLu_Aggregates_kokkos.hpp" 74 #include "MueLu_AmalgamationInfo.hpp" 75 #include "MueLu_Utilities.hpp" 79 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
80 UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::UncoupledAggregationFactory_kokkos()
81 : bDefinitionPhase_(true)
84 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
85 RCP<const ParameterList> UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::GetValidParameterList()
const {
86 RCP<ParameterList> validParamList = rcp(
new ParameterList());
91 typedef Teuchos::StringToIntegralParameterEntryValidator<int> validatorType;
92 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name)) 97 validParamList->getEntry(
"aggregation: ordering").setValidator(
98 rcp(
new validatorType(Teuchos::tuple<std::string>(
"natural",
"graph",
"random"),
"aggregation: ordering")));
105 #undef SET_VALID_ENTRY 108 validParamList->set< RCP<const FactoryBase> >(
"Graph", null,
"Generating factory of the graph");
109 validParamList->set< RCP<const FactoryBase> >(
"DofsPerNode", null,
"Generating factory for variable \'DofsPerNode\', usually the same as for \'Graph\'");
112 validParamList->set< std::string > (
"OnePt aggregate map name",
"",
"Name of input map for single node aggregates. (default='')");
113 validParamList->set< std::string > (
"OnePt aggregate map factory",
"",
"Generating factory of (DOF) map for single node aggregates.");
116 return validParamList;
119 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
120 void UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& currentLevel)
const {
121 Input(currentLevel,
"Graph");
122 Input(currentLevel,
"DofsPerNode");
124 const ParameterList& pL = GetParameterList();
127 std::string mapOnePtName = pL.get<std::string>(
"OnePt aggregate map name");
128 if (mapOnePtName.length() > 0) {
129 std::string mapOnePtFactName = pL.get<std::string>(
"OnePt aggregate map factory");
130 if (mapOnePtFactName ==
"" || mapOnePtFactName ==
"NoFactory") {
131 currentLevel.DeclareInput(mapOnePtName, NoFactory::get());
133 RCP<const FactoryBase> mapOnePtFact = GetFactory(mapOnePtFactName);
134 currentLevel.DeclareInput(mapOnePtName, mapOnePtFact.get());
139 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
140 void UncoupledAggregationFactory_kokkos<LocalOrdinal, GlobalOrdinal, Node>::Build(Level ¤tLevel)
const {
141 FactoryMonitor m(*
this,
"Build", currentLevel);
143 ParameterList pL = GetParameterList();
144 bDefinitionPhase_ =
false;
146 if (pL.get<
int>(
"aggregation: max agg size") == -1)
147 pL.set(
"aggregation: max agg size", INT_MAX);
150 RCP<const FactoryBase> graphFact = GetFactory(
"Graph");
154 algos_.push_back(rcp(
new PreserveDirichletAggregationAlgorithm_kokkos(graphFact)));
155 if (pL.get<
bool>(
"aggregation: allow user-specified singletons") ==
true) algos_.push_back(rcp(
new OnePtAggregationAlgorithm_kokkos (graphFact)));
156 if (pL.get<
bool>(
"aggregation: enable phase 1" ) ==
true) algos_.push_back(rcp(
new AggregationPhase1Algorithm_kokkos (graphFact)));
157 if (pL.get<
bool>(
"aggregation: enable phase 2a") ==
true) algos_.push_back(rcp(
new AggregationPhase2aAlgorithm_kokkos (graphFact)));
158 if (pL.get<
bool>(
"aggregation: enable phase 2b") ==
true) algos_.push_back(rcp(
new AggregationPhase2bAlgorithm_kokkos (graphFact)));
159 if (pL.get<
bool>(
"aggregation: enable phase 3" ) ==
true) algos_.push_back(rcp(
new AggregationPhase3Algorithm_kokkos (graphFact)));
161 std::string mapOnePtName = pL.get<std::string>(
"OnePt aggregate map name");
162 RCP<Map> OnePtMap = Teuchos::null;
163 if (mapOnePtName.length()) {
164 std::string mapOnePtFactName = pL.get<std::string>(
"OnePt aggregate map factory");
165 if (mapOnePtFactName ==
"" || mapOnePtFactName ==
"NoFactory") {
166 OnePtMap = currentLevel.Get<RCP<Map> >(mapOnePtName, NoFactory::get());
168 RCP<const FactoryBase> mapOnePtFact = GetFactory(mapOnePtFactName);
169 OnePtMap = currentLevel.Get<RCP<Map> >(mapOnePtName, mapOnePtFact.get());
173 RCP<const LWGraph_kokkos> graph = Get< RCP<LWGraph_kokkos> >(currentLevel,
"Graph");
176 RCP<Aggregates_kokkos> aggregates = rcp(
new Aggregates_kokkos(*graph));
177 aggregates->setObjectLabel(
"UC");
179 const LO numRows = graph->GetNodeNumVertices();
182 std::vector<unsigned> aggStat(numRows,
READY);
186 ArrayRCP<const bool> dirichletBoundaryMap;
188 if (dirichletBoundaryMap != Teuchos::null)
189 for (LO i = 0; i < numRows; i++)
190 if (dirichletBoundaryMap[i] ==
true)
193 LO nDofsPerNode = Get<LO>(currentLevel,
"DofsPerNode");
194 GO indexBase = graph->GetDomainMap()->getIndexBase();
195 if (OnePtMap != Teuchos::null) {
196 for (LO i = 0; i < numRows; i++) {
198 GO grid = (graph->GetDomainMap()->getGlobalElement(i)-indexBase) * nDofsPerNode + indexBase;
200 for (LO kr = 0; kr < nDofsPerNode; kr++)
201 if (OnePtMap->isNodeGlobalElement(grid + kr))
207 const RCP<const Teuchos::Comm<int> > comm = graph->GetComm();
208 GO numGlobalRows = 0;
212 LO numNonAggregatedNodes = numRows;
213 GO numGlobalAggregatedPrev = 0, numGlobalAggsPrev = 0;
214 for (
size_t a = 0; a < algos_.size(); a++) {
215 std::string phase = algos_[a]->description();
216 SubFactoryMonitor sfm(*
this,
"Algo \"" + phase +
"\"", currentLevel);
218 int oldRank = algos_[a]->SetProcRankVerbose(this->GetProcRankVerbose());
219 algos_[a]->BuildAggregates(pL, *graph, *aggregates, aggStat, numNonAggregatedNodes);
220 algos_[a]->SetProcRankVerbose(oldRank);
223 GO numLocalAggregated = numRows - numNonAggregatedNodes, numGlobalAggregated = 0;
224 GO numLocalAggs = aggregates->GetNumAggregates(), numGlobalAggs = 0;
225 MueLu_sumAll(comm, numLocalAggregated, numGlobalAggregated);
228 double aggPercent = 100*as<double>(numGlobalAggregated)/as<double>(numGlobalRows);
229 if (aggPercent > 99.99 && aggPercent < 100.00) {
236 GetOStream(
Statistics1) <<
" aggregated : " << (numGlobalAggregated - numGlobalAggregatedPrev) <<
" (phase), " << std::fixed
237 << std::setprecision(2) << numGlobalAggregated <<
"/" << numGlobalRows <<
" [" << aggPercent <<
"%] (total)\n" 238 <<
" remaining : " << numGlobalRows - numGlobalAggregated <<
"\n" 239 <<
" aggregates : " << numGlobalAggs-numGlobalAggsPrev <<
" (phase), " << numGlobalAggs <<
" (total)" << std::endl;
240 numGlobalAggregatedPrev = numGlobalAggregated;
241 numGlobalAggsPrev = numGlobalAggs;
245 TEUCHOS_TEST_FOR_EXCEPTION(numNonAggregatedNodes, Exceptions::RuntimeError,
"MueLu::UncoupledAggregationFactory::Build: Leftover nodes found! Error!");
247 aggregates->AggregatesCrossProcessors(
false);
249 Set(currentLevel,
"Aggregates", aggregates);
251 GetOStream(
Statistics1) << aggregates->description() << std::endl;
256 #endif // HAVE_MUELU_KOKKOS_REFACTOR #define MueLu_sumAll(rcpComm, in, out)
Namespace for MueLu classes and methods.
#define SET_VALID_ENTRY(name)