118 if (aggregateSizes_.size() && !forceRecompute) {
119 return aggregateSizes_;
125 int myPID = GetMap()->getComm()->getRank();
127 auto vertex2AggId = vertex2AggId_->getDeviceLocalView(Xpetra::Access::ReadOnly);
128 auto procWinner = procWinner_ ->getDeviceLocalView(Xpetra::Access::ReadOnly);
130 typename AppendTrait<
decltype(aggregateSizes_), Kokkos::Atomic>::type aggregateSizesAtomic = aggregateSizes;
131 Kokkos::parallel_for(
"MueLu:Aggregates:ComputeAggregateSizes:for",
range_type(0,procWinner.size()),
132 KOKKOS_LAMBDA(
const LO i) {
133 if (procWinner(i, 0) == myPID)
134 aggregateSizesAtomic(vertex2AggId(i, 0))++;
137 aggregateSizes_ = aggregateSizes;
139 return aggregateSizes;
147 ComputeAggregateSizesArrayRCP(
bool forceRecompute)
const {
148 auto aggregateSizes = this->ComputeAggregateSizes(forceRecompute);
151 if(!aggregateSizesHost_.is_allocated()) {
152 aggregateSizesHost_ = Kokkos::create_mirror_view(aggregateSizes);
153 Kokkos::deep_copy(aggregateSizesHost_, aggregateSizes);
157 Kokkos::deep_copy(aggregateSizesHost_, aggregateSizes);
161 Teuchos::ArrayRCP<LocalOrdinal> aggregateSizesArrayRCP(aggregateSizesHost_.data(),0,aggregateSizesHost_.extent(0),
false);
163 return aggregateSizesArrayRCP;
169 using row_map_type =
typename local_graph_type::row_map_type;
170 using entries_type =
typename local_graph_type::entries_type;
171 using size_type =
typename local_graph_type::size_type;
173 auto numAggregates = numAggregates_;
175 if (
static_cast<LO
>(graph_.numRows()) == numAggregates)
178 auto vertex2AggId = vertex2AggId_->getDeviceLocalView(Xpetra::Access::ReadOnly);
179 auto procWinner = procWinner_ ->getDeviceLocalView(Xpetra::Access::ReadOnly);
180 auto sizes = ComputeAggregateSizes();
183 typename row_map_type::non_const_type
rows(
"Agg_rows", numAggregates+1);
186 Kokkos::parallel_scan(
"MueLu:Aggregates:GetGraph:compute_rows",
range_type(0, numAggregates),
187 KOKKOS_LAMBDA(
const LO i, LO& update,
const bool& final_pass) {
193 decltype(
rows) offsets(Kokkos::ViewAllocateWithoutInitializing(
"Agg_offsets"), numAggregates+1);
194 Kokkos::deep_copy(offsets,
rows);
196 int myPID = GetMap()->getComm()->getRank();
200 Kokkos::View<size_type, device_type> numNNZ_device = Kokkos::subview(
rows, numAggregates);
201 typename Kokkos::View<size_type, device_type>::HostMirror numNNZ_host = Kokkos::create_mirror_view(numNNZ_device);
202 Kokkos::deep_copy(numNNZ_host, numNNZ_device);
203 numNNZ = numNNZ_host();
205 typename entries_type::non_const_type cols(Kokkos::ViewAllocateWithoutInitializing(
"Agg_cols"), numNNZ);
207 Kokkos::parallel_reduce(
"MueLu:Aggregates:GetGraph:compute_cols",
range_type(0, procWinner.size()),
208 KOKKOS_LAMBDA(
const LO i,
size_t& nnz) {
209 if (procWinner(i, 0) == myPID) {
210 typedef typename std::remove_reference<
decltype( offsets(0) ) >::type atomic_incr_type;
211 auto idx = Kokkos::atomic_fetch_add( &offsets(vertex2AggId(i,0)), atomic_incr_type(1));
217 "MueLu: Internal error: Something is wrong with aggregates graph construction: numNNZ = " << numNNZ <<
" != " << realnnz <<
" = realnnz");
227 LO numAggs = GetNumAggregates();
228 LO numNodes = vertex2AggId_->getLocalLength();
229 auto vertex2AggId = vertex2AggId_->getDeviceLocalView(Xpetra::Access::ReadOnly);
230 typename aggregates_sizes_type::const_type aggSizes = ComputeAggregateSizes(
true);
231 LO INVALID = Teuchos::OrdinalTraits<LO>::invalid();
233 aggPtr =
LO_view(
"aggPtr",numAggs+1);
234 aggNodes =
LO_view(
"aggNodes",numNodes);
235 LO_view aggCurr(
"agg curr",numAggs+1);
238 Kokkos::parallel_scan(
"MueLu:Aggregates:ComputeNodesInAggregate:scan",
range_type(0,numAggs+1),
239 KOKKOS_LAMBDA(
const LO aggIdx, LO& aggOffset,
bool final_pass) {
242 count = aggSizes(aggIdx);
244 aggPtr(aggIdx) = aggOffset;
245 aggCurr(aggIdx) = aggOffset;
247 aggCurr(numAggs) = 0;
253 LO numUnaggregated = 0;
254 Kokkos::parallel_reduce(
"MueLu:Aggregates:ComputeNodesInAggregate:unaggregatedSize",
range_type(0,numNodes),
255 KOKKOS_LAMBDA(
const LO nodeIdx, LO & count) {
256 if(vertex2AggId(nodeIdx,0)==INVALID)
259 unaggregated =
LO_view(
"unaggregated",numUnaggregated);
262 Kokkos::parallel_for(
"MueLu:Aggregates:ComputeNodesInAggregate:for",
range_type(0,numNodes),
263 KOKKOS_LAMBDA(
const LO nodeIdx) {
264 LO aggIdx = vertex2AggId(nodeIdx,0);
265 if(aggIdx != INVALID) {
267 aggNodes(Kokkos::atomic_fetch_add(&aggCurr(aggIdx),1)) = nodeIdx;
270 unaggregated(Kokkos::atomic_fetch_add(&aggCurr(numAggs),1)) = nodeIdx;
305 const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal, Tpetra::KokkosCompat::KokkosDeviceWrapperNode<DeviceType>> >