46#ifndef MUELU_STRUCTUREDAGGREGATIONFACTORY_KOKKOS_DEF_HPP
47#define MUELU_STRUCTUREDAGGREGATIONFACTORY_KOKKOS_DEF_HPP
50#include <Xpetra_Map.hpp>
51#include <Xpetra_CrsGraph.hpp>
57#include "MueLu_Utilities.hpp"
60#include "MueLu_LWGraph_kokkos.hpp"
61#include "MueLu_Aggregates_kokkos.hpp"
62#include "MueLu_IndexManager_kokkos.hpp"
63#include "MueLu_AggregationStructuredAlgorithm_kokkos.hpp"
69 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 RCP<ParameterList> validParamList = rcp(
new ParameterList());
78#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
81 SET_VALID_ENTRY(
"aggregation: error on nodes with no on-rank neighbors");
86 validParamList->set<std::string> (
"aggregation: output type",
"Aggregates",
87 "Type of object holding the aggregation data: Aggregtes or CrsGraph");
88 validParamList->set<std::string> (
"aggregation: coarsening rate",
"{3}",
89 "Coarsening rate per spatial dimensions");
90 validParamList->set<
int> (
"aggregation: coarsening order", 0,
91 "The interpolation order used to construct grid transfer operators based off these aggregates.");
92 validParamList->set<RCP<const FactoryBase> >(
"Graph", Teuchos::null,
93 "Graph of the matrix after amalgamation but without dropping.");
94 validParamList->set<RCP<const FactoryBase> >(
"DofsPerNode", Teuchos::null,
95 "Number of degrees of freedom per mesh node, provided by the coalsce drop factory.");
96 validParamList->set<RCP<const FactoryBase> >(
"numDimensions", Teuchos::null,
97 "Number of spatial dimension provided by CoordinatesTransferFactory.");
98 validParamList->set<RCP<const FactoryBase> >(
"lNodesPerDim", Teuchos::null,
99 "Number of nodes per spatial dimmension provided by CoordinatesTransferFactory.");
101 return validParamList;
104 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
107 Input(currentLevel,
"Graph");
108 Input(currentLevel,
"DofsPerNode");
117 "numDimensions was not provided by the user on level0!");
124 "lNodesPerDim was not provided by the user on level0!");
127 Input(currentLevel,
"lNodesPerDim");
128 Input(currentLevel,
"numDimensions");
132 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137 RCP<Teuchos::FancyOStream> out;
138 if(
const char* dbg = std::getenv(
"MUELU_STRUCTUREDAGGREGATION_DEBUG")) {
139 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
140 out->setShowAllFrontMatter(
false).setShowProcRank(
true);
142 out = Teuchos::getFancyOStream(rcp(
new Teuchos::oblackholestream()));
145 using device_type =
typename LWGraph_kokkos::local_graph_type::device_type;
146 using execution_space =
typename LWGraph_kokkos::local_graph_type::device_type::execution_space;
147 using memory_space =
typename LWGraph_kokkos::local_graph_type::device_type::memory_space;
149 *out <<
"Entering structured aggregation" << std::endl;
151 ParameterList pL = GetParameterList();
152 bDefinitionPhase_ =
false;
155 RCP<const LWGraph_kokkos> graph = Get<RCP<LWGraph_kokkos> >(currentLevel,
"Graph");
156 RCP<const Map> fineMap = graph->GetDomainMap();
157 const int myRank = fineMap->getComm()->getRank();
158 const LO dofsPerNode = Get<LO>(currentLevel,
"DofsPerNode");
162 const int interpolationOrder = pL.get<
int>(
"aggregation: coarsening order");
163 std::string outputType = pL.get<std::string>(
"aggregation: output type");
164 const bool outputAggregates = (outputType ==
"Aggregates" ? true :
false);
165 Array<LO> lFineNodesPerDir(3);
169 lFineNodesPerDir = currentLevel.
Get<Array<LO> >(
"lNodesPerDim",
NoFactory::get());
173 lFineNodesPerDir = Get<Array<LO> >(currentLevel,
"lNodesPerDim");
174 numDimensions = Get<int>(currentLevel,
"numDimensions");
179 for(
int dim = 0; dim < 3; ++dim) {
180 if(dim >= numDimensions) {
181 lFineNodesPerDir[dim] = 1;
186 std::string coarseningRate = pL.get<std::string>(
"aggregation: coarsening rate");
187 Teuchos::Array<LO> coarseRate;
189 coarseRate = Teuchos::fromStringToArray<LO>(coarseningRate);
190 }
catch(
const Teuchos::InvalidArrayStringRepresentation& e) {
191 GetOStream(
Errors,-1) <<
" *** \"aggregation: coarsening rate\" must be a string convertible into an array! *** "
195 TEUCHOS_TEST_FOR_EXCEPTION((coarseRate.size() > 1) && (coarseRate.size() < numDimensions),
197 "\"aggregation: coarsening rate\" must have at least as many"
198 " components as the number of spatial dimensions in the problem.");
202 interpolationOrder, myRank,
206 *out <<
"The index manager has now been built" << std::endl;
207 TEUCHOS_TEST_FOR_EXCEPTION(fineMap->getLocalNumElements()
208 !=
static_cast<size_t>(geoData->getNumLocalFineNodes()),
210 "The local number of elements in the graph's map is not equal to "
211 "the number of nodes given by: lNodesPerDim!");
215 RCP<AggregationStructuredAlgorithm_kokkos> myStructuredAlgorithm
218 if(interpolationOrder == 0 && outputAggregates){
219 RCP<Aggregates_kokkos> aggregates = rcp(
new Aggregates_kokkos(graph->GetDomainMap()));
220 aggregates->setObjectLabel(
"ST");
221 aggregates->SetIndexManager(geoData);
222 aggregates->AggregatesCrossProcessors(
false);
223 aggregates->SetNumAggregates(geoData->getNumCoarseNodes());
225 LO numNonAggregatedNodes = geoData->getNumLocalFineNodes();
226 Kokkos::View<unsigned*, device_type> aggStat(
"aggStat", numNonAggregatedNodes);
227 Kokkos::parallel_for(
"StructuredAggregation: initialize aggStat",
228 Kokkos::RangePolicy<execution_space>(0, numNonAggregatedNodes),
229 KOKKOS_LAMBDA(
const LO nodeIdx) {aggStat(nodeIdx) =
READY;});
231 myStructuredAlgorithm->BuildAggregates(pL, *graph, *aggregates, aggStat,
232 numNonAggregatedNodes);
234 *out <<
"numNonAggregatedNodes: " << numNonAggregatedNodes << std::endl;
237 "MueLu::StructuredAggregationFactory::Build: Leftover nodes found! Error!");
238 aggregates->ComputeAggregateSizes(
true);
239 GetOStream(
Statistics1) << aggregates->description() << std::endl;
240 Set(currentLevel,
"Aggregates", aggregates);
244 RCP<CrsGraph> myGraph;
245 myStructuredAlgorithm->BuildGraph(*graph, geoData, dofsPerNode, myGraph);
246 Set(currentLevel,
"prolongatorGraph", myGraph);
249 Set(currentLevel,
"lCoarseNodesPerDim", geoData->getCoarseNodesPerDirArray());
250 Set(currentLevel,
"indexManager", geoData);
251 Set(currentLevel,
"structuredInterpolationOrder", interpolationOrder);
252 Set(currentLevel,
"numDimensions", numDimensions);
#define SET_VALID_ENTRY(name)
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
Container class for mesh layout and indices calculation.
Class that holds all level-specific information.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
int GetLevelID() const
Return level number.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
static const NoFactory * get()
StructuredAggregationFactory_kokkos()
Constructor.
void Build(Level ¤tLevel) const
Build aggregates.
void DeclareInput(Level ¤tLevel) const
Input.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Namespace for MueLu classes and methods.
@ Statistics1
Print more statistics.