|
1 | | -// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors |
| 1 | +// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors |
2 | 2 | // |
3 | 3 | // SPDX-License-Identifier: BSD-3-Clause |
4 | 4 |
|
|
11 | 11 |
|
12 | 12 | #include <ginkgo/core/base/executor.hpp> |
13 | 13 | #include <ginkgo/core/factorization/ilu.hpp> |
| 14 | +#include <ginkgo/core/log/logger.hpp> |
14 | 15 | #include <ginkgo/core/matrix/coo.hpp> |
15 | 16 | #include <ginkgo/core/matrix/csr.hpp> |
16 | 17 | #include <ginkgo/core/matrix/dense.hpp> |
17 | 18 |
|
18 | 19 | #include "core/test/utils.hpp" |
19 | 20 |
|
20 | 21 |
|
21 | | -namespace { |
| 22 | +struct CheckOperationLogger : gko::log::Logger { |
| 23 | + void on_operation_launched(const gko::Executor*, |
| 24 | + const gko::Operation* op) const override |
| 25 | + { |
| 26 | + std::string s = op->get_name(); |
| 27 | + if (s.find("sparselib") != std::string::npos) { |
| 28 | + contains_sparselib = true; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + mutable bool contains_sparselib = false; |
| 33 | +}; |
22 | 34 |
|
23 | 35 |
|
24 | 36 | class DummyLinOp : public gko::EnableLinOp<DummyLinOp>, |
@@ -147,7 +159,7 @@ class Ilu : public ::testing::Test { |
147 | 159 | mtx_csr_small2 = std::move(tmp_csr2); |
148 | 160 | } |
149 | 161 |
|
150 | | - std::shared_ptr<const gko::ReferenceExecutor> ref; |
| 162 | + std::shared_ptr<gko::ReferenceExecutor> ref; |
151 | 163 | std::shared_ptr<const gko::Executor> exec; |
152 | 164 | std::shared_ptr<const Dense> identity; |
153 | 165 | std::shared_ptr<const Dense> lower_triangular; |
@@ -229,6 +241,40 @@ TYPED_TEST(Ilu, SetUStrategy) |
229 | 241 | } |
230 | 242 |
|
231 | 243 |
|
| 244 | +TYPED_TEST(Ilu, UsesSyncFreeAlgorithm) |
| 245 | +{ |
| 246 | + using value_type = typename TestFixture::value_type; |
| 247 | + using index_type = typename TestFixture::index_type; |
| 248 | + auto logger = std::make_shared<CheckOperationLogger>(); |
| 249 | + this->ref->add_logger(logger); |
| 250 | + |
| 251 | + auto fact = |
| 252 | + gko::factorization::Ilu<value_type, index_type>::build() |
| 253 | + .with_algorithm(gko::factorization::incomplete_algorithm::syncfree) |
| 254 | + .on(this->ref) |
| 255 | + ->generate(this->mtx_small); |
| 256 | + |
| 257 | + ASSERT_FALSE(logger->contains_sparselib); |
| 258 | +} |
| 259 | + |
| 260 | + |
| 261 | +TYPED_TEST(Ilu, UsesSparseLibAlgorithm) |
| 262 | +{ |
| 263 | + using value_type = typename TestFixture::value_type; |
| 264 | + using index_type = typename TestFixture::index_type; |
| 265 | + auto logger = std::make_shared<CheckOperationLogger>(); |
| 266 | + this->ref->add_logger(logger); |
| 267 | + |
| 268 | + auto fact = |
| 269 | + gko::factorization::Ilu<value_type, index_type>::build() |
| 270 | + .with_algorithm(gko::factorization::incomplete_algorithm::sparselib) |
| 271 | + .on(this->ref) |
| 272 | + ->generate(this->mtx_small); |
| 273 | + |
| 274 | + ASSERT_TRUE(logger->contains_sparselib); |
| 275 | +} |
| 276 | + |
| 277 | + |
232 | 278 | TYPED_TEST(Ilu, LUFactorFunctionsSetProperly) |
233 | 279 | { |
234 | 280 | auto factors = this->ilu_factory_skip->generate(this->mtx_small); |
@@ -565,6 +611,3 @@ TYPED_TEST(Ilu, GenerateForReverseCsrSmall) |
565 | 611 | GKO_ASSERT_MTX_NEAR(l_factor, this->small_l_expected, r<value_type>::value); |
566 | 612 | GKO_ASSERT_MTX_NEAR(u_factor, this->small_u_expected, r<value_type>::value); |
567 | 613 | } |
568 | | - |
569 | | - |
570 | | -} // namespace |
|
0 commit comments