10#ifndef MUELU_MATRIXCONSTRUCTION_HPP
11#define MUELU_MATRIXCONSTRUCTION_HPP
13#include "Kokkos_Core.hpp"
14#include "Kokkos_ArithTraits.hpp"
18#ifdef MUELU_COALESCE_DROP_DEBUG
34template <
class local_matrix_type,
class functor_type,
class... remaining_functor_types>
42 using rowptr_type =
typename local_matrix_type::row_map_type::non_const_type;
51#ifdef MUELU_COALESCE_DROP_DEBUG
52 std::string functorName;
63#ifdef MUELU_COALESCE_DROP_DEBUG
64 std::string mangledFunctorName =
typeid(
decltype(
functor)).name();
66 char* demangledFunctorName = 0;
67 demangledFunctorName = abi::__cxa_demangle(mangledFunctorName.c_str(), 0, 0, &status);
68 functorName = demangledFunctorName;
79#ifdef MUELU_COALESCE_DROP_DEBUG
80 std::string mangledFunctorName =
typeid(
decltype(
functor)).name();
82 char* demangledFunctorName = 0;
83 demangledFunctorName = abi::__cxa_demangle(mangledFunctorName.c_str(), 0, 0, &status);
84 functorName = demangledFunctorName;
88 KOKKOS_INLINE_FUNCTION
90#ifdef MUELU_COALESCE_DROP_DEBUG
92 Kokkos::printf(
"\nStarting on row %d\n", rlid);
94 auto row =
A.rowConst(rlid);
96 Kokkos::printf(
"indices: ");
98 auto clid = row.colidx(k);
99 Kokkos::printf(
"%5d ", clid);
101 Kokkos::printf(
"\n");
103 Kokkos::printf(
"values: ");
105 auto val = row.value(k);
106 Kokkos::printf(
"%5f ", val);
108 Kokkos::printf(
"\n");
114#ifdef MUELU_COALESCE_DROP_DEBUG
116 Kokkos::printf(
"%s\n", functorName.c_str());
118 auto row =
A.rowConst(rlid);
119 const size_t offset =
A.graph.row_map(rlid);
121 Kokkos::printf(
"decisions: ");
123 Kokkos::printf(
"%5d ",
results(offset + k));
125 Kokkos::printf(
"\n");
133template <
class local_matrix_type,
class functor_type>
141 using rowptr_type =
typename local_matrix_type::row_map_type::non_const_type;
149#ifdef MUELU_COALESCE_DROP_DEBUG
150 std::string functorName;
160#ifdef MUELU_COALESCE_DROP_DEBUG
161 std::string mangledFunctorName =
typeid(
decltype(
functor)).name();
163 char* demangledFunctorName = 0;
164 demangledFunctorName = abi::__cxa_demangle(mangledFunctorName.c_str(), 0, 0, &status);
165 functorName = demangledFunctorName;
175#ifdef MUELU_COALESCE_DROP_DEBUG
176 std::string mangledFunctorName =
typeid(
decltype(
functor)).name();
178 char* demangledFunctorName = 0;
179 demangledFunctorName = abi::__cxa_demangle(mangledFunctorName.c_str(), 0, 0, &status);
180 functorName = demangledFunctorName;
184 KOKKOS_INLINE_FUNCTION
186#ifdef MUELU_COALESCE_DROP_DEBUG
188 Kokkos::printf(
"\nStarting on row %d\n", rlid);
190 auto row =
A.rowConst(rlid);
192 Kokkos::printf(
"indices: ");
194 auto clid = row.colidx(k);
195 Kokkos::printf(
"%5d ", clid);
197 Kokkos::printf(
"\n");
199 Kokkos::printf(
"values: ");
201 auto val = row.value(k);
202 Kokkos::printf(
"%5f ", val);
204 Kokkos::printf(
"\n");
210#ifdef MUELU_COALESCE_DROP_DEBUG
211 Kokkos::printf(
"%s\n", functorName);
213 auto row =
A.rowConst(rlid);
214 const size_t offset =
A.graph.row_map(rlid);
216 Kokkos::printf(
"decisions: ");
218 Kokkos::printf(
"%5d ",
results(offset + k));
221 Kokkos::printf(
"\n");
222 Kokkos::printf(
"Done with row %d\n", rlid);
225 size_t start =
A.graph.row_map(rlid);
226 size_t end =
A.graph.row_map(rlid + 1);
227 for (
size_t i = start; i < end; ++i) {
245template <
class local_matrix_type,
class local_graph_type,
bool lumping>
252 using ATS = Kokkos::ArithTraits<scalar_type>;
271 KOKKOS_INLINE_FUNCTION
273 auto rowA =
A.row(rlid);
274 size_t row_start =
A.graph.row_map(rlid);
282 if constexpr (lumping) {
289 rowFilteredA.colidx(j) = rowA.colidx(k);
290 rowFilteredA.value(j) = rowA.value(k);
292 graph.entries(graph_offset + jj) = rowA.colidx(k);
294 }
else if constexpr (lumping) {
295 diagCorrection += rowA.value(k);
296 rowFilteredA.colidx(j) = rowA.colidx(k);
297 rowFilteredA.value(j) =
zero;
300 rowFilteredA.colidx(j) = rowA.colidx(k);
301 rowFilteredA.value(j) =
zero;
305 if constexpr (lumping) {
306 rowFilteredA.value(diagOffset) += diagCorrection;
308 rowFilteredA.value(diagOffset) =
one;
320template <
class local_matrix_type,
bool lumping>
327 using ATS = Kokkos::ArithTraits<scalar_type>;
344 KOKKOS_INLINE_FUNCTION
346 auto rowA =
A.row(rlid);
347 size_t K =
A.graph.row_map(rlid);
353 if constexpr (lumping) {
360 rowFilteredA.colidx(j) = rowA.colidx(k);
361 rowFilteredA.value(j) = rowA.value(k);
363 }
else if constexpr (lumping) {
364 diagCorrection += rowA.value(k);
367 if constexpr (lumping) {
368 rowFilteredA.value(diagOffset) += diagCorrection;
370 rowFilteredA.value(diagOffset) =
one;
375template <
class local_matrix_type>
392 template <
class local_matrix_type2>
399 const local_matrix_type2
A;
404 KOKKOS_INLINE_FUNCTION
407 ,
offset(A_.graph.row_map(bsize_ * brlid_))
410 KOKKOS_INLINE_FUNCTION
418 KOKKOS_INLINE_FUNCTION
434template <
class local_matrix_type,
436 class... remaining_functor_types>
446 using rowptr_type =
typename local_matrix_type::row_map_type::non_const_type;
447 using ATS = Kokkos::ArithTraits<local_ordinal_type>;
463#ifdef MUELU_COALESCE_DROP_DEBUG
464 std::string functorName;
477 ,
remainingFunctors(A_, blockSize_, ghosted_point_to_block_, results_, filtered_rowptr_, graph_rowptr_, remainingFunctors_...) {
479#ifdef MUELU_COALESCE_DROP_DEBUG
480 std::string mangledFunctorName =
typeid(
decltype(
functor)).name();
482 char* demangledFunctorName = 0;
483 demangledFunctorName = abi::__cxa_demangle(mangledFunctorName.c_str(), 0, 0, &status);
484 functorName = demangledFunctorName;
488 KOKKOS_INLINE_FUNCTION
489 void join(Kokkos::pair<local_ordinal_type, local_ordinal_type>& dest,
const Kokkos::pair<local_ordinal_type, local_ordinal_type>& src)
const {
490 dest.first += src.first;
491 dest.second += src.second;
494 KOKKOS_INLINE_FUNCTION
500 KOKKOS_INLINE_FUNCTION
502 auto nnz_filtered = &nnz.first;
503 auto nnz_graph = &nnz.second;
505#ifdef MUELU_COALESCE_DROP_DEBUG
506 Kokkos::printf(
"\nStarting on block row %d\n", brlid);
509#ifdef MUELU_COALESCE_DROP_DEBUG
511 Kokkos::printf(
"\nStarting on row %d\n", rlid);
513 auto row =
A.rowConst(rlid);
515 Kokkos::printf(
"indices: ");
517 auto clid = row.colidx(k);
518 Kokkos::printf(
"%5d ", clid);
520 Kokkos::printf(
"\n");
522 Kokkos::printf(
"values: ");
524 auto val = row.value(k);
525 Kokkos::printf(
"%5f ", val);
527 Kokkos::printf(
"\n");
534#ifdef MUELU_COALESCE_DROP_DEBUG
536 Kokkos::printf(
"%s\n", functorName.c_str());
538 auto row =
A.rowConst(rlid);
539 const size_t offset =
A.graph.row_map(rlid);
541 Kokkos::printf(
"decisions: ");
543 Kokkos::printf(
"%5d ",
results(offset + k));
545 Kokkos::printf(
"\n");
549#ifdef MUELU_COALESCE_DROP_DEBUG
550 Kokkos::printf(
"Done with row %d\n", rlid);
553 size_t start =
A.graph.row_map(rlid);
554 size_t end =
A.graph.row_map(rlid + 1);
555 for (
size_t i = start; i < end; ++i) {
564#ifdef MUELU_COALESCE_DROP_DEBUG
565 Kokkos::printf(
"Done with block row %d\nGraph indices ", brlid);
569 auto block_clids = Kokkos::subview(
A.graph.entries, Kokkos::make_pair(
A.graph.row_map(
blockSize * brlid),
572 auto block_permutation = Kokkos::subview(
permutation, Kokkos::make_pair(
A.graph.row_map(
blockSize * brlid),
574 for (
size_t i = 0; i < block_permutation.extent(0); ++i)
575 block_permutation(i) = i;
577 auto comparator =
comparison.getComparator(brlid);
581 bool alreadyAdded =
false;
584 auto offset =
A.graph.row_map(
blockSize * brlid);
585 for (
size_t i = 0; i < block_permutation.extent(0); ++i) {
586 auto idx = offset + block_permutation(i);
587 auto clid =
A.graph.entries(idx);
591 if (bclid > prev_bclid)
592 alreadyAdded =
false;
598#ifdef MUELU_COALESCE_DROP_DEBUG
599 Kokkos::printf(
"%5d ", bclid);
604#ifdef MUELU_COALESCE_DROP_DEBUG
605 Kokkos::printf(
"\n");
612template <
class local_matrix_type,
623 using rowptr_type =
typename local_matrix_type::row_map_type::non_const_type;
624 using ATS = Kokkos::ArithTraits<local_ordinal_type>;
636#ifdef MUELU_COALESCE_DROP_DEBUG
637 std::string functorName;
654#ifdef MUELU_COALESCE_DROP_DEBUG
655 std::string mangledFunctorName =
typeid(
decltype(
functor)).name();
657 char* demangledFunctorName = 0;
658 demangledFunctorName = abi::__cxa_demangle(mangledFunctorName.c_str(), 0, 0, &status);
659 functorName = demangledFunctorName;
663 KOKKOS_INLINE_FUNCTION
664 void join(Kokkos::pair<local_ordinal_type, local_ordinal_type>& dest,
const Kokkos::pair<local_ordinal_type, local_ordinal_type>& src)
const {
665 dest.first += src.first;
666 dest.second += src.second;
669 KOKKOS_INLINE_FUNCTION
674 KOKKOS_INLINE_FUNCTION
676 auto nnz_filtered = &nnz.first;
677 auto nnz_graph = &nnz.second;
679#ifdef MUELU_COALESCE_DROP_DEBUG
680 Kokkos::printf(
"\nStarting on block row %d\n", brlid);
683#ifdef MUELU_COALESCE_DROP_DEBUG
685 Kokkos::printf(
"\nStarting on row %d\n", rlid);
687 auto row =
A.rowConst(rlid);
689 Kokkos::printf(
"indices: ");
691 auto clid = row.colidx(k);
692 Kokkos::printf(
"%5d ", clid);
694 Kokkos::printf(
"\n");
696 Kokkos::printf(
"values: ");
698 auto val = row.value(k);
699 Kokkos::printf(
"%5f ", val);
701 Kokkos::printf(
"\n");
707#ifdef MUELU_COALESCE_DROP_DEBUG
709 Kokkos::printf(
"%s\n", functorName.c_str());
711 auto row =
A.rowConst(rlid);
712 const size_t offset =
A.graph.row_map(rlid);
714 Kokkos::printf(
"decisions: ");
716 Kokkos::printf(
"%5d ",
results(offset + k));
718 Kokkos::printf(
"\n");
722#ifdef MUELU_COALESCE_DROP_DEBUG
723 Kokkos::printf(
"Done with row %d\n", rlid);
726 size_t start =
A.graph.row_map(rlid);
727 size_t end =
A.graph.row_map(rlid + 1);
728 for (
size_t i = start; i < end; ++i) {
737#ifdef MUELU_COALESCE_DROP_DEBUG
738 Kokkos::printf(
"Done with block row %d\nGraph indices ", brlid);
742 auto block_clids = Kokkos::subview(
A.graph.entries, Kokkos::make_pair(
A.graph.row_map(
blockSize * brlid),
745 auto block_permutation = Kokkos::subview(
permutation, Kokkos::make_pair(
A.graph.row_map(
blockSize * brlid),
747 for (
size_t i = 0; i < block_permutation.extent(0); ++i)
748 block_permutation(i) = i;
750 auto comparator =
comparison.getComparator(brlid);
754 bool alreadyAdded =
false;
757 auto offset =
A.graph.row_map(
blockSize * brlid);
758 for (
size_t i = 0; i < block_permutation.extent(0); ++i) {
759 auto idx = offset + block_permutation(i);
760 auto clid =
A.graph.entries(idx);
764 if (bclid > prev_bclid)
765 alreadyAdded =
false;
771#ifdef MUELU_COALESCE_DROP_DEBUG
772 Kokkos::printf(
"%5d ", bclid);
777#ifdef MUELU_COALESCE_DROP_DEBUG
778 Kokkos::printf(
"\n");
792template <
class local_matrix_type,
bool lumping,
bool reuse>
800 using ATS = Kokkos::ArithTraits<scalar_type>;
801 using OTS = Kokkos::ArithTraits<local_ordinal_type>;
832 KOKKOS_INLINE_FUNCTION
835 auto rowA =
A.row(rlid);
836 size_t row_start =
A.graph.row_map(rlid);
842 if constexpr (lumping) {
849 rowFilteredA.colidx(j) = rowA.colidx(k);
850 rowFilteredA.value(j) = rowA.value(k);
852 }
else if constexpr (lumping) {
853 diagCorrection += rowA.value(k);
854 if constexpr (reuse) {
855 rowFilteredA.colidx(j) = rowA.colidx(k);
856 rowFilteredA.value(j) =
zero;
859 }
else if constexpr (reuse) {
860 rowFilteredA.colidx(j) = rowA.colidx(k);
861 rowFilteredA.value(j) =
zero;
865 if constexpr (lumping) {
866 rowFilteredA.value(diagOffset) += diagCorrection;
868 rowFilteredA.value(diagOffset) =
one;
873 auto block_clids = Kokkos::subview(
A.graph.entries, Kokkos::make_pair(
A.graph.row_map(
blockSize * brlid),
876 auto block_permutation = Kokkos::subview(
permutation, Kokkos::make_pair(
A.graph.row_map(
blockSize * brlid),
878 for (
size_t i = 0; i < block_permutation.extent(0); ++i)
879 block_permutation(i) = i;
881 auto comparator =
comparison.getComparator(brlid);
885 bool alreadyAdded =
false;
889 auto offset =
A.graph.row_map(
blockSize * brlid);
890 for (
size_t i = 0; i < block_permutation.extent(0); ++i) {
891 auto idx = offset + block_permutation(i);
892 auto clid =
A.graph.entries(idx);
896 if (bclid > prev_bclid)
897 alreadyAdded =
false;
901 graph.entries(j) = bclid;
BlockRowComparison(local_matrix_type &A_, local_ordinal_type bsize_, block_indices_view_type ghosted_point_to_block_)
block_indices_view_type ghosted_point_to_block
typename local_matrix_type::ordinal_type local_ordinal_type
Comparator< local_matrix_type > comparator_type
KOKKOS_INLINE_FUNCTION comparator_type getComparator(local_ordinal_type brlid) const
Kokkos::View< local_ordinal_type *, memory_space > block_indices_view_type
typename local_matrix_type::memory_space memory_space
typename local_matrix_type::memory_space memory_space
Kokkos::View< DecisionType *, memory_space > results_view
PointwiseCountingFunctor(local_matrix_type &A_, results_view &results_, rowptr_type &rowptr_, bool firstFunctor_, functor_type &functor_)
typename local_matrix_type::row_map_type::non_const_type rowptr_type
PointwiseCountingFunctor(local_matrix_type &A_, results_view &results_, rowptr_type &rowptr_, functor_type &functor_)
typename local_matrix_type::ordinal_type local_ordinal_type
KOKKOS_INLINE_FUNCTION void operator()(const local_ordinal_type rlid, local_ordinal_type &nnz, const bool &final) const
typename local_matrix_type::value_type scalar_type
typename local_matrix_type::memory_space memory_space
PointwiseCountingFunctor(local_matrix_type &A_, results_view &results_, rowptr_type &rowptr_, bool firstFunctor_, functor_type &functor_, remaining_functor_types &... remainingFunctors_)
Kokkos::View< DecisionType *, memory_space > results_view
KOKKOS_INLINE_FUNCTION void operator()(const local_ordinal_type rlid, local_ordinal_type &nnz, const bool &final) const
typename local_matrix_type::ordinal_type local_ordinal_type
typename local_matrix_type::value_type scalar_type
typename local_matrix_type::row_map_type::non_const_type rowptr_type
PointwiseCountingFunctor< local_matrix_type, remaining_functor_types... > remainingFunctors
PointwiseCountingFunctor(local_matrix_type &A_, results_view &results_, rowptr_type &rowptr_, functor_type &functor_, remaining_functor_types &... remainingFunctors_)
local_matrix_type filteredA
typename local_matrix_type::memory_space memory_space
typename local_matrix_type::ordinal_type local_ordinal_type
magnitudeType dirichletThreshold
PointwiseFillNoReuseFunctor(local_matrix_type &A_, results_view &results_, local_matrix_type &filteredA_, magnitudeType dirichletThreshold_)
typename local_matrix_type::value_type scalar_type
Kokkos::ArithTraits< scalar_type > ATS
typename ATS::magnitudeType magnitudeType
KOKKOS_INLINE_FUNCTION void operator()(const local_ordinal_type rlid) const
Kokkos::View< DecisionType *, memory_space > results_view
magnitudeType dirichletThreshold
KOKKOS_INLINE_FUNCTION void operator()(const local_ordinal_type rlid) const
Kokkos::ArithTraits< scalar_type > ATS
typename ATS::magnitudeType magnitudeType
Kokkos::View< DecisionType *, memory_space > results_view
typename local_matrix_type::memory_space memory_space
typename local_matrix_type::value_type scalar_type
local_matrix_type filteredA
typename local_matrix_type::ordinal_type local_ordinal_type
PointwiseFillReuseFunctor(local_matrix_type &A_, results_view &results_, local_matrix_type &filteredA_, local_graph_type &graph_, magnitudeType dirichletThreshold_)
typename local_matrix_type::row_map_type::non_const_type rowptr_type
KOKKOS_INLINE_FUNCTION void join(Kokkos::pair< local_ordinal_type, local_ordinal_type > &dest, const Kokkos::pair< local_ordinal_type, local_ordinal_type > &src) const
KOKKOS_INLINE_FUNCTION void operator()(const local_ordinal_type brlid, Kokkos::pair< local_ordinal_type, local_ordinal_type > &nnz, const bool &final) const
block_indices_view_type ghosted_point_to_block
BlockRowComparison< local_matrix_type > comparison
Kokkos::ArithTraits< local_ordinal_type > ATS
local_ordinal_type blockSize
Kokkos::View< DecisionType *, memory_space > results_view
Kokkos::View< local_ordinal_type *, memory_space > permutation_type
typename local_matrix_type::memory_space memory_space
permutation_type permutation
KOKKOS_INLINE_FUNCTION void operatorRow(const local_ordinal_type rlid) const
rowptr_type filtered_rowptr
VectorCountingFunctor(local_matrix_type &A_, local_ordinal_type blockSize_, block_indices_view_type ghosted_point_to_block_, results_view &results_, rowptr_type &filtered_rowptr_, rowptr_type &graph_rowptr_, functor_type &functor_)
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
VectorCountingFunctor(local_matrix_type &A_, local_ordinal_type blockSize_, block_indices_view_type ghosted_point_to_block_, results_view &results_, rowptr_type &filtered_rowptr_, rowptr_type &graph_rowptr_, functor_type &functor_, remaining_functor_types &... remainingFunctors_)
typename local_matrix_type::row_map_type::non_const_type rowptr_type
KOKKOS_INLINE_FUNCTION void operator()(const local_ordinal_type brlid, Kokkos::pair< local_ordinal_type, local_ordinal_type > &nnz, const bool &final) const
rowptr_type filtered_rowptr
block_indices_view_type ghosted_point_to_block
local_ordinal_type blockSize
Kokkos::View< local_ordinal_type *, memory_space > block_indices_view_type
Kokkos::ArithTraits< local_ordinal_type > ATS
KOKKOS_INLINE_FUNCTION void join(Kokkos::pair< local_ordinal_type, local_ordinal_type > &dest, const Kokkos::pair< local_ordinal_type, local_ordinal_type > &src) const
VectorCountingFunctor< local_matrix_type, remaining_functor_types... > remainingFunctors
Kokkos::View< local_ordinal_type *, memory_space > permutation_type
typename local_matrix_type::ordinal_type local_ordinal_type
BlockRowComparison< local_matrix_type > comparison
permutation_type permutation
KOKKOS_INLINE_FUNCTION void operatorRow(const local_ordinal_type rlid) const
typename local_matrix_type::memory_space memory_space
Kokkos::View< DecisionType *, memory_space > results_view
typename local_matrix_type::value_type scalar_type
Kokkos::View< local_ordinal_type *, memory_space > block_indices_view_type
Kokkos::ArithTraits< local_ordinal_type > OTS
magnitudeType dirichletThreshold
Kokkos::ArithTraits< scalar_type > ATS
typename local_matrix_type::ordinal_type local_ordinal_type
local_matrix_type filteredA
typename local_matrix_type::memory_space memory_space
permutation_type permutation
typename ATS::magnitudeType magnitudeType
Kokkos::View< DecisionType *, memory_space > results_view
BlockRowComparison< local_matrix_type > comparison
KOKKOS_INLINE_FUNCTION void operator()(const local_ordinal_type brlid) const
VectorFillFunctor(local_matrix_type &A_, local_ordinal_type blockSize_, block_indices_view_type ghosted_point_to_block_, results_view &results_, local_matrix_type &filteredA_, local_graph_type &graph_, magnitudeType dirichletThreshold_)
Kokkos::View< local_ordinal_type *, memory_space > permutation_type
local_ordinal_type blockSize
block_indices_view_type ghosted_point_to_block
typename local_matrix_type::staticcrsgraph_type local_graph_type
typename local_matrix_type::value_type scalar_type
KOKKOS_INLINE_FUNCTION void serialHeapSort(view_type &v, comparator_type comparator)
const local_matrix_type A
KOKKOS_INLINE_FUNCTION bool operator()(size_t x, size_t y) const
typename local_matrix_type2::memory_space memory_space
typename local_matrix_type2::ordinal_type local_ordinal_type
const local_ordinal_type offset
Kokkos::View< local_ordinal_type *, memory_space > block_indices_view_type
const block_indices_view_type ghosted_point_to_block
KOKKOS_INLINE_FUNCTION Comparator(const local_matrix_type2 &A_, local_ordinal_type bsize_, local_ordinal_type brlid_, block_indices_view_type ghosted_point_to_block_)