From d66627a7d7b123d223333095a2f94cf5937b5158 Mon Sep 17 00:00:00 2001 From: "Yu-Hsiang M. Tsai" Date: Wed, 13 Nov 2024 19:14:11 +0100 Subject: [PATCH] change the diagonal to reduce random on parilut/parict --- test/factorization/par_ict_kernels.cpp | 13 +++++++++++++ test/factorization/par_ilut_kernels.cpp | 14 +++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/test/factorization/par_ict_kernels.cpp b/test/factorization/par_ict_kernels.cpp index 07a4ddc63ff..8d6579d584e 100644 --- a/test/factorization/par_ict_kernels.cpp +++ b/test/factorization/par_ict_kernels.cpp @@ -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::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(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); diff --git a/test/factorization/par_ilut_kernels.cpp b/test/factorization/par_ilut_kernels.cpp index ba2d84b4cc7..b1af2b4c748 100644 --- a/test/factorization/par_ilut_kernels.cpp +++ b/test/factorization/par_ilut_kernels.cpp @@ -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::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(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); @@ -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());