10 #ifndef MUELU_TENTATIVEPFACTORY_KOKKOS_DEF_HPP
11 #define MUELU_TENTATIVEPFACTORY_KOKKOS_DEF_HPP
13 #include "Kokkos_UnorderedMap.hpp"
18 #include "MueLu_Aggregates.hpp"
19 #include "MueLu_AmalgamationInfo.hpp"
22 #include "MueLu_PerfUtils.hpp"
31 template <
class LocalOrdinal,
class View>
32 class ReduceMaxFunctor {
34 ReduceMaxFunctor(View view)
37 KOKKOS_INLINE_FUNCTION
43 KOKKOS_INLINE_FUNCTION
50 KOKKOS_INLINE_FUNCTION
60 template <
class LOType,
class GOType,
class SCType,
class DeviceType,
class NspType,
class aggRowsType,
class maxAggDofSizeType,
class agg2RowMapLOType,
class statusType,
class rowsType,
class rowsAuxType,
class colsAuxType,
class valsAuxType>
61 class LocalQRDecompFunctor {
67 typedef typename DeviceType::execution_space execution_space;
68 typedef typename Kokkos::ArithTraits<SC>::val_type impl_SC;
69 typedef Kokkos::ArithTraits<impl_SC> impl_ATS;
70 typedef typename impl_ATS::magnitudeType Magnitude;
72 typedef Kokkos::View<impl_SC**, typename execution_space::scratch_memory_space, Kokkos::MemoryUnmanaged> shared_matrix;
73 typedef Kokkos::View<impl_SC*, typename execution_space::scratch_memory_space, Kokkos::MemoryUnmanaged> shared_vector;
89 LocalQRDecompFunctor(NspType fineNS_, NspType coarseNS_, aggRowsType aggRows_, maxAggDofSizeType maxAggDofSize_, agg2RowMapLOType agg2RowMapLO_, statusType statusAtomic_, rowsType rows_, rowsAuxType rowsAux_, colsAuxType colsAux_, valsAuxType valsAux_,
bool doQRStep_)
102 KOKKOS_INLINE_FUNCTION
103 void operator()(
const typename Kokkos::TeamPolicy<execution_space>::member_type& thread,
size_t& nnz)
const {
104 auto agg = thread.league_rank();
109 const impl_SC one = impl_ATS::one();
110 const impl_SC two = one + one;
111 const impl_SC zero = impl_ATS::zero();
112 const auto zeroM = impl_ATS::magnitude(zero);
122 shared_matrix r(thread.team_shmem(), m, n);
123 for (
int j = 0; j < n; j++)
124 for (
int k = 0; k < m; k++)
128 for (
int i = 0; i < m; i++) {
129 for (
int j = 0; j < n; j++)
130 printf(
" %5.3lf ", r(i,j));
136 shared_matrix q(thread.team_shmem(), m, m);
138 bool isSingular =
false;
142 for (
int i = 0; i < m; i++) {
143 for (
int j = 0; j < m; j++)
148 for (
int k = 0; k < n; k++) {
150 Magnitude s = zeroM, norm, norm_x;
151 for (
int i = k + 1; i < m; i++)
152 s += pow(impl_ATS::magnitude(r(i, k)), 2);
153 norm = sqrt(pow(impl_ATS::magnitude(r(k, k)), 2) + s);
160 r(k, k) -= norm * one;
162 norm_x = sqrt(pow(impl_ATS::magnitude(r(k, k)), 2) + s);
163 if (norm_x == zeroM) {
166 r(k, k) = norm * one;
171 for (
int i = k; i < m; i++)
175 for (
int j = k + 1; j < n; j++) {
178 for (
int i = k; i < m; i++)
179 si += r(i, k) * r(i, j);
180 for (
int i = k; i < m; i++)
181 r(i, j) -= two * si * r(i, k);
185 for (
int j = k; j < m; j++) {
188 for (
int i = k; i < m; i++)
189 si += r(i, k) * qt(i, j);
190 for (
int i = k; i < m; i++)
191 qt(i, j) -= two * si * r(i, k);
195 r(k, k) = norm * one;
196 for (
int i = k + 1; i < m; i++)
202 for (
int i = 0; i < m; i++)
203 for (
int j = 0; j < i; j++) {
204 impl_SC tmp = qt(i,j);
211 for (
int j = 0; j < n; j++)
212 for (
int k = 0; k <= j; k++)
251 for (
int j = 0; j < n; j++)
252 for (
int k = 0; k < n; k++)
256 coarseNS(offset + k, j) = (k == j ? one : zero);
259 for (
int i = 0; i < m; i++)
260 for (
int j = 0; j < n; j++)
261 q(i, j) = (j == i ? one : zero);
265 for (
int j = 0; j < m; j++) {
267 size_t rowStart =
rowsAux(localRow);
269 for (
int k = 0; k < n; k++) {
271 if (q(j, k) != zero) {
272 colsAux(rowStart + lnnz) = offset + k;
273 valsAux(rowStart + lnnz) = q(j, k);
277 rows(localRow + 1) = lnnz;
283 for (
int i = 0; i < m; i++) {
284 for (
int j = 0; j < n; j++)
290 for (
int i = 0; i < aggSize; i++) {
291 for (
int j = 0; j < aggSize; j++)
292 printf(
" %5.3lf ", q(i,j));
306 for (
int j = 0; j < m; j++) {
308 size_t rowStart =
rowsAux(localRow);
310 for (
int k = 0; k < n; k++) {
311 const impl_SC qr_jk =
fineNS(localRow, k);
314 colsAux(rowStart + lnnz) = offset + k;
315 valsAux(rowStart + lnnz) = qr_jk;
319 rows(localRow + 1) = lnnz;
323 for (
int j = 0; j < n; j++)
329 size_t team_shmem_size(
int )
const {
333 return shared_matrix::shmem_size(m, n) +
334 shared_matrix::shmem_size(m, m);
342 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
346 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
349 #undef SET_VALID_ENTRY
354 validParamList->
set<
RCP<const FactoryBase>>(
"Scaled Nullspace", Teuchos::null,
"Generating factory of the scaled nullspace");
355 validParamList->
set<
RCP<const FactoryBase>>(
"UnAmalgamationInfo", Teuchos::null,
"Generating factory of UnAmalgamationInfo");
358 validParamList->
set<
RCP<const FactoryBase>>(
"Node Comm", Teuchos::null,
"Generating factory of the node level communicator");
362 norecurse.disableRecursiveValidation();
363 validParamList->
set<
ParameterList>(
"matrixmatrix: kernel params", norecurse,
"MatrixMatrix kernel parameters");
365 return validParamList;
368 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
372 std::string nspName =
"Nullspace";
373 if (pL.
isParameter(
"Nullspace name")) nspName = pL.
get<std::string>(
"Nullspace name");
375 Input(fineLevel,
"A");
376 Input(fineLevel,
"Aggregates");
377 Input(fineLevel, nspName);
378 Input(fineLevel,
"UnAmalgamationInfo");
379 Input(fineLevel,
"CoarseMap");
382 pL.
get<
bool>(
"tentative: build coarse coordinates")) {
383 bTransferCoordinates_ =
true;
384 Input(fineLevel,
"Coordinates");
385 }
else if (bTransferCoordinates_) {
386 Input(fineLevel,
"Coordinates");
390 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
392 return BuildP(fineLevel, coarseLevel);
395 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
402 std::string nspName =
"Nullspace";
403 if (pL.
isParameter(
"Nullspace name")) nspName = pL.
get<std::string>(
"Nullspace name");
405 auto A = Get<RCP<Matrix>>(fineLevel,
"A");
406 auto aggregates = Get<RCP<Aggregates>>(fineLevel,
"Aggregates");
407 auto amalgInfo = Get<RCP<AmalgamationInfo>>(fineLevel,
"UnAmalgamationInfo");
408 auto fineNullspace = Get<RCP<MultiVector>>(fineLevel, nspName);
409 auto coarseMap = Get<RCP<const Map>>(fineLevel,
"CoarseMap");
411 if (bTransferCoordinates_) {
412 fineCoords = Get<RCP<RealValuedMultiVector>>(fineLevel,
"Coordinates");
418 if (aggregates->GetNumGlobalAggregatesComputeIfNeeded() == 0) {
419 Ptentative = Teuchos::null;
420 Set(coarseLevel,
"P", Ptentative);
426 if (bTransferCoordinates_) {
428 using array_type =
typename Map::global_indices_array_device_type;
431 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
432 blkSize = rcp_dynamic_cast<
const StridedMap>(coarseMap)->getFixedBlockSize();
437 coarseCoordMap = coarseMap;
443 using range_policy = Kokkos::RangePolicy<typename Node::execution_space>;
444 array_type elementAList = coarseMap->getMyGlobalIndicesDevice();
445 GO indexBase = coarseMap->getIndexBase();
446 auto numElements = elementAList.size() / blkSize;
447 typename array_type::non_const_type elementList_nc(
"elementList", numElements);
450 Kokkos::parallel_for(
451 "Amalgamate Element List", range_policy(0, numElements), KOKKOS_LAMBDA(
LO i) {
452 elementList_nc[i] = (elementAList[i * blkSize] - indexBase) / blkSize + indexBase;
454 array_type elementList = elementList_nc;
456 elementList, indexBase, coarseMap->getComm());
459 coarseCoords = RealValuedMultiVectorFactory::Build(coarseCoordMap, fineCoords->getNumVectors());
462 auto uniqueMap = fineCoords->getMap();
464 if (aggregates->AggregatesCrossProcessors()) {
465 auto nonUniqueMap = aggregates->GetMap();
466 auto importer = ImportFactory::Build(uniqueMap, nonUniqueMap);
468 ghostedCoords = RealValuedMultiVectorFactory::Build(nonUniqueMap, fineCoords->getNumVectors());
474 auto aggGraph = aggregates->GetGraph();
475 auto numAggs = aggGraph.numRows();
477 auto fineCoordsView = fineCoords->getDeviceLocalView(Xpetra::Access::ReadOnly);
478 auto coarseCoordsView = coarseCoords->getDeviceLocalView(Xpetra::Access::OverwriteAll);
484 const auto dim = fineCoords->getNumVectors();
487 for (
size_t j = 0; j < dim; j++) {
488 Kokkos::parallel_for(
489 "MueLu::TentativeP::BuildCoords", Kokkos::RangePolicy<local_ordinal_type, execution_space>(0, numAggs),
490 KOKKOS_LAMBDA(
const LO i) {
494 auto aggregate = aggGraph.rowConst(i);
496 coordinate_type sum = 0.0;
497 for (
size_t colID = 0; colID < static_cast<size_t>(aggregate.length); colID++)
498 sum += fineCoordsRandomView(aggregate(colID), j);
500 coarseCoordsView(i, j) = sum / aggregate.length;
506 if (!aggregates->AggregatesCrossProcessors()) {
508 BuildPuncoupledBlockCrs(coarseLevel, A, aggregates, amalgInfo, fineNullspace, coarseMap, Ptentative, coarseNullspace,
511 BuildPuncoupled(coarseLevel, A, aggregates, amalgInfo, fineNullspace, coarseMap, Ptentative, coarseNullspace, coarseLevel.
GetLevelID());
514 BuildPcoupled(A, aggregates, amalgInfo, fineNullspace, coarseMap, Ptentative, coarseNullspace);
524 if (A->IsView(
"stridedMaps") ==
true)
525 Ptentative->CreateView(
"stridedMaps", A->getRowMap(
"stridedMaps"), coarseMap);
527 Ptentative->CreateView(
"stridedMaps", Ptentative->getRangeMap(), coarseMap);
529 if (bTransferCoordinates_) {
530 Set(coarseLevel,
"Coordinates", coarseCoords);
534 if (fineLevel.IsAvailable(
"Node Comm")) {
536 Set<RCP<const Teuchos::Comm<int>>>(coarseLevel,
"Node Comm", nodeComm);
539 Set(coarseLevel,
"Nullspace", coarseNullspace);
540 Set(coarseLevel,
"P", Ptentative);
544 params->
set(
"printLoadBalancingInfo",
true);
549 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
555 auto rowMap = A->getRowMap();
556 auto colMap = A->getColMap();
558 const size_t numRows = rowMap->getLocalNumElements();
559 const size_t NSDim = fineNullspace->getNumVectors();
561 typedef Kokkos::ArithTraits<SC> ATS;
562 using impl_SC =
typename ATS::val_type;
563 using impl_ATS = Kokkos::ArithTraits<impl_SC>;
564 const impl_SC zero = impl_ATS::zero(), one = impl_ATS::one();
573 auto aggRows = aggGraph.row_map;
574 auto aggCols = aggGraph.entries;
582 goodMap = isGoodMap(*rowMap, *colMap);
586 "MueLu: TentativePFactory_kokkos: for now works only with good maps "
587 "(i.e. \"matching\" row and column maps)");
596 LO fullBlockSize, blockID, stridingOffset, stridedBlockSize;
602 auto procWinner = aggregates->
GetProcWinner()->getDeviceLocalView(Xpetra::Access::ReadOnly);
603 auto vertex2AggId = aggregates->
GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadOnly);
606 int myPID = aggregates->
GetMap()->getComm()->getRank();
611 typedef typename Aggregates::aggregates_sizes_type::non_const_type AggSizeType;
612 AggSizeType aggDofSizes;
614 if (stridedBlockSize == 1) {
618 aggDofSizes = AggSizeType(
"agg_dof_sizes", numAggregates + 1);
621 Kokkos::deep_copy(Kokkos::subview(aggDofSizes, Kokkos::make_pair(static_cast<size_t>(1), numAggregates + 1)), sizesConst);
627 aggDofSizes = AggSizeType(
"agg_dof_sizes", numAggregates + 1);
629 auto nodeMap = aggregates->
GetMap()->getLocalMap();
630 auto dofMap = colMap->getLocalMap();
632 Kokkos::parallel_for(
633 "MueLu:TentativePF:Build:compute_agg_sizes",
range_type(0, numAggregates),
634 KOKKOS_LAMBDA(
const LO agg) {
635 auto aggRowView = aggGraph.rowConst(agg);
638 for (
LO colID = 0; colID < aggRowView.length; colID++) {
639 GO nodeGID = nodeMap.getGlobalElement(aggRowView(colID));
641 for (
LO k = 0; k < stridedBlockSize; k++) {
642 GO dofGID = (nodeGID - indexBase) * fullBlockSize + k + indexBase + globalOffset + stridingOffset;
644 if (dofMap.getLocalElement(dofGID) != INVALID)
648 aggDofSizes(agg + 1) = size;
655 ReduceMaxFunctor<LO, decltype(aggDofSizes)> reduceMax(aggDofSizes);
656 Kokkos::parallel_reduce(
"MueLu:TentativePF:Build:max_agg_size",
range_type(0, aggDofSizes.extent(0)), reduceMax, maxAggSize);
660 Kokkos::parallel_scan(
661 "MueLu:TentativePF:Build:aggregate_sizes:stage1_scan",
range_type(0, numAggregates + 1),
662 KOKKOS_LAMBDA(
const LO i,
LO& update,
const bool& final_pass) {
663 update += aggDofSizes(i);
665 aggDofSizes(i) = update;
670 Kokkos::View<LO*, DeviceType>
agg2RowMapLO(Kokkos::ViewAllocateWithoutInitializing(
"agg2row_map_LO"), numRows);
674 AggSizeType aggOffsets(Kokkos::ViewAllocateWithoutInitializing(
"aggOffsets"), numAggregates);
675 Kokkos::deep_copy(aggOffsets, Kokkos::subview(aggDofSizes, Kokkos::make_pair(static_cast<size_t>(0), numAggregates)));
677 Kokkos::parallel_for(
678 "MueLu:TentativePF:Build:createAgg2RowMap",
range_type(0, vertex2AggId.extent(0)),
679 KOKKOS_LAMBDA(
const LO lnode) {
680 if (procWinner(lnode, 0) == myPID) {
682 auto aggID = vertex2AggId(lnode, 0);
684 auto offset = Kokkos::atomic_fetch_add(&aggOffsets(aggID), stridedBlockSize);
688 for (
LO k = 0; k < stridedBlockSize; k++)
689 agg2RowMapLO(offset + k) = lnode * stridedBlockSize + k;
696 coarseNullspace = MultiVectorFactory::Build(coarseMap, NSDim);
699 auto fineNS = fineNullspace->getDeviceLocalView(Xpetra::Access::ReadWrite);
700 auto coarseNS = coarseNullspace->getDeviceLocalView(Xpetra::Access::OverwriteAll);
705 typedef typename local_matrix_type::row_map_type::non_const_type rows_type;
706 typedef typename local_matrix_type::index_type::non_const_type cols_type;
707 typedef typename local_matrix_type::values_type::non_const_type vals_type;
710 typedef Kokkos::View<int[10], DeviceType> status_type;
711 status_type status(
"status");
717 const bool&
doQRStep = pL.
get<
bool>(
"tentative: calculate qr");
719 GetOStream(
Runtime1) <<
"TentativePFactory : bypassing local QR phase" << std::endl;
721 GetOStream(
Warnings0) <<
"TentativePFactor : for nontrivial nullspace, this may degrade performance" << std::endl;
724 size_t nnzEstimate = numRows * NSDim;
725 rows_type
rowsAux(Kokkos::ViewAllocateWithoutInitializing(
"Ptent_aux_rows"), numRows + 1);
726 cols_type
colsAux(Kokkos::ViewAllocateWithoutInitializing(
"Ptent_aux_cols"), nnzEstimate);
727 vals_type
valsAux(
"Ptent_aux_vals", nnzEstimate);
728 rows_type
rows(
"Ptent_rows", numRows + 1);
735 Kokkos::parallel_for(
736 "MueLu:TentativePF:BuildPuncoupled:for1",
range_type(0, numRows + 1),
737 KOKKOS_LAMBDA(
const LO row) {
740 Kokkos::parallel_for(
741 "MueLu:TentativePF:BuildUncoupled:for2",
range_type(0, nnzEstimate),
742 KOKKOS_LAMBDA(
const LO j) {
759 const Kokkos::TeamPolicy<execution_space> policy(numAggregates, 1);
762 Kokkos::parallel_for(
763 "MueLu:TentativePF:BuildUncoupled:main_loop", policy,
764 KOKKOS_LAMBDA(
const typename Kokkos::TeamPolicy<execution_space>::member_type& thread) {
765 auto agg = thread.league_rank();
773 auto norm = impl_ATS::magnitude(zero);
778 for (decltype(aggSize) k = 0; k < aggSize; k++) {
780 norm += dnorm * dnorm;
794 for (decltype(aggSize) k = 0; k < aggSize; k++) {
798 rows(localRow + 1) = 1;
804 typename status_type::HostMirror statusHost = Kokkos::create_mirror_view(status);
805 Kokkos::deep_copy(statusHost, status);
806 for (decltype(statusHost.size()) i = 0; i < statusHost.size(); i++)
808 std::ostringstream oss;
809 oss <<
"MueLu::TentativePFactory::MakeTentative: ";
811 case 0: oss <<
"!goodMap is not implemented";
break;
812 case 1: oss <<
"fine level NS part has a zero column";
break;
818 Kokkos::parallel_for(
819 "MueLu:TentativePF:BuildUncoupled:main_loop_noqr", policy,
820 KOKKOS_LAMBDA(
const typename Kokkos::TeamPolicy<execution_space>::member_type& thread) {
821 auto agg = thread.league_rank();
830 for (decltype(aggSize) k = 0; k < aggSize; k++) {
834 rows(localRow + 1) = 1;
841 Kokkos::parallel_reduce(
842 "MueLu:TentativeP:CountNNZ",
range_type(0, numRows + 1),
843 KOKKOS_LAMBDA(
const LO i,
size_t& nnz_count) {
844 nnz_count +=
rows(i);
862 const Kokkos::TeamPolicy<execution_space> policy(numAggregates, 1);
864 decltype(aggDofSizes ), decltype(maxAggSize), decltype(agg2RowMapLO),
865 decltype(statusAtomic), decltype(rows), decltype(rowsAux), decltype(colsAux),
867 localQRFunctor(fineNSRandom,
coarseNS, aggDofSizes, maxAggSize, agg2RowMapLO, statusAtomic,
868 rows, rowsAux, colsAux, valsAux, doQRStep);
869 Kokkos::parallel_reduce(
"MueLu:TentativePF:BuildUncoupled:main_qr_loop", policy, localQRFunctor, nnz);
872 typename status_type::HostMirror statusHost = Kokkos::create_mirror_view(status);
873 Kokkos::deep_copy(statusHost, status);
874 for (decltype(statusHost.size()) i = 0; i < statusHost.size(); i++)
876 std::ostringstream oss;
877 oss <<
"MueLu::TentativePFactory::MakeTentative: ";
879 case 0: oss <<
"!goodMap is not implemented";
break;
880 case 1: oss <<
"fine level NS part has a zero column";
break;
893 if (nnz != nnzEstimate) {
898 Kokkos::parallel_scan(
899 "MueLu:TentativePF:Build:compress_rows",
range_type(0, numRows + 1),
900 KOKKOS_LAMBDA(
const LO i,
LO& upd,
const bool&
final) {
910 cols = cols_type(
"Ptent_cols", nnz);
911 vals = vals_type(
"Ptent_vals", nnz);
916 Kokkos::parallel_for(
917 "MueLu:TentativePF:Build:compress_cols_vals",
range_type(0, numRows),
918 KOKKOS_LAMBDA(
const LO i) {
924 cols(rowStart + lnnz) =
colsAux(j);
925 vals(rowStart + lnnz) =
valsAux(j);
937 GetOStream(
Runtime1) <<
"TentativePFactory : aggregates do not cross process boundaries" << std::endl;
943 local_matrix_type lclMatrix = local_matrix_type(
"A", numRows, coarseMap->getLocalNumElements(), nnz, vals,
rows, cols);
947 if (pL.
isSublist(
"matrixmatrix: kernel params"))
953 FCparams->set(
"compute global constants", FCparams->get(
"compute global constants",
false));
954 FCparams->set(
"Timer Label", std::string(
"MueLu::TentativeP-") +
toString(levelID));
956 auto PtentCrs = CrsMatrixFactory::Build(lclMatrix, rowMap, coarseMap, coarseMap, A->getDomainMap());
957 Ptentative =
rcp(
new CrsMatrixWrap(PtentCrs));
961 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
980 const size_t numFineBlockRows = rowMap->getLocalNumElements();
986 typedef Kokkos::ArithTraits<SC> ATS;
987 using impl_SC =
typename ATS::val_type;
988 using impl_ATS = Kokkos::ArithTraits<impl_SC>;
989 const impl_SC one = impl_ATS::one();
992 const size_t NSDim = fineNullspace->getNumVectors();
1000 auto aggRows = aggGraph.row_map;
1001 auto aggCols = aggGraph.entries;
1007 const size_t numCoarseBlockRows = coarsePointMap->getLocalNumElements() / NSDim;
1008 RCP<const Map> coarseBlockMap = MapFactory::Build(coarsePointMap->lib(),
1011 coarsePointMap->getIndexBase(),
1012 coarsePointMap->getComm());
1024 "MueLu: TentativePFactory_kokkos: for now works only with good maps "
1025 "(i.e. \"matching\" row and column maps)");
1034 LO fullBlockSize, blockID, stridingOffset, stridedBlockSize;
1040 auto procWinner = aggregates->
GetProcWinner()->getDeviceLocalView(Xpetra::Access::ReadOnly);
1041 auto vertex2AggId = aggregates->
GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadOnly);
1044 int myPID = aggregates->
GetMap()->getComm()->getRank();
1049 typedef typename Aggregates::aggregates_sizes_type::non_const_type AggSizeType;
1050 AggSizeType aggDofSizes;
1056 aggDofSizes = AggSizeType(
"agg_dof_sizes", numAggregates + 1);
1058 Kokkos::deep_copy(Kokkos::subview(aggDofSizes, Kokkos::make_pair(static_cast<size_t>(1), numAggregates + 1)), aggSizes);
1064 ReduceMaxFunctor<LO, decltype(aggDofSizes)> reduceMax(aggDofSizes);
1065 Kokkos::parallel_reduce(
"MueLu:TentativePF:Build:max_agg_size",
range_type(0, aggDofSizes.extent(0)), reduceMax, maxAggSize);
1069 Kokkos::parallel_scan(
1070 "MueLu:TentativePF:Build:aggregate_sizes:stage1_scan",
range_type(0, numAggregates + 1),
1071 KOKKOS_LAMBDA(
const LO i,
LO& update,
const bool& final_pass) {
1072 update += aggDofSizes(i);
1074 aggDofSizes(i) = update;
1079 Kokkos::View<LO*, DeviceType> aggToRowMapLO(Kokkos::ViewAllocateWithoutInitializing(
"aggtorow_map_LO"), numFineBlockRows);
1083 AggSizeType aggOffsets(Kokkos::ViewAllocateWithoutInitializing(
"aggOffsets"), numAggregates);
1084 Kokkos::deep_copy(aggOffsets, Kokkos::subview(aggDofSizes, Kokkos::make_pair(static_cast<size_t>(0), numAggregates)));
1086 Kokkos::parallel_for(
1087 "MueLu:TentativePF:Build:createAgg2RowMap",
range_type(0, vertex2AggId.extent(0)),
1088 KOKKOS_LAMBDA(
const LO lnode) {
1089 if (procWinner(lnode, 0) == myPID) {
1091 auto aggID = vertex2AggId(lnode, 0);
1093 auto offset = Kokkos::atomic_fetch_add(&aggOffsets(aggID), stridedBlockSize);
1097 for (
LO k = 0; k < stridedBlockSize; k++)
1098 aggToRowMapLO(offset + k) = lnode * stridedBlockSize + k;
1105 coarseNullspace = MultiVectorFactory::Build(coarsePointMap, NSDim);
1108 auto fineNS = fineNullspace->getDeviceLocalView(Xpetra::Access::ReadWrite);
1109 auto coarseNS = coarseNullspace->getDeviceLocalView(Xpetra::Access::OverwriteAll);
1112 typedef typename local_matrix_type::row_map_type::non_const_type rows_type;
1113 typedef typename local_matrix_type::index_type::non_const_type cols_type;
1117 typedef Kokkos::View<int[10], DeviceType> status_type;
1118 status_type status(
"status");
1124 GetOStream(
Runtime1) <<
"TentativePFactory : bypassing local QR phase" << std::endl;
1130 rows_type ia(Kokkos::ViewAllocateWithoutInitializing(
"BlockGraph_rowptr"), numFineBlockRows + 1);
1131 cols_type ja(Kokkos::ViewAllocateWithoutInitializing(
"BlockGraph_colind"), numFineBlockRows);
1133 Kokkos::parallel_for(
1134 "MueLu:TentativePF:BlockCrs:graph_init",
range_type(0, numFineBlockRows),
1135 KOKKOS_LAMBDA(
const LO j) {
1139 if (j == (
LO)numFineBlockRows - 1)
1140 ia[numFineBlockRows] = numFineBlockRows;
1144 const Kokkos::TeamPolicy<execution_space> policy(numAggregates, 1);
1145 Kokkos::parallel_for(
1146 "MueLu:TentativePF:BlockCrs:fillGraph", policy,
1147 KOKKOS_LAMBDA(
const typename Kokkos::TeamPolicy<execution_space>::member_type& thread) {
1148 auto agg = thread.league_rank();
1154 for (
LO j = 0; j < aggSize; j++) {
1156 const LO localRow = aggToRowMapLO[aggDofSizes[agg] + j];
1157 const size_t rowStart = ia[localRow];
1158 ja[rowStart] = offset;
1168 rows_type i_temp(Kokkos::ViewAllocateWithoutInitializing(
"BlockGraph_rowptr"), numFineBlockRows + 1);
1170 Kokkos::parallel_scan(
1171 "MueLu:TentativePF:BlockCrs:compress_rows",
range_type(0, numFineBlockRows),
1172 KOKKOS_LAMBDA(
const LO i,
LO& upd,
const bool&
final) {
1175 for (
auto j = ia[i]; j < ia[i + 1]; j++)
1176 if (ja[j] != INVALID)
1178 if (
final && i == (
LO)numFineBlockRows - 1)
1179 i_temp[numFineBlockRows] = upd;
1183 cols_type j_temp(Kokkos::ViewAllocateWithoutInitializing(
"BlockGraph_colind"), nnz);
1185 Kokkos::parallel_for(
1186 "MueLu:TentativePF:BlockCrs:compress_cols",
range_type(0, numFineBlockRows),
1187 KOKKOS_LAMBDA(
const LO i) {
1188 size_t rowStart = i_temp[i];
1190 for (
auto j = ia[i]; j < ia[i + 1]; j++)
1191 if (ja[j] != INVALID) {
1192 j_temp[rowStart + lnnz] = ja[j];
1201 RCP<CrsGraph> BlockGraph = CrsGraphFactory::Build(rowMap, coarseBlockMap, ia, ja);
1206 if (pL.isSublist(
"matrixmatrix: kernel params"))
1207 FCparams =
rcp(
new ParameterList(pL.sublist(
"matrixmatrix: kernel params")));
1211 FCparams->
set(
"compute global constants", FCparams->
get(
"compute global constants",
false));
1212 std::string levelIDs =
toString(levelID);
1213 FCparams->
set(
"Timer Label", std::string(
"MueLu::TentativeP-") + levelIDs);
1216 BlockGraph->expertStaticFillComplete(coarseBlockMap, rowMap, dummy_i, dummy_e, FCparams);
1228 if (P_tpetra.
is_null())
throw std::runtime_error(
"BuildPUncoupled: Matrix factory did not return a Tpetra::BlockCrsMatrix");
1231 auto values = P_tpetra->getTpetra_BlockCrsMatrix()->getValuesDeviceNonConst();
1232 const LO stride = NSDim * NSDim;
1234 Kokkos::parallel_for(
1235 "MueLu:TentativePF:BlockCrs:main_loop_noqr", policy,
1236 KOKKOS_LAMBDA(
const typename Kokkos::TeamPolicy<execution_space>::member_type& thread) {
1237 auto agg = thread.league_rank();
1244 for (
LO j = 0; j < aggSize; j++) {
1245 LO localBlockRow = aggToRowMapLO(
aggRows(agg) + j);
1246 LO rowStart = localBlockRow * stride;
1247 for (
LO r = 0; r < (
LO)NSDim; r++) {
1248 LO localPointRow = localBlockRow * NSDim + r;
1249 for (
LO c = 0; c < (
LO)NSDim; c++) {
1250 values[rowStart + r * NSDim + c] = fineNSRandom(localPointRow, c);
1256 for (
LO j = 0; j < (
LO)NSDim; j++)
1260 Ptentative = P_wrap;
1263 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1272 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1275 auto rowLocalMap = rowMap.getLocalMap();
1276 auto colLocalMap = colMap.getLocalMap();
1278 const size_t numRows = rowLocalMap.getLocalNumElements();
1279 const size_t numCols = colLocalMap.getLocalNumElements();
1281 if (numCols < numRows)
1285 Kokkos::parallel_reduce(
1286 "MueLu:TentativePF:isGoodMap",
range_type(0, numRows),
1287 KOKKOS_LAMBDA(
const LO i,
size_t& diff) {
1288 diff += (rowLocalMap.getGlobalElement(i) != colLocalMap.getGlobalElement(i));
1292 return (numDiff == 0);
1297 #define MUELU_TENTATIVEPFACTORY_KOKKOS_SHORT
1298 #endif // MUELU_TENTATIVEPFACTORY_KOKKOS_DEF_HPP
Important warning messages (one line)
void BuildPcoupled(RCP< Matrix > A, RCP< Aggregates > aggregates, RCP< AmalgamationInfo > amalgInfo, RCP< MultiVector > fineNullspace, RCP< const Map > coarseMap, RCP< Matrix > &Ptentative, RCP< MultiVector > &coarseNullspace) const
MueLu::DefaultLocalOrdinal LocalOrdinal
void BuildPuncoupledBlockCrs(Level &coarseLevel, RCP< Matrix > A, RCP< Aggregates > aggregates, RCP< AmalgamationInfo > amalgInfo, RCP< MultiVector > fineNullspace, RCP< const Map > coarseMap, RCP< Matrix > &Ptentative, RCP< MultiVector > &coarseNullspace, const int levelID) const
static bool MapsAreNested(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &rowMap, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &colMap)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const RCP< const Map > GetMap() const
returns (overlapping) map of aggregate/node distribution
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static const NoFactory * get()
Print even more statistics.
#define SET_VALID_ENTRY(name)
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void BuildPuncoupled(Level &coarseLevel, RCP< Matrix > A, RCP< Aggregates > aggregates, RCP< AmalgamationInfo > amalgInfo, RCP< MultiVector > fineNullspace, RCP< const Map > coarseMap, RCP< Matrix > &Ptentative, RCP< MultiVector > &coarseNullspace, const int levelID) const
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Kokkos::RangePolicy< local_ordinal_type, execution_space > range_type
Class that holds all level-specific information.
bool isSublist(const std::string &name) const
void GetStridingInformation(LO &fullBlockSize, LO &blockID, LO &stridingOffset, LO &stridedBlockSize, GO &indexBase)
returns striding information
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
typename LWGraph_kokkos::local_graph_type local_graph_type
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
GO GlobalOffset()
returns offset of global dof ids
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
Description of what is happening (more verbose)
bool isGoodMap(const Map &rowMap, const Map &colMap) const
maxAggDofSizeType maxAggDofSize
local_graph_type GetGraph() const
Node::device_type DeviceType
agg2RowMapLOType agg2RowMapLO
aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute=false) const
Compute sizes of aggregates.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.