10#ifndef MUELU_DROPPINGCOMMON_HPP
11#define MUELU_DROPPINGCOMMON_HPP
15#include "Kokkos_Core.hpp"
16#include "KokkosKernels_ArithTraits.hpp"
17#include "Tpetra_Access.hpp"
18#include "Xpetra_Matrix.hpp"
19#include "Xpetra_VectorFactory.hpp"
20#include "MueLu_Utilities.hpp"
38template <
class local_ordinal_type>
43 KOKKOS_FORCEINLINE_FUNCTION
52template <
class local_matrix_type>
71 KOKKOS_FORCEINLINE_FUNCTION
73 auto row =
A.rowConst(rlid);
74 const size_t offset =
A.graph.row_map(rlid);
78 auto clid = row.colidx(k);
90template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 using local_matrix_type =
typename Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_matrix_device_type;
109 A = A_.getLocalMatrixDevice();
110 auto boundaryNodesColumn =
typename boundary_nodes_view::non_const_type(
"boundaryNodesColumn", A_.getColMap()->getLocalNumElements());
111 auto boundaryNodesDomain =
typename boundary_nodes_view::non_const_type(
"boundaryNodesDomain", A_.getDomainMap()->getLocalNumElements());
116 KOKKOS_FORCEINLINE_FUNCTION
118 auto row =
A.rowConst(rlid);
119 const size_t offset =
A.graph.row_map(rlid);
122 auto clid = row.colidx(k);
134template <
class local_matrix_type>
156 KOKKOS_FORCEINLINE_FUNCTION
158 auto row =
A.rowConst(rlid);
159 const size_t offset =
A.graph.row_map(rlid);
163 auto clid = row.colidx(k);
175template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
178 using local_matrix_type =
typename Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_matrix_device_type;
199 A = A_.getLocalMatrixDevice();
200 auto boundaryNodesColumn =
typename boundary_nodes_view::non_const_type(
"boundaryNodesColumn", A_.getColMap()->getLocalNumElements());
201 auto boundaryNodesDomain =
typename boundary_nodes_view::non_const_type(
"boundaryNodesDomain", A_.getDomainMap()->getLocalNumElements());
206 KOKKOS_FORCEINLINE_FUNCTION
208 auto row =
A.rowConst(rlid);
209 const size_t offset =
A.graph.row_map(rlid);
212 auto clid = row.colidx(k);
225template <
class local_matrix_type>
241 KOKKOS_FORCEINLINE_FUNCTION
243 auto row =
A.rowConst(rlid);
244 const size_t offset =
A.graph.row_map(rlid);
246 auto clid = row.colidx(k);
259template <
class local_matrix_type>
275 KOKKOS_FORCEINLINE_FUNCTION
277 auto row =
A.rowConst(rlid);
278 const size_t offset =
A.graph.row_map(rlid);
280 auto clid = row.colidx(k);
281 if (clid >=
A.numRows()) {
292template <
class local_matrix_type>
312 KOKKOS_FORCEINLINE_FUNCTION
314 auto row =
A.rowConst(rlid);
315 const size_t offset =
A.graph.row_map(rlid);
317 auto clid = row.colidx(k);
318 if ((
results(offset + k) ==
KEEP) && (rlid != clid))
323 auto clid = row.colidx(k);
336template <
class local_matrix_type>
359 KOKKOS_FORCEINLINE_FUNCTION
361 auto row =
A.rowConst(rlid);
362 const size_t offset =
A.graph.row_map(rlid);
364 auto clid = row.colidx(k);
365 if ((
results(offset + k) ==
KEEP) && (rlid != clid))
371 auto clid = row.colidx(k);
384template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
387 using matrix_type = Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
406 :
A(A_.getLocalMatrixDevice())
407 ,
point_to_block(point_to_block_.getLocalViewDevice(Tpetra::Access::ReadOnly))
409 auto importer = A_.getCrsGraph()->getImporter();
411 if (!importer.is_null()) {
412 ghosted_point_to_blockMV = Xpetra::VectorFactory<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>::Build(importer->getTargetMap(), false);
413 ghosted_point_to_blockMV->doImport(point_to_block_, *importer, Xpetra::INSERT);
414 ghosted_point_to_block = ghosted_point_to_blockMV->getLocalViewDevice(Tpetra::Access::ReadOnly);
419 KOKKOS_FORCEINLINE_FUNCTION
421 auto row =
A.rowConst(rlid);
422 const size_t offset =
A.graph.row_map(rlid);
424 auto clid = row.colidx(k);
438template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
441 using matrix_type = Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
464 :
A(A_.getLocalMatrixDevice())
465 ,
point_to_block(point_to_block_.getLocalViewDevice(Tpetra::Access::ReadOnly))
469 if (!importer.is_null()) {
470 ghosted_point_to_blockMV = Xpetra::VectorFactory<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node>::Build(importer->getTargetMap(), false);
471 ghosted_point_to_blockMV->doImport(point_to_block_, *importer, Xpetra::INSERT);
472 ghosted_point_to_block = ghosted_point_to_blockMV->getLocalViewDevice(Tpetra::Access::ReadOnly);
477 KOKKOS_FORCEINLINE_FUNCTION
479 auto row =
A.rowConst(rlid);
480 const size_t offset =
A.graph.row_map(rlid);
483 auto clid = row.colidx(k);
498template <
class local_matrix_type>
516 KOKKOS_FORCEINLINE_FUNCTION
518 auto row =
A.rowConst(rlid);
519 const size_t offset =
A.graph.row_map(rlid);
522 Kokkos::printf(
"No dropping decision was taken for entry (%d, %d)\n", rlid, row.colidx(k));
533template <
class local_matrix_type,
bool weakWins = false,
bool offdiagNnzsCanBeReducedToZero = false>
540 using ATS = KokkosKernels::ArithTraits<scalar_type>;
542 using impl_ATS = KokkosKernels::ArithTraits<impl_SC>;
543 using magATS = KokkosKernels::ArithTraits<typename impl_ATS::magnitudeType>;
553 KOKKOS_FORCEINLINE_FUNCTION
555 auto row =
A.rowConst(rlid);
556 const size_t offset =
A.graph.row_map(rlid);
558 bool hadOffdiagKeep =
false;
561 auto clid = row.colidx(k);
563 if constexpr (weakWins && !offdiagNnzsCanBeReducedToZero) {
564 if (!hadOffdiagKeep && clid != rlid &&
results(offset + k) ==
KEEP) {
565 hadOffdiagKeep =
true;
568 if (clid >=
A.numRows())
570 auto row2 =
A.rowConst(clid);
571 const size_t offset2 =
A.graph.row_map(clid);
573 auto clid2 = row2.colidx(k2);
576 if constexpr (weakWins) {
577 if constexpr (!offdiagNnzsCanBeReducedToZero) {
592 if constexpr (weakWins && !offdiagNnzsCanBeReducedToZero) {
593 if (hadOffdiagKeep) {
594 bool hasOffdiagKeepNow =
false;
596 typename impl_ATS::magnitudeType rescueVal = magATS::zero();
599 const auto clid = row.colidx(k);
600 if (clid == rlid)
continue;
602 const auto d =
results(offset + k);
604 hasOffdiagKeepNow =
true;
609 auto temp = impl_ATS::magnitude(row.value(k));
610 if (temp >= rescueVal) {
618 if (!hasOffdiagKeepNow && rescueK >= 0) {
629template <
class view_type,
class comparator_type>
630KOKKOS_INLINE_FUNCTION
void serialHeapSort(view_type& v, comparator_type comparator) {
631 auto N = v.extent(0);
632 size_t start = N / 2;
644 while (2 * root + 1 < end) {
645 size_t child = 2 * root + 1;
646 if ((child + 1 < end) and (comparator(v(child), v(child + 1))))
649 if (comparator(v(root), v(child))) {
695#define MUELU_ETI_SLGN_SoC(CLASSNAME, SC, LO, GO, NO) \
696 template class CLASSNAME<SC, LO, GO, NO, MueLu::Misc::SmoothedAggregationMeasure>; \
697 template class CLASSNAME<SC, LO, GO, NO, MueLu::Misc::SignedRugeStuebenMeasure>; \
698 template class CLASSNAME<SC, LO, GO, NO, MueLu::Misc::SignedSmoothedAggregationMeasure>; \
699 template class CLASSNAME<SC, LO, GO, NO, MueLu::Misc::UnscaledMeasure>;
Teuchos::RCP< block_indices_type > ghosted_point_to_blockMV
typename matrix_type::local_matrix_device_type local_matrix_type
Xpetra::MultiVector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > block_indices_type
typename local_matrix_type::value_type scalar_type
local_block_indices_view_type point_to_block
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > matrix_type
local_block_indices_view_type ghosted_point_to_block
typename block_indices_type::dual_view_type_const::t_dev local_block_indices_view_type
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
typename local_matrix_type::memory_space memory_space
typename local_matrix_type::ordinal_type local_ordinal_type
Kokkos::View< DecisionType *, memory_space > results_view
BlockDiagonalizeFunctor(matrix_type &A_, block_indices_type &point_to_block_, results_view &results_)
Xpetra::Vector< LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node > block_indices_type
id_translation_type col_translation
typename local_matrix_type::memory_space memory_space
Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > importer_type
typename block_indices_type::dual_view_type_const::t_dev local_block_indices_view_type
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > matrix_type
BlockDiagonalizeVectorFunctor(matrix_type &A_, block_indices_type &point_to_block_, const RCP< const importer_type > &importer, results_view &results_, id_translation_type row_translation_, id_translation_type col_translation_)
id_translation_type row_translation
typename local_matrix_type::value_type scalar_type
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
Kokkos::View< DecisionType *, memory_space > results_view
local_block_indices_view_type point_to_block
typename local_matrix_type::ordinal_type local_ordinal_type
Teuchos::RCP< block_indices_type > ghosted_point_to_blockMV
Kokkos::View< local_ordinal_type *, memory_space > id_translation_type
typename matrix_type::local_matrix_device_type local_matrix_type
local_block_indices_view_type ghosted_point_to_block
Kokkos::View< DecisionType *, memory_space > results_view
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
DebugFunctor(local_matrix_type &A_, results_view &results_)
typename local_matrix_type::ordinal_type local_ordinal_type
Kokkos::View< bool *, memory_space > boundary_nodes_view
typename local_matrix_type::value_type scalar_type
typename local_matrix_type::memory_space memory_space
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
Kokkos::View< DecisionType *, memory_space > results_view
typename local_matrix_type::ordinal_type local_ordinal_type
typename local_matrix_type::memory_space memory_space
typename local_matrix_type::value_type scalar_type
DropOffRankFunctor(local_matrix_type &A_, results_view &results_)
Kokkos::View< DecisionType *, memory_space > results_view
typename local_matrix_type::memory_space memory_space
KeepDiagonalFunctor(local_matrix_type &A_, results_view &results_)
typename local_matrix_type::ordinal_type local_ordinal_type
typename local_matrix_type::value_type scalar_type
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
Kokkos::View< DecisionType *, memory_space > results_view
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
typename local_matrix_type::value_type scalar_type
MarkSingletonFunctor(local_matrix_type &A_, boundary_nodes_view boundaryNodes_, results_view &results_)
typename local_matrix_type::memory_space memory_space
boundary_nodes_view boundaryNodes
typename local_matrix_type::ordinal_type local_ordinal_type
Kokkos::View< bool *, memory_space > boundary_nodes_view
MarkSingletonVectorFunctor(local_matrix_type &A_, block_indices_view_type point_to_block_, boundary_nodes_view boundaryNodes_, results_view &results_)
Kokkos::View< DecisionType *, memory_space > results_view
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
typename local_matrix_type::value_type scalar_type
Kokkos::View< local_ordinal_type *, memory_space > block_indices_view_type
typename local_matrix_type::ordinal_type local_ordinal_type
Kokkos::View< bool *, memory_space > boundary_nodes_view
typename local_matrix_type::memory_space memory_space
block_indices_view_type point_to_block
boundary_nodes_view boundaryNodes
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
typename local_matrix_type::ordinal_type local_ordinal_type
typename local_matrix_type::memory_space memory_space
Kokkos::View< const bool *, memory_space > boundary_nodes_view
boundary_nodes_view boundaryNodes
typename local_matrix_type::value_type scalar_type
Kokkos::View< DecisionType *, memory_space > results_view
PointwiseDropBoundaryFunctor(local_matrix_type &A_, boundary_nodes_view boundaryNodes_, results_view &results_)
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
Kokkos::View< DecisionType *, memory_space > results_view
boundary_nodes_view boundaryNodes
typename Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_device_type local_matrix_type
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
typename local_matrix_type::value_type scalar_type
boundary_nodes_view boundaryNodesCol
typename local_matrix_type::ordinal_type local_ordinal_type
Kokkos::View< bool *, memory_space > boundary_nodes_view
typename local_matrix_type::memory_space memory_space
PointwiseSymmetricDropBoundaryFunctor(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A_, boundary_nodes_view boundaryNodes_, results_view &results_)
KokkosKernels::ArithTraits< typename impl_ATS::magnitudeType > magATS
KokkosKernels::ArithTraits< scalar_type > ATS
SymmetrizeFunctor(local_matrix_type &A_, results_view &results_)
typename local_matrix_type::memory_space memory_space
KokkosKernels::ArithTraits< impl_SC > impl_ATS
typename ATS::val_type impl_SC
typename local_matrix_type::value_type scalar_type
typename local_matrix_type::ordinal_type local_ordinal_type
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
Kokkos::View< DecisionType *, memory_space > results_view
VectorDropBoundaryFunctor(local_matrix_type &A_, block_indices_view_type point_to_block_, boundary_nodes_view boundaryNodes_, results_view &results_)
block_indices_view_type point_to_block
Kokkos::View< local_ordinal_type *, memory_space > block_indices_view_type
Kokkos::View< const bool *, memory_space > boundary_nodes_view
typename local_matrix_type::memory_space memory_space
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
typename local_matrix_type::ordinal_type local_ordinal_type
Kokkos::View< DecisionType *, memory_space > results_view
boundary_nodes_view boundaryNodes
typename local_matrix_type::value_type scalar_type
boundary_nodes_view boundaryNodes
block_indices_view_type point_to_block
typename local_matrix_type::value_type scalar_type
typename local_matrix_type::memory_space memory_space
typename Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_device_type local_matrix_type
KOKKOS_FORCEINLINE_FUNCTION void operator()(local_ordinal_type rlid) const
Kokkos::View< bool *, memory_space > boundary_nodes_view
Kokkos::View< DecisionType *, memory_space > results_view
boundary_nodes_view boundaryNodesCol
VectorSymmetricDropBoundaryFunctor(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A_, block_indices_view_type point_to_block_, block_indices_view_type ghosted_point_to_block_, boundary_nodes_view boundaryNodes_, results_view &results_)
Kokkos::View< local_ordinal_type *, memory_space > block_indices_view_type
typename local_matrix_type::ordinal_type local_ordinal_type
block_indices_view_type ghosted_point_to_block
static void DetectDirichletColsAndDomains(const Xpetra::Matrix< Scalar, DefaultLocalOrdinal, DefaultGlobalOrdinal, DefaultNode > &A, const Teuchos::ArrayRCP< bool > &dirichletRows, Teuchos::ArrayRCP< bool > dirichletCols, Teuchos::ArrayRCP< bool > dirichletDomain)
KOKKOS_INLINE_FUNCTION void serialHeapSort(view_type &v, comparator_type comparator)
@ SignedSmoothedAggregationMeasure
@ SignedRugeStuebenMeasure
@ SmoothedAggregationMeasure
Namespace for MueLu classes and methods.