Skip to content

Commit

Permalink
change the diagonal to reduce random on parilut/parict
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Nov 20, 2024
1 parent 65dc7c1 commit 8ba9c5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions test/factorization/par_ict_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ TYPED_TEST(ParIct, KernelAddCandidatesIsEquivalentToRef)
{
using Csr = typename TestFixture::Csr;
using value_type = typename TestFixture::value_type;
if (std::is_same_v<gko::remove_complex<value_type>, gko::half>) {
// We set the diagonal larger than 1 in half precision to reduce the
// possibility of resulting inf. It might introduce (a - llh)/diag when
// the entry is not presented in the original matrix
auto dist = std::uniform_real_distribution<>(1.0, 10.0);
for (gko::size_type i = 0; i < this->mtx_l->get_size()[0]; i++) {
this->mtx_l
->get_values()[this->mtx_l->get_const_row_ptrs()[i + 1] - 1] =
gko::detail::get_rand_value<value_type>(dist,
this->rand_engine);
}
this->dmtx_l->copy_from(this->mtx_l);
}
auto mtx_llh = Csr::create(this->ref, this->mtx_size);
this->mtx_l->apply(this->mtx_l->conj_transpose(), mtx_llh);
auto dmtx_llh = Csr::create(this->exec, this->mtx_size);
Expand Down
14 changes: 13 additions & 1 deletion test/factorization/par_ilut_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ TYPED_TEST(ParIlut, KernelAddCandidatesIsEquivalentToRef)
{
using Csr = typename TestFixture::Csr;
using value_type = typename TestFixture::value_type;
if (std::is_same_v<gko::remove_complex<value_type>, gko::half>) {
// We set the diagonal larger than 1 in half precision to reduce the
// possibility of resulting inf. It might introduce (a - lu)/u_diag when
// the entry is not presented in the original matrix
auto dist = std::uniform_real_distribution<>(1.0, 10.0);
for (gko::size_type i = 0; i < this->mtx_u->get_size()[0]; i++) {
this->mtx_u->get_values()[this->mtx_u->get_const_row_ptrs()[i]] =
gko::detail::get_rand_value<value_type>(dist,
this->rand_engine);
}
this->dmtx_u->copy_from(this->mtx_u);
}
auto square_size = this->mtx_square->get_size();
auto mtx_lu = Csr::create(this->ref, square_size);
this->mtx_l2->apply(this->mtx_u, mtx_lu);
Expand All @@ -422,7 +434,7 @@ TYPED_TEST(ParIlut, KernelAddCandidatesIsEquivalentToRef)
auto res_mtx_u = Csr::create(this->ref, square_size);
auto dres_mtx_l = Csr::create(this->exec, square_size);
auto dres_mtx_u = Csr::create(this->exec, square_size);

// gko::write(std::cout, mtx_lu);
gko::kernels::reference::par_ilut_factorization::add_candidates(
this->ref, mtx_lu.get(), this->mtx_square.get(), this->mtx_l2.get(),
this->mtx_u.get(), res_mtx_l.get(), res_mtx_u.get());
Expand Down

0 comments on commit 8ba9c5a

Please sign in to comment.