47 #ifndef MUELU_AGGREGATES_KOKKOS_DEF_HPP 48 #define MUELU_AGGREGATES_KOKKOS_DEF_HPP 54 #include "MueLu_LWGraph_kokkos.hpp" 61 template <
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
62 Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::Aggregates_kokkos(LWGraph_kokkos graph) {
65 vertex2AggId_ = LOVectorFactory::Build(graph.GetImportMap());
68 procWinner_ = LOVectorFactory::Build(graph.GetImportMap());
71 isRoot_ = Teuchos::ArrayRCP<bool>(graph.GetImportMap()->getNodeNumElements(),
false);
74 aggregatesIncludeGhosts_ =
true;
78 template <
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
79 Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::Aggregates_kokkos(
const RCP<const Map>& map) {
82 vertex2AggId_ = LOVectorFactory::Build(map);
85 procWinner_ = LOVectorFactory::Build(map);
88 isRoot_ = Teuchos::ArrayRCP<bool>(map->getNodeNumElements(),
false);
91 aggregatesIncludeGhosts_ =
true;
95 template<
class ProcWinnerType,
class Vertex2AggIdType,
class AggregateSizesType,
class LO>
111 KOKKOS_INLINE_FUNCTION
117 template <
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
118 typename Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::aggregates_sizes_type::const_type
119 Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::ComputeAggregateSizes(
bool forceRecompute,
bool cacheSizes)
const {
120 if (aggregateSizes_.size() && !forceRecompute) {
121 return aggregateSizes_;
126 aggregateSizes_ = aggregates_sizes_type(
"aggregates", 0);
128 aggregates_sizes_type aggregateSizes(
"aggregates", nAggregates_);
130 int myPID = GetMap()->getComm()->getRank();
132 auto vertex2AggId = vertex2AggId_->template getLocalView<DeviceType>();
133 auto procWinner = procWinner_ ->template getLocalView<DeviceType>();
135 typename AppendTrait<decltype(aggregateSizes_), Kokkos::Atomic>::type aggregateSizesAtomic = aggregateSizes;
137 ComputeAggregateSizesFunctor<decltype(procWinner), decltype(vertex2AggId), decltype(aggregateSizesAtomic), LO>
138 computeAggSizesFunctor(procWinner, vertex2AggId, myPID, aggregateSizesAtomic);
139 Kokkos::parallel_for(
"MueLu:Aggregates:ComputeAggregateSizes:for", procWinner.size(), computeAggSizesFunctor);
142 aggregateSizes_ = aggregateSizes;
144 return aggregateSizes;
149 template <
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
150 typename Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::local_graph_type
151 Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::GetGraph()
const {
152 typedef typename local_graph_type::row_map_type row_map_type;
153 typedef typename local_graph_type::entries_type entries_type;
155 int myPID = GetMap()->getComm()->getRank();
157 ArrayRCP<LO> vertex2AggId = vertex2AggId_->getDataNonConst(0);
158 ArrayRCP<LO> procWinner = procWinner_->getDataNonConst(0);
160 typename aggregates_sizes_type::const_type sizes = ComputeAggregateSizes();
162 int numAggregates = nAggregates_;
164 typename row_map_type::non_const_type rows(
"row_map", numAggregates+1);
165 for (
LO i = 0; i < nAggregates_; i++)
166 rows(i+1) = rows(i) + sizes(i);
168 aggregates_sizes_type offsets(
"offsets", numAggregates);
169 for (
LO i = 0; i < numAggregates; i++)
170 offsets(i) = rows(i);
172 typename entries_type::non_const_type cols(
"entries", rows(nAggregates_));
173 for (
LO i = 0; i < procWinner.size(); i++)
174 if (procWinner[i] == myPID)
175 cols(offsets(vertex2AggId[i])++) = i;
177 return local_graph_type(cols, rows);
180 template <
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
181 std::string Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::description()
const {
185 template <
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
186 void Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::print(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const {
190 out0 <<
"Global number of aggregates: " << GetNumGlobalAggregates() << std::endl;
193 template <
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
194 GlobalOrdinal Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType> >::GetNumGlobalAggregates()
const {
195 LO nAggregates = GetNumAggregates();
196 GO nGlobalAggregates;
197 MueLu_sumAll(vertex2AggId_->getMap()->getComm(), (
GO)nAggregates, nGlobalAggregates);
198 return nGlobalAggregates;
201 template <
class LocalOrdinal,
class GlobalOrdinal,
class DeviceType>
202 const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>> >
203 Aggregates_kokkos<LocalOrdinal, GlobalOrdinal, Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>>::GetMap()
const {
204 return vertex2AggId_->getMap();
209 #endif // MUELU_AGGREGATES_KOKKOS_DEF_HPP
#define MueLu_sumAll(rcpComm, in, out)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
ComputeAggregateSizesFunctor(ProcWinnerType procWinner_, Vertex2AggIdType vertex2AggId_, int myPID_, AggregateSizesType aggregateSizes_)
Namespace for MueLu classes and methods.
Vertex2AggIdType vertex2AggId
#define MUELU_UNAGGREGATED
AggregateSizesType aggregateSizes
KOKKOS_INLINE_FUNCTION void operator()(const LO k) const
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
ProcWinnerType procWinner
virtual std::string description() const
Return a simple one-line description of this object.