Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/muelu/src/Graph/MatrixTransformation/MueLu_CutDrop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ class CutDropFunctor {
size_t keepStart = 0;
size_t dropStart = nnz;
// find index where dropping starts

bool nonFiniteValueEncountered = false;
for (size_t i = 1; i < nnz; ++i) {
auto const& x = row_permutation(i - 1);
auto const& y = row_permutation(i);
Expand All @@ -971,6 +973,17 @@ class CutDropFunctor {
dropStart = i;
}
}

nonFiniteValueEncountered |= !is_finite_type_safe(x_aij);
nonFiniteValueEncountered |= !is_finite_type_safe(y_aij);
Comment on lines +977 to +978
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This loop contains redundant finiteness checks. Since x at iteration i is the same as y from iteration i-1, x_aij has already been validated in the previous step. To improve efficiency, consider checking the first element of row_permutation once before the loop and then only checking y_aij inside the loop. Additionally, since a non-finite value is a fatal error, using an immediate Kokkos::abort or a break would avoid unnecessary processing of the remaining elements in the row.

}

if (nonFiniteValueEncountered) {
const char* message =
"Error encountered in MueLu::CutDrop::CutDropFunctor::operator():\n"
"Non-finite values encountered in strength-of-connection measure.\n"
"A potential fix is to enable rebalancing and/or perform an initial rebalance.\n";
Kokkos::abort(message);
}

// drop everything to the right of where values stop passing threshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ class DropFunctor {
}
#endif

bool nonFiniteValueEncountered = false;
for (local_ordinal_type k = 0; k < row.length; ++k) {
auto clid = row.colidx(k);

Expand All @@ -623,11 +624,14 @@ class DropFunctor {
auto aiiajj = ATS::magnitude(diag(rlid)) * ATS::magnitude(diag(clid)); // |a_ii|*|a_jj|
auto aij2 = ATS::magnitude(val) * ATS::magnitude(val); // |a_ij|^2

nonFiniteValueEncountered |= !is_finite_type_safe(aiiajj) || !is_finite_type_safe(aij2);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The check !is_finite_type_safe(aiiajj) repeatedly validates diag(rlid), which is constant for the entire row. For better performance, consider checking the finiteness of the row's diagonal entry once outside the column loop. Furthermore, since encountering a non-finite value is a fatal error, using an early exit (e.g., break) after detecting the first such value would avoid wasted iterations. This applies to both DropFunctor and VectorDropFunctor.


results(offset + k) = Kokkos::max((aij2 <= eps * eps * aiiajj) ? DROP : KEEP,
results(offset + k));
} else if constexpr (measure == Misc::SignedRugeStuebenMeasure) {
auto neg_aij = -ATS::real(val);
auto max_neg_aik = eps * ATS::real(diag(rlid));
auto neg_aij = -ATS::real(val);
auto max_neg_aik = eps * ATS::real(diag(rlid));
nonFiniteValueEncountered |= !is_finite_type_safe(neg_aij) || !is_finite_type_safe(max_neg_aik);
results(offset + k) = Kokkos::max((neg_aij < max_neg_aik) ? DROP : KEEP,
results(offset + k));
} else if constexpr (measure == Misc::SignedSmoothedAggregationMeasure) {
Expand All @@ -637,10 +641,19 @@ class DropFunctor {
// + |a_ij|^2, if a_ij < 0, - |a_ij|^2 if a_ij >=0
if (!is_nonpositive)
aij2 = -aij2;
nonFiniteValueEncountered |= !is_finite_type_safe(aiiajj) || !is_finite_type_safe(aij2);
results(offset + k) = Kokkos::max((aij2 <= eps * eps * aiiajj) ? DROP : KEEP,
results(offset + k));
}
}

if (nonFiniteValueEncountered) {
const char* message =
"Error encountered in MueLu::DistanceLaplacian::DropFunctor::operator():\n"
"Non-finite values encountered in strength-of-connection measure.\n"
"A potential fix is to enable rebalancing and/or perform an initial rebalance.\n";
Kokkos::abort(message);
}
}
};

Expand Down Expand Up @@ -736,6 +749,7 @@ class VectorDropFunctor {
}
#endif

bool nonFiniteValueEncountered = false;
for (local_ordinal_type k = 0; k < row.length; ++k) {
auto clid = row.colidx(k);
auto bclid = ghosted_point_to_block(clid);
Expand All @@ -751,11 +765,14 @@ class VectorDropFunctor {
auto aiiajj = ATS::magnitude(diag(brlid)) * ATS::magnitude(diag(bclid)); // |a_ii|*|a_jj|
auto aij2 = ATS::magnitude(val) * ATS::magnitude(val); // |a_ij|^2

nonFiniteValueEncountered |= !is_finite_type_safe(aiiajj) || !is_finite_type_safe(aij2);

results(offset + k) = Kokkos::max((aij2 <= eps * eps * aiiajj) ? DROP : KEEP,
results(offset + k));
} else if constexpr (measure == Misc::SignedRugeStuebenMeasure) {
auto neg_aij = -ATS::real(val);
auto max_neg_aik = eps * ATS::real(diag(brlid));
auto neg_aij = -ATS::real(val);
auto max_neg_aik = eps * ATS::real(diag(brlid));
nonFiniteValueEncountered |= !is_finite_type_safe(neg_aij) || !is_finite_type_safe(max_neg_aik);
results(offset + k) = Kokkos::max((neg_aij < max_neg_aik) ? DROP : KEEP,
results(offset + k));
} else if constexpr (measure == Misc::SignedSmoothedAggregationMeasure) {
Expand All @@ -765,10 +782,19 @@ class VectorDropFunctor {
// + |a_ij|^2, if a_ij < 0, - |a_ij|^2 if a_ij >=0
if (!is_nonpositive)
aij2 = -aij2;
nonFiniteValueEncountered |= !is_finite_type_safe(aiiajj) || !is_finite_type_safe(aij2);
results(offset + k) = Kokkos::max((aij2 <= eps * eps * aiiajj) ? DROP : KEEP,
results(offset + k));
}
}

if (nonFiniteValueEncountered) {
const char* message =
"Error encountered in MueLu::DistanceLaplacian::VectorDropFunctor::operator():\n"
"Non-finite values encountered in strength-of-connection measure.\n"
"A potential fix is to enable rebalancing and/or perform an initial rebalance.\n";
Kokkos::abort(message);
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ enum DecisionType : char {
BOUNDARY = 3 // entry is a boundary
};

template <typename T>
KOKKOS_INLINE_FUNCTION bool is_finite_type_safe(T value) {
if constexpr (std::is_floating_point_v<T>) {
return Kokkos::isfinite(value);
} else {
return true;
}
}

namespace Misc {

template <class local_ordinal_type>
Expand Down
Loading