diff --git a/CMakeLists.txt b/CMakeLists.txt index efb3fcc24ff..4fd7c658c0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -511,3 +511,8 @@ else() FILE(READ ${PROJECT_BINARY_DIR}/minimal.log GINKGO_LOG_SUMMARY) endif() MESSAGE(STATUS "${GINKGO_LOG_SUMMARY}") + +# make sure no build files get committed accidentally +if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/.gitignore) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/.gitignore "*") +endif() diff --git a/benchmark/solver/solver_common.hpp b/benchmark/solver/solver_common.hpp index 0248ab8e757..784b70eca61 100644 --- a/benchmark/solver/solver_common.hpp +++ b/benchmark/solver/solver_common.hpp @@ -239,21 +239,18 @@ std::unique_ptr generate_solver( return gko::experimental::solver::Direct::build() .with_factorization( gko::experimental::factorization::Cholesky::build() - .on(exec)) + itype>::build()) .on(exec); } else if (description == "symm_direct") { return gko::experimental::solver::Direct::build() .with_factorization( gko::experimental::factorization::Lu::build() - .with_symmetric_sparsity(true) - .on(exec)) + .with_symmetric_sparsity(true)) .on(exec); } else if (description == "direct") { return gko::experimental::solver::Direct::build() .with_factorization( - gko::experimental::factorization::Lu::build().on( - exec)) + gko::experimental::factorization::Lu::build()) .on(exec); } else if (description == "overhead") { return add_criteria_precond_finalize>( diff --git a/benchmark/utils/overhead_linop.hpp b/benchmark/utils/overhead_linop.hpp index 168e650234d..d947b8de38e 100644 --- a/benchmark/utils/overhead_linop.hpp +++ b/benchmark/utils/overhead_linop.hpp @@ -104,27 +104,12 @@ class Overhead : public EnableLinOp>, friend class EnablePolymorphicObject; public: - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - }; + class Factory; + + struct parameters_type + : public gko::solver:: + enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> {}; GKO_ENABLE_LIN_OP_FACTORY(Overhead, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/benchmark/utils/preconditioners.hpp b/benchmark/utils/preconditioners.hpp index 466d5f2d3f9..3450eb71b44 100644 --- a/benchmark/utils/preconditioners.hpp +++ b/benchmark/utils/preconditioners.hpp @@ -122,7 +122,7 @@ const std::map( .on(exec)); return gko::preconditioner::Ic, itype>::build() - .with_factorization_factory(fact) + .with_factorization(fact) .on(exec); }}, {"parict", @@ -137,7 +137,7 @@ const std::map( return gko::preconditioner:: Ilu, gko::solver::UpperTrs, false, itype>::build() - .with_factorization_factory(fact) + .with_factorization(fact) .on(exec); }}, {"parilu", @@ -150,7 +150,7 @@ const std::map( return gko::preconditioner:: Ilu, gko::solver::UpperTrs, false, itype>::build() - .with_factorization_factory(fact) + .with_factorization(fact) .on(exec); }}, {"parilut", @@ -165,7 +165,7 @@ const std::map( return gko::preconditioner:: Ilu, gko::solver::UpperTrs, false, itype>::build() - .with_factorization_factory(fact) + .with_factorization(fact) .on(exec); }}, {"ic", @@ -174,7 +174,7 @@ const std::map( gko::factorization::Ic::build().on(exec)); return gko::preconditioner::Ic, itype>::build() - .with_factorization_factory(fact) + .with_factorization(fact) .on(exec); }}, {"ilu", @@ -184,7 +184,7 @@ const std::map( return gko::preconditioner:: Ilu, gko::solver::UpperTrs, false, itype>::build() - .with_factorization_factory(fact) + .with_factorization(fact) .on(exec); }}, {"paric-isai", @@ -201,8 +201,8 @@ const std::map( return gko::preconditioner::Ic< gko::preconditioner::LowerIsai, itype>::build() - .with_factorization_factory(fact) - .with_l_solver_factory(lisai) + .with_factorization(fact) + .with_l_solver(lisai) .on(exec); }}, {"parict-isai", @@ -221,8 +221,8 @@ const std::map( return gko::preconditioner::Ic< gko::preconditioner::LowerIsai, itype>::build() - .with_factorization_factory(fact) - .with_l_solver_factory(lisai) + .with_factorization(fact) + .with_l_solver(lisai) .on(exec); }}, {"parilu-isai", @@ -244,9 +244,9 @@ const std::map( gko::preconditioner::LowerIsai, gko::preconditioner::UpperIsai, false, itype>::build() - .with_factorization_factory(fact) - .with_l_solver_factory(lisai) - .with_u_solver_factory(uisai) + .with_factorization(fact) + .with_l_solver(lisai) + .with_u_solver(uisai) .on(exec); }}, {"parilut-isai", @@ -270,9 +270,9 @@ const std::map( gko::preconditioner::LowerIsai, gko::preconditioner::UpperIsai, false, itype>::build() - .with_factorization_factory(fact) - .with_l_solver_factory(lisai) - .with_u_solver_factory(uisai) + .with_factorization(fact) + .with_l_solver(lisai) + .with_u_solver(uisai) .on(exec); }}, {"ic-isai", @@ -286,8 +286,8 @@ const std::map( return gko::preconditioner::Ic< gko::preconditioner::LowerIsai, itype>::build() - .with_factorization_factory(fact) - .with_l_solver_factory(lisai) + .with_factorization(fact) + .with_l_solver(lisai) .on(exec); }}, {"ilu-isai", @@ -306,9 +306,9 @@ const std::map( gko::preconditioner::LowerIsai, gko::preconditioner::UpperIsai, false, itype>::build() - .with_factorization_factory(fact) - .with_l_solver_factory(lisai) - .with_u_solver_factory(uisai) + .with_factorization(fact) + .with_l_solver(lisai) + .with_u_solver(uisai) .on(exec); }}, {"general-isai", @@ -326,8 +326,7 @@ const std::map( {"overhead", [](std::shared_ptr exec) { return gko::Overhead::build() .with_criteria(gko::stop::ResidualNorm::build() - .with_reduction_factor(rc_etype{}) - .on(exec)) + .with_reduction_factor(rc_etype{})) .on(exec); }}}; diff --git a/core/distributed/preconditioner/schwarz.cpp b/core/distributed/preconditioner/schwarz.cpp index 31c57947704..0d1267bc0b4 100644 --- a/core/distributed/preconditioner/schwarz.cpp +++ b/core/distributed/preconditioner/schwarz.cpp @@ -102,8 +102,8 @@ template void Schwarz::generate( std::shared_ptr system_matrix) { - if (parameters_.local_solver_factory) { - this->local_solver_ = parameters_.local_solver_factory->generate( + if (parameters_.local_solver) { + this->local_solver_ = parameters_.local_solver->generate( as>( system_matrix) diff --git a/core/preconditioner/isai.cpp b/core/preconditioner/isai.cpp index 52fa9140853..4e0e2ea95d8 100644 --- a/core/preconditioner/isai.cpp +++ b/core/preconditioner/isai.cpp @@ -230,17 +230,15 @@ void Isai::generate_inverse( excess_solver_factory = Gmres::build() .with_preconditioner( - Bj::build().with_max_block_size(32u).on(exec)) + Bj::build().with_max_block_size(32u)) .with_criteria( - gko::stop::Iteration::build() - .with_max_iters(excess_dim) - .on(exec), + gko::stop::Iteration::build().with_max_iters( + excess_dim), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::rhs_norm) .with_reduction_factor( remove_complex{ - excess_solver_reduction}) - .on(exec)) + excess_solver_reduction})) .on(exec); excess_solution->copy_from(excess_rhs); } else if (is_lower) { diff --git a/core/solver/multigrid.cpp b/core/solver/multigrid.cpp index 303106fa4f6..84afc1666cc 100644 --- a/core/solver/multigrid.cpp +++ b/core/solver/multigrid.cpp @@ -569,21 +569,18 @@ void Multigrid::generate() using absolute_value_type = remove_complex; return solver::Gmres::build() .with_criteria( - stop::Iteration::build() - .with_max_iters(matrix->get_size()[0]) - .on(exec), + stop::Iteration::build().with_max_iters( + matrix->get_size()[0]), stop::ResidualNorm::build() .with_reduction_factor( std::numeric_limits< absolute_value_type>::epsilon() * - absolute_value_type{10}) - .on(exec)) + absolute_value_type{10})) .with_krylov_dim( std::min(size_type(100), matrix->get_size()[0])) .with_preconditioner( preconditioner::Jacobi::build() - .with_max_block_size(1u) - .on(exec)) + .with_max_block_size(1u)) .on(exec) ->generate(matrix); } else { @@ -591,8 +588,7 @@ void Multigrid::generate() int32>::build() .with_factorization( experimental::factorization::Lu::build() - .on(exec)) + int32>::build()) .on(exec) ->generate(matrix); } diff --git a/core/test/log/convergence.cpp b/core/test/log/convergence.cpp index f6294d08cd4..746e8603865 100644 --- a/core/test/log/convergence.cpp +++ b/core/test/log/convergence.cpp @@ -68,8 +68,7 @@ class Convergence : public ::testing::Test { gko::initialize({6}, exec); std::unique_ptr system = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec) ->generate(gko::initialize(I>{{1, 2}, {0, 3}}, exec)); std::unique_ptr rhs = gko::initialize({15, 25}, exec); diff --git a/core/test/log/papi.cpp b/core/test/log/papi.cpp index 2ed266449f6..0928f35d1ba 100644 --- a/core/test/log/papi.cpp +++ b/core/test/log/papi.cpp @@ -471,8 +471,7 @@ TYPED_TEST(Papi, CatchesLinOpFactoryGenerateStarted) { auto factory = gko::solver::Bicgstab::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto str = this->init(gko::log::Logger::linop_factory_generate_started_mask, "linop_factory_generate_started", factory.get()); @@ -492,8 +491,7 @@ TYPED_TEST(Papi, CatchesLinOpFactoryGenerateCompleted) { auto factory = gko::solver::Bicgstab::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); TypeParam dummy; auto str = diff --git a/core/test/log/profiler_hook.cpp b/core/test/log/profiler_hook.cpp index 281eed2d70b..cd6e1b0a3ce 100644 --- a/core/test/log/profiler_hook.cpp +++ b/core/test/log/profiler_hook.cpp @@ -202,8 +202,7 @@ TEST(ProfilerHook, LogsIteration) auto alpha = gko::share(gko::initialize({1.0}, exec)); auto solver = gko::solver::Ir<>::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec) ->generate(mtx); logger->set_object_name(solver, "solver"); diff --git a/core/test/log/record.cpp b/core/test/log/record.cpp index 0aeca2b3df7..098f93ad523 100644 --- a/core/test/log/record.cpp +++ b/core/test/log/record.cpp @@ -440,8 +440,7 @@ TEST(Record, CatchesLinopFactoryGenerateStarted) gko::log::Logger::linop_factory_generate_started_mask); auto factory = gko::solver::Bicgstab<>::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(exec); auto input = factory->generate(gko::matrix::Dense<>::create(exec)); @@ -462,8 +461,7 @@ TEST(Record, CatchesLinopFactoryGenerateCompleted) gko::log::Logger::linop_factory_generate_completed_mask); auto factory = gko::solver::Bicgstab<>::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(exec); auto input = factory->generate(gko::matrix::Dense<>::create(exec)); auto output = factory->generate(gko::matrix::Dense<>::create(exec)); @@ -569,8 +567,7 @@ TEST(Record, CatchesIterations) gko::log::Record::create(gko::log::Logger::iteration_complete_mask); auto factory = gko::solver::Bicgstab<>::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(exec); auto solver = factory->generate(gko::initialize({1.1}, exec)); auto right_hand_side = gko::initialize({-5.5}, exec); diff --git a/core/test/log/stream.cpp b/core/test/log/stream.cpp index 3558a7d5564..721273ca468 100644 --- a/core/test/log/stream.cpp +++ b/core/test/log/stream.cpp @@ -606,8 +606,7 @@ TYPED_TEST(Stream, CatchesLinopFactoryGenerateStarted) gko::log::Logger::linop_factory_generate_started_mask, out); auto factory = gko::solver::Bicgstab::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(exec); auto input = factory->generate(gko::matrix::Dense::create(exec)); std::stringstream ptrstream_factory; @@ -633,8 +632,7 @@ TYPED_TEST(Stream, CatchesLinopFactoryGenerateCompleted) gko::log::Logger::linop_factory_generate_completed_mask, out); auto factory = gko::solver::Bicgstab::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(exec); auto input = factory->generate(gko::matrix::Dense::create(exec)); auto output = @@ -815,8 +813,7 @@ TYPED_TEST(Stream, CatchesIterationsWithVerbose) auto factory = gko::solver::Bicgstab::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(exec); auto solver = factory->generate(gko::initialize({1.1}, exec)); auto right_hand_side = gko::initialize({-5.5}, exec); diff --git a/core/test/mpi/distributed/preconditioner/schwarz.cpp b/core/test/mpi/distributed/preconditioner/schwarz.cpp index ff1cd0d45e5..16b0af91b74 100644 --- a/core/test/mpi/distributed/preconditioner/schwarz.cpp +++ b/core/test/mpi/distributed/preconditioner/schwarz.cpp @@ -67,7 +67,7 @@ class SchwarzFactory : public ::testing::Test { mtx(Mtx::create(exec, MPI_COMM_WORLD)) { schwarz = Schwarz::build() - .with_local_solver_factory(jacobi_factory) + .with_local_solver(jacobi_factory) .on(exec) ->generate(mtx); } @@ -83,8 +83,8 @@ class SchwarzFactory : public ::testing::Test { gko::ptr_param b) { ASSERT_EQ(a->get_size(), b->get_size()); - ASSERT_EQ(a->get_parameters().local_solver_factory, - b->get_parameters().local_solver_factory); + ASSERT_EQ(a->get_parameters().local_solver, + b->get_parameters().local_solver); } std::shared_ptr exec; @@ -105,7 +105,7 @@ TYPED_TEST(SchwarzFactory, KnowsItsExecutor) TYPED_TEST(SchwarzFactory, CanSetLocalFactory) { - ASSERT_EQ(this->schwarz->get_parameters().local_solver_factory, + ASSERT_EQ(this->schwarz->get_parameters().local_solver, this->jacobi_factory); } @@ -123,9 +123,8 @@ TYPED_TEST(SchwarzFactory, CanBeCopied) using Jacobi = typename TestFixture::Jacobi; using Schwarz = typename TestFixture::Schwarz; using Mtx = typename TestFixture::Mtx; - auto bj = gko::share(Jacobi::build().on(this->exec)); auto copy = Schwarz::build() - .with_local_solver_factory(bj) + .with_local_solver(Jacobi::build()) .on(this->exec) ->generate(Mtx::create(this->exec, MPI_COMM_WORLD)); @@ -141,9 +140,8 @@ TYPED_TEST(SchwarzFactory, CanBeMoved) using Schwarz = typename TestFixture::Schwarz; using Mtx = typename TestFixture::Mtx; auto tmp = clone(this->schwarz); - auto bj = gko::share(Jacobi::build().on(this->exec)); auto copy = Schwarz::build() - .with_local_solver_factory(bj) + .with_local_solver(Jacobi::build()) .on(this->exec) ->generate(Mtx::create(this->exec, MPI_COMM_WORLD)); @@ -158,7 +156,20 @@ TYPED_TEST(SchwarzFactory, CanBeCleared) this->schwarz->clear(); ASSERT_EQ(this->schwarz->get_size(), gko::dim<2>(0, 0)); - ASSERT_EQ(this->schwarz->get_parameters().local_solver_factory, nullptr); + ASSERT_EQ(this->schwarz->get_parameters().local_solver, nullptr); +} + + +TYPED_TEST(SchwarzFactory, PassExplicitFactory) +{ + using Jacobi = typename TestFixture::Jacobi; + using Schwarz = typename TestFixture::Schwarz; + auto jacobi_factory = gko::share(Jacobi::build().on(this->exec)); + + auto factory = + Schwarz::build().with_local_solver(jacobi_factory).on(this->exec); + + ASSERT_EQ(factory->get_parameters().local_solver, jacobi_factory); } diff --git a/core/test/preconditioner/ic.cpp b/core/test/preconditioner/ic.cpp index efd54ee9ebc..dfcb5e5af3f 100644 --- a/core/test/preconditioner/ic.cpp +++ b/core/test/preconditioner/ic.cpp @@ -33,6 +33,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + +#endif +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 5211, 4973, 4974) +#endif + + #include @@ -44,6 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include "core/test/utils.hpp" + + namespace { @@ -77,9 +91,8 @@ TEST_F(IcFactory, KnowsItsExecutor) TEST_F(IcFactory, CanSetLSolverFactory) { - auto ic_factory = ic_prec_type::build() - .with_l_solver_factory(this->l_factory) - .on(this->exec); + auto ic_factory = + ic_prec_type::build().with_l_solver(this->l_factory).on(this->exec); ASSERT_EQ(ic_factory->get_parameters().l_solver_factory, this->l_factory); } @@ -88,7 +101,7 @@ TEST_F(IcFactory, CanSetLSolverFactory) TEST_F(IcFactory, CanSetFactorizationFactory) { auto ic_factory = ic_prec_type::build() - .with_factorization_factory(this->fact_factory) + .with_factorization(this->fact_factory) .on(this->exec); ASSERT_EQ(ic_factory->get_parameters().factorization_factory, @@ -96,4 +109,31 @@ TEST_F(IcFactory, CanSetFactorizationFactory) } +TEST_F(IcFactory, DeprecatedFactoryParameter) +{ + auto ilu_factory = ic_prec_type::build() + .with_l_solver_factory(this->l_factory) + .with_factorization_factory(this->fact_factory) + .on(this->exec); + + ASSERT_EQ(ilu_factory->get_parameters().l_solver_factory, this->l_factory); + ASSERT_EQ(ilu_factory->get_parameters().factorization_factory, + this->fact_factory); +} + + +TEST_F(IcFactory, DeferredFactoryParameter) +{ + auto ic_factory = ic_prec_type::build() + .with_l_solver(solver_type::build()) + .with_factorization(ic_type::build()) + .on(this->exec); + + GKO_ASSERT_DYNAMIC_TYPE(ic_factory->get_parameters().l_solver_factory, + solver_type::Factory); + GKO_ASSERT_DYNAMIC_TYPE(ic_factory->get_parameters().factorization_factory, + ic_type::Factory); +} + + } // namespace diff --git a/core/test/preconditioner/ilu.cpp b/core/test/preconditioner/ilu.cpp index c7b72e09b09..dec3c8532d2 100644 --- a/core/test/preconditioner/ilu.cpp +++ b/core/test/preconditioner/ilu.cpp @@ -33,6 +33,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + +#endif +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 5211, 4973, 4974) +#endif + + #include @@ -44,6 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include "core/test/utils.hpp" + + namespace { @@ -81,9 +95,8 @@ TEST_F(IluFactory, KnowsItsExecutor) TEST_F(IluFactory, CanSetLSolverFactory) { - auto ilu_factory = ilu_prec_type::build() - .with_l_solver_factory(this->l_factory) - .on(this->exec); + auto ilu_factory = + ilu_prec_type::build().with_l_solver(this->l_factory).on(this->exec); ASSERT_EQ(ilu_factory->get_parameters().l_solver_factory, this->l_factory); } @@ -91,9 +104,8 @@ TEST_F(IluFactory, CanSetLSolverFactory) TEST_F(IluFactory, CanSetUSolverFactory) { - auto ilu_factory = ilu_prec_type::build() - .with_u_solver_factory(this->u_factory) - .on(this->exec); + auto ilu_factory = + ilu_prec_type::build().with_u_solver(this->u_factory).on(this->exec); ASSERT_EQ(ilu_factory->get_parameters().u_solver_factory, this->u_factory); } @@ -102,12 +114,44 @@ TEST_F(IluFactory, CanSetUSolverFactory) TEST_F(IluFactory, CanSetFactorizationFactory) { auto ilu_factory = ilu_prec_type::build() + .with_factorization(this->fact_factory) + .on(this->exec); + + ASSERT_EQ(ilu_factory->get_parameters().factorization_factory, + this->fact_factory); +} + + +TEST_F(IluFactory, DeprecatedFactoryParameter) +{ + auto ilu_factory = ilu_prec_type::build() + .with_l_solver_factory(this->l_factory) + .with_u_solver_factory(this->u_factory) .with_factorization_factory(this->fact_factory) .on(this->exec); + ASSERT_EQ(ilu_factory->get_parameters().l_solver_factory, this->l_factory); + ASSERT_EQ(ilu_factory->get_parameters().u_solver_factory, this->u_factory); ASSERT_EQ(ilu_factory->get_parameters().factorization_factory, this->fact_factory); } +TEST_F(IluFactory, DeferredFactoryParameter) +{ + auto ilu_factory = ilu_prec_type::build() + .with_l_solver(l_solver_type::build()) + .with_u_solver(u_solver_type::build()) + .with_factorization(ilu_type::build()) + .on(this->exec); + + GKO_ASSERT_DYNAMIC_TYPE(ilu_factory->get_parameters().l_solver_factory, + l_solver_type::Factory); + GKO_ASSERT_DYNAMIC_TYPE(ilu_factory->get_parameters().u_solver_factory, + u_solver_type::Factory); + GKO_ASSERT_DYNAMIC_TYPE(ilu_factory->get_parameters().factorization_factory, + ilu_type::Factory); +} + + } // namespace diff --git a/core/test/solver/CMakeLists.txt b/core/test/solver/CMakeLists.txt index 4ca8763e2ee..f4e6b2e5b7b 100644 --- a/core/test/solver/CMakeLists.txt +++ b/core/test/solver/CMakeLists.txt @@ -2,6 +2,7 @@ ginkgo_create_test(bicg) ginkgo_create_test(bicgstab) ginkgo_create_test(cg) ginkgo_create_test(cgs) +ginkgo_create_test(direct) ginkgo_create_test(fcg) ginkgo_create_test(gcr) ginkgo_create_test(gmres) diff --git a/core/test/solver/bicg.cpp b/core/test/solver/bicg.cpp index 4c7421f63e1..c13070fad1e 100644 --- a/core/test/solver/bicg.cpp +++ b/core/test/solver/bicg.cpp @@ -66,10 +66,9 @@ class Bicg : public ::testing::Test { bicg_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(gko::remove_complex{1e-6}) - .on(exec)) + .with_reduction_factor(gko::remove_complex{1e-6})) .on(exec)), solver(bicg_factory->generate(mtx)) {} @@ -165,18 +164,12 @@ TYPED_TEST(Bicg, CanSetPreconditionerGenerator) using value_type = typename TestFixture::value_type; auto bicg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor( - gko::remove_complex(1e-6)) - .on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor( + gko::remove_complex(1e-6))) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = bicg_factory->generate(this->mtx); auto precond = dynamic_cast*>( @@ -195,15 +188,13 @@ TYPED_TEST(Bicg, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr bicg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto bicg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(bicg_precond) .on(this->exec); auto solver = bicg_factory->generate(this->mtx); @@ -246,15 +237,13 @@ TYPED_TEST(Bicg, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr bicg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto bicg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(bicg_precond) .on(this->exec); @@ -279,15 +268,13 @@ TYPED_TEST(Bicg, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr bicg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto bicg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = bicg_factory->generate(this->mtx); solver->set_preconditioner(bicg_precond); @@ -298,4 +285,21 @@ TYPED_TEST(Bicg, CanSetPreconditioner) } +TYPED_TEST(Bicg, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/bicgstab.cpp b/core/test/solver/bicgstab.cpp index c42cd7db2af..b420ccfc49e 100644 --- a/core/test/solver/bicgstab.cpp +++ b/core/test/solver/bicgstab.cpp @@ -64,10 +64,9 @@ class Bicgstab : public ::testing::Test { bicgstab_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(gko::remove_complex{1e-6}) - .on(exec)) + .with_reduction_factor(gko::remove_complex{1e-6})) .on(exec)), solver(bicgstab_factory->generate(mtx)) {} @@ -160,14 +159,9 @@ TYPED_TEST(Bicgstab, CanSetPreconditionerGenerator) using value_type = typename TestFixture::value_type; auto bicgstab_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = bicgstab_factory->generate(this->mtx); @@ -208,15 +202,13 @@ TYPED_TEST(Bicgstab, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr bicgstab_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto bicgstab_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(bicgstab_precond) .on(this->exec); auto solver = bicgstab_factory->generate(this->mtx); @@ -235,15 +227,13 @@ TYPED_TEST(Bicgstab, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr bicgstab_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto bicgstab_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(bicgstab_precond) .on(this->exec); @@ -268,15 +258,13 @@ TYPED_TEST(Bicgstab, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr bicgstab_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto bicgstab_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = bicgstab_factory->generate(this->mtx); solver->set_preconditioner(bicgstab_precond); @@ -287,4 +275,21 @@ TYPED_TEST(Bicgstab, CanSetPreconditioner) } +TYPED_TEST(Bicgstab, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/cb_gmres.cpp b/core/test/solver/cb_gmres.cpp index b81d84f8b1e..434544b3ca2 100644 --- a/core/test/solver/cb_gmres.cpp +++ b/core/test/solver/cb_gmres.cpp @@ -72,23 +72,20 @@ class CbGmres : public ::testing::Test { Solver::build() .with_storage_precision(storage_precision) .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(nc_value_type{1e-6}) - .on(exec)) + .with_reduction_factor(nc_value_type{1e-6})) .on(exec)), solver(cb_gmres_factory->generate(mtx)), cb_gmres_big_factory( Solver::build() .with_storage_precision(storage_precision) .with_criteria( - gko::stop::Iteration::build().with_max_iters(128u).on( - exec), + gko::stop::Iteration::build().with_max_iters(128u), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(nc_value_type{1e-6}) - .on(exec)) + .with_reduction_factor(nc_value_type{1e-6})) .on(exec)), big_solver(cb_gmres_big_factory->generate(mtx)) {} @@ -226,18 +223,12 @@ TYPED_TEST(CbGmres, CanSetPreconditionerGenerator) using Solver = typename TestFixture::Solver; auto cb_gmres_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), - gko::stop::ResidualNorm::build() - .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(nc_value_type{1e-6}) - .on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_baseline(gko::stop::mode::initial_resnorm) + .with_reduction_factor(nc_value_type{1e-6})) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = cb_gmres_factory->generate(this->mtx); auto precond = @@ -259,8 +250,7 @@ TYPED_TEST(CbGmres, CanSetKrylovDim) auto cb_gmres_factory = Solver::build() .with_krylov_dim(new_krylov_dim) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(this->exec); auto solver = cb_gmres_factory->generate(this->mtx); @@ -279,8 +269,7 @@ TYPED_TEST(CbGmres, CanUseSetKrylovDim) const gko::size_type new_krylov_dim{40u}; auto cb_gmres_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(this->exec); auto solver = cb_gmres_factory->generate(this->mtx); @@ -298,15 +287,13 @@ TYPED_TEST(CbGmres, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr cb_gmres_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto cb_gmres_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(cb_gmres_precond) .on(this->exec); auto solver = cb_gmres_factory->generate(this->mtx); @@ -325,15 +312,13 @@ TYPED_TEST(CbGmres, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr cb_gmres_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto cb_gmres_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(cb_gmres_precond) .on(this->exec); @@ -346,15 +331,13 @@ TYPED_TEST(CbGmres, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr cb_gmres_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto cb_gmres_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = cb_gmres_factory->generate(this->mtx); solver->set_preconditioner(cb_gmres_precond); @@ -365,4 +348,21 @@ TYPED_TEST(CbGmres, CanSetPreconditioner) } +TYPED_TEST(CbGmres, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/cg.cpp b/core/test/solver/cg.cpp index 5daf43bc160..f94694e775b 100644 --- a/core/test/solver/cg.cpp +++ b/core/test/solver/cg.cpp @@ -66,10 +66,9 @@ class Cg : public ::testing::Test { cg_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(gko::remove_complex{1e-6}) - .on(exec)) + .with_reduction_factor(gko::remove_complex{1e-6})) .on(exec)), solver(cg_factory->generate(mtx)) {} @@ -164,18 +163,12 @@ TYPED_TEST(Cg, CanSetPreconditionerGenerator) using value_type = typename TestFixture::value_type; auto cg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor( - gko::remove_complex(1e-6)) - .on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor( + gko::remove_complex(1e-6))) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = cg_factory->generate(this->mtx); auto precond = dynamic_cast*>( @@ -194,15 +187,13 @@ TYPED_TEST(Cg, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr cg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto cg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(cg_precond) .on(this->exec); auto solver = cg_factory->generate(this->mtx); @@ -245,15 +236,13 @@ TYPED_TEST(Cg, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr cg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto cg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(cg_precond) .on(this->exec); @@ -278,15 +267,13 @@ TYPED_TEST(Cg, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr cg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto cg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = cg_factory->generate(this->mtx); solver->set_preconditioner(cg_precond); @@ -297,4 +284,21 @@ TYPED_TEST(Cg, CanSetPreconditioner) } +TYPED_TEST(Cg, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/cgs.cpp b/core/test/solver/cgs.cpp index c23dc7b2e3b..6216899d898 100644 --- a/core/test/solver/cgs.cpp +++ b/core/test/solver/cgs.cpp @@ -66,10 +66,9 @@ class Cgs : public ::testing::Test { cgs_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(gko::remove_complex{1e-6}) - .on(exec)) + .with_reduction_factor(gko::remove_complex{1e-6})) .on(exec)), solver(cgs_factory->generate(mtx)) {} @@ -164,18 +163,12 @@ TYPED_TEST(Cgs, CanSetPreconditionerGenerator) using value_type = typename TestFixture::value_type; auto cgs_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor( - gko::remove_complex(1e-6)) - .on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor( + gko::remove_complex(1e-6))) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = cgs_factory->generate(this->mtx); auto precond = dynamic_cast*>( @@ -218,15 +211,13 @@ TYPED_TEST(Cgs, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr cgs_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto cgs_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(cgs_precond) .on(this->exec); auto solver = cgs_factory->generate(this->mtx); @@ -245,15 +236,13 @@ TYPED_TEST(Cgs, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr cgs_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto cgs_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(cgs_precond) .on(this->exec); @@ -278,15 +267,13 @@ TYPED_TEST(Cgs, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr cgs_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto cgs_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = cgs_factory->generate(this->mtx); solver->set_preconditioner(cgs_precond); @@ -297,4 +284,21 @@ TYPED_TEST(Cgs, CanSetPreconditioner) } +TYPED_TEST(Cgs, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/direct.cpp b/core/test/solver/direct.cpp new file mode 100644 index 00000000000..a4110c8c18d --- /dev/null +++ b/core/test/solver/direct.cpp @@ -0,0 +1,105 @@ +/************************************************************* +Copyright (c) 2017-2023, the Ginkgo authors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*************************************************************/ + +#include + + +#include + + +#include + + +#include +#include + + +#include "core/test/utils.hpp" + + +namespace { + + +template +class Direct : public ::testing::Test { +protected: + using value_type = + typename std::tuple_element<0, decltype(ValueIndexType())>::type; + using index_type = + typename std::tuple_element<1, decltype(ValueIndexType())>::type; + using Solver = gko::experimental::solver::Direct; + using Lu = gko::experimental::factorization::Lu; + + Direct() + : exec(gko::ReferenceExecutor::create()), + factory(Solver::build().with_factorization(Lu::build()).on(exec)) + {} + + std::shared_ptr exec; + std::unique_ptr factory; +}; + +TYPED_TEST_SUITE(Direct, gko::test::ValueIndexTypes, PairTypenameNameGenerator); + + +TYPED_TEST(Direct, FactoryKnowsItsExecutor) +{ + ASSERT_EQ(this->factory->get_executor(), this->exec); +} + + +TYPED_TEST(Direct, ThrowsOnRectangularMatrixInFactory) +{ + using Mtx = gko::matrix::Csr; + std::shared_ptr rectangular_matrix = + Mtx::create(this->exec, gko::dim<2>{1, 2}, 0); + + ASSERT_THROW(this->factory->generate(rectangular_matrix), + gko::DimensionMismatch); +} + + +TYPED_TEST(Direct, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + using Lu = typename TestFixture::Lu; + auto lu_factory = gko::share(Lu::build().on(this->exec)); + + auto factory = + Solver::build().with_factorization(lu_factory).on(this->exec); + + ASSERT_EQ(factory->get_parameters().factorization, lu_factory); +} + + +} // namespace diff --git a/core/test/solver/fcg.cpp b/core/test/solver/fcg.cpp index 59bb5e0cdee..87f27c2bacd 100644 --- a/core/test/solver/fcg.cpp +++ b/core/test/solver/fcg.cpp @@ -63,10 +63,9 @@ class Fcg : public ::testing::Test { fcg_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(gko::remove_complex{1e-6}) - .on(exec)) + .with_reduction_factor(gko::remove_complex{1e-6})) .on(exec)), solver(fcg_factory->generate(mtx)) {} @@ -163,18 +162,12 @@ TYPED_TEST(Fcg, CanSetPreconditionerGenerator) using value_type = typename TestFixture::value_type; auto fcg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor( - gko::remove_complex(1e-6)) - .on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor( + gko::remove_complex(1e-6))) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = fcg_factory->generate(this->mtx); auto precond = dynamic_cast*>( @@ -217,15 +210,13 @@ TYPED_TEST(Fcg, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr fcg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto fcg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(fcg_precond) .on(this->exec); auto solver = fcg_factory->generate(this->mtx); @@ -244,15 +235,13 @@ TYPED_TEST(Fcg, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr fcg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto fcg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(fcg_precond) .on(this->exec); @@ -277,15 +266,13 @@ TYPED_TEST(Fcg, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr fcg_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto fcg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = fcg_factory->generate(this->mtx); solver->set_preconditioner(fcg_precond); @@ -296,4 +283,21 @@ TYPED_TEST(Fcg, CanSetPreconditioner) } +TYPED_TEST(Fcg, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/gcr.cpp b/core/test/solver/gcr.cpp index f7ba80ebba1..4c08863f09b 100644 --- a/core/test/solver/gcr.cpp +++ b/core/test/solver/gcr.cpp @@ -67,23 +67,19 @@ class Gcr : public ::testing::Test { : exec(gko::ReferenceExecutor::create()), mtx(gko::initialize( {{1.0, 2.0, 3.0}, {3.0, 2.0, -1.0}, {0.0, -1.0, 2}}, exec)), - gcr_factory( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) - .on(exec)), + gcr_factory(Solver::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) + .on(exec)), solver(gcr_factory->generate(mtx)), gcr_big_factory( Big_solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(128u).on( - exec), + gko::stop::Iteration::build().with_max_iters(128u), gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_reduction_factor(reduction_factor)) .on(exec)), big_solver(gcr_big_factory->generate(mtx)) {} @@ -198,16 +194,11 @@ TYPED_TEST(Gcr, CanSetPreconditionerGenerator) auto gcr_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(TestFixture::reduction_factor) - .on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_reduction_factor(TestFixture::reduction_factor)) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = gcr_factory->generate(this->mtx); auto precond = dynamic_cast*>( @@ -253,10 +244,9 @@ TYPED_TEST(Gcr, CanSetKrylovDim) Solver::build() .with_krylov_dim(4u) .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(this->exec), + gko::stop::Iteration::build().with_max_iters(4u), gko::stop::ResidualNorm::build() - .with_reduction_factor(TestFixture::reduction_factor) - .on(this->exec)) + .with_reduction_factor(TestFixture::reduction_factor)) .on(this->exec); auto solver = gcr_factory->generate(this->mtx); auto krylov_dim = solver->get_krylov_dim(); @@ -289,15 +279,13 @@ TYPED_TEST(Gcr, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr gcr_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto gcr_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(gcr_precond) .on(this->exec); auto solver = gcr_factory->generate(this->mtx); @@ -316,15 +304,13 @@ TYPED_TEST(Gcr, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr gcr_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto gcr_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(gcr_precond) .on(this->exec); @@ -349,15 +335,13 @@ TYPED_TEST(Gcr, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr gcr_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto gcr_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = gcr_factory->generate(this->mtx); solver->set_preconditioner(gcr_precond); @@ -368,4 +352,21 @@ TYPED_TEST(Gcr, CanSetPreconditioner) } +TYPED_TEST(Gcr, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/gmres.cpp b/core/test/solver/gmres.cpp index 11cafe2c86f..2464bb7273d 100644 --- a/core/test/solver/gmres.cpp +++ b/core/test/solver/gmres.cpp @@ -70,20 +70,17 @@ class Gmres : public ::testing::Test { gmres_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_reduction_factor(reduction_factor)) .on(exec)), solver(gmres_factory->generate(mtx)), gmres_big_factory( Big_solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(128u).on( - exec), + gko::stop::Iteration::build().with_max_iters(128u), gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_reduction_factor(reduction_factor)) .on(exec)), big_solver(gmres_big_factory->generate(mtx)) {} @@ -183,16 +180,11 @@ TYPED_TEST(Gmres, CanSetPreconditionerGenerator) auto gmres_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(TestFixture::reduction_factor) - .on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_reduction_factor(TestFixture::reduction_factor)) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = gmres_factory->generate(this->mtx); auto precond = dynamic_cast*>( @@ -239,10 +231,9 @@ TYPED_TEST(Gmres, CanSetKrylovDim) Solver::build() .with_krylov_dim(4u) .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(this->exec), + gko::stop::Iteration::build().with_max_iters(4u), gko::stop::ResidualNorm::build() - .with_reduction_factor(TestFixture::reduction_factor) - .on(this->exec)) + .with_reduction_factor(TestFixture::reduction_factor)) .on(this->exec); auto solver = gmres_factory->generate(this->mtx); auto krylov_dim = solver->get_krylov_dim(); @@ -275,15 +266,13 @@ TYPED_TEST(Gmres, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr gmres_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto gmres_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(gmres_precond) .on(this->exec); auto solver = gmres_factory->generate(this->mtx); @@ -302,15 +291,13 @@ TYPED_TEST(Gmres, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr gmres_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto gmres_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(gmres_precond) .on(this->exec); @@ -335,15 +322,13 @@ TYPED_TEST(Gmres, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr gmres_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto gmres_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = gmres_factory->generate(this->mtx); solver->set_preconditioner(gmres_precond); @@ -354,4 +339,21 @@ TYPED_TEST(Gmres, CanSetPreconditioner) } +TYPED_TEST(Gmres, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/idr.cpp b/core/test/solver/idr.cpp index 45511be8e1b..5552f6f1c0a 100644 --- a/core/test/solver/idr.cpp +++ b/core/test/solver/idr.cpp @@ -64,10 +64,9 @@ class Idr : public ::testing::Test { idr_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() - .with_reduction_factor(gko::remove_complex{1e-6}) - .on(exec)) + .with_reduction_factor(gko::remove_complex{1e-6})) .on(exec)), solver(idr_factory->generate(mtx)) {} @@ -162,14 +161,9 @@ TYPED_TEST(Idr, CanSetPreconditionerGenerator) using value_type = typename TestFixture::value_type; auto idr_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) - .with_preconditioner( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) + .with_preconditioner(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = idr_factory->generate(this->mtx); @@ -209,15 +203,13 @@ TYPED_TEST(Idr, CanSetPreconditionerInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr idr_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto idr_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(idr_precond) .on(this->exec); auto solver = idr_factory->generate(this->mtx); @@ -236,15 +228,13 @@ TYPED_TEST(Idr, ThrowsOnWrongPreconditionerInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr idr_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto idr_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_preconditioner(idr_precond) .on(this->exec); @@ -257,15 +247,13 @@ TYPED_TEST(Idr, CanSetPreconditioner) using Solver = typename TestFixture::Solver; std::shared_ptr idr_precond = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto idr_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = idr_factory->generate(this->mtx); solver->set_preconditioner(idr_precond); @@ -283,8 +271,7 @@ TYPED_TEST(Idr, CanSetSubspaceDim) auto idr_factory = Solver::build() .with_subspace_dim(8u) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(this->exec); auto solver = idr_factory->generate(this->mtx); auto subspace_dim = solver->get_subspace_dim(); @@ -320,8 +307,7 @@ TYPED_TEST(Idr, CanSetKappa) auto idr_factory = Solver::build() .with_kappa(real_type{0.05}) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(this->exec); auto solver = idr_factory->generate(this->mtx); auto kappa = solver->get_kappa(); @@ -359,8 +345,7 @@ TYPED_TEST(Idr, CanSetDeterministic) auto idr_factory = Solver::build() .with_deterministic(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(this->exec); auto solver = idr_factory->generate(this->mtx); auto deterministic = solver->get_deterministic(); @@ -396,8 +381,7 @@ TYPED_TEST(Idr, CanSetComplexSubspace) auto idr_factory = Solver::build() .with_complex_subspace(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(this->exec); auto solver = idr_factory->generate(this->mtx); auto complex_subspace = solver->get_complex_subspace(); @@ -426,4 +410,21 @@ TYPED_TEST(Idr, CanSetComplexSubspaceAgain) } +TYPED_TEST(Idr, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto precond_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_preconditioner(precond_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory); +} + + } // namespace diff --git a/core/test/solver/ir.cpp b/core/test/solver/ir.cpp index 5fdcd55af14..171c0c92b00 100644 --- a/core/test/solver/ir.cpp +++ b/core/test/solver/ir.cpp @@ -64,14 +64,12 @@ class Ir : public ::testing::Test { : exec(gko::ReferenceExecutor::create()), mtx(gko::initialize( {{2, -1.0, 0.0}, {-1.0, 2, -1.0}, {0.0, -1.0, 2}}, exec)), - ir_factory( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)), + ir_factory(Solver::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)), solver(ir_factory->generate(mtx)) {} @@ -164,17 +162,11 @@ TYPED_TEST(Ir, CanSetInnerSolverInFactory) using value_type = typename TestFixture::value_type; auto ir_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) - .with_solver( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .with_solver(Solver::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(3u))) .on(this->exec); auto solver = ir_factory->generate(this->mtx); auto inner_solver = dynamic_cast( @@ -191,15 +183,13 @@ TYPED_TEST(Ir, CanSetGeneratedInnerSolverInFactory) using Solver = typename TestFixture::Solver; std::shared_ptr ir_solver = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto ir_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_solver(ir_solver) .on(this->exec); auto solver = ir_factory->generate(this->mtx); @@ -242,15 +232,13 @@ TYPED_TEST(Ir, ThrowsOnWrongInnerSolverInFactory) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr ir_solver = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto ir_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_generated_solver(ir_solver) .on(this->exec); @@ -263,15 +251,13 @@ TYPED_TEST(Ir, CanSetInnerSolver) using Solver = typename TestFixture::Solver; std::shared_ptr ir_solver = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(this->mtx); auto ir_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = ir_factory->generate(this->mtx); solver->set_solver(ir_solver); @@ -291,9 +277,7 @@ TYPED_TEST(Ir, CanSetApplyWithInitialGuessMode) initial_guess_mode::zero}) { auto ir_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on( - this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_default_initial_guess(guess) .on(this->exec); auto solver = ir_factory->generate(this->mtx); @@ -312,15 +296,13 @@ TYPED_TEST(Ir, ThrowOnWrongInnerSolverSet) Mtx::create(this->exec, gko::dim<2>{2, 2}); std::shared_ptr ir_solver = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec) ->generate(wrong_sized_mtx); auto ir_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .on(this->exec); auto solver = ir_factory->generate(this->mtx); @@ -347,11 +329,9 @@ TYPED_TEST(Ir, DefaultRelaxationFactor) auto richardson = gko::solver::Richardson::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) .on(this->exec) ->generate(this->mtx); @@ -366,11 +346,9 @@ TYPED_TEST(Ir, UseAsRichardson) auto richardson = gko::solver::Richardson::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) .with_relaxation_factor(relaxation_factor) .on(this->exec) ->generate(this->mtx); @@ -497,4 +475,21 @@ TYPED_TEST(Ir, RunResidualNormCheckCorrectTimes) } +TYPED_TEST(Ir, PassExplicitFactory) +{ + using Solver = typename TestFixture::Solver; + auto stop_factory = gko::share( + gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)); + auto inner_solver_factory = gko::share(Solver::build().on(this->exec)); + + auto factory = Solver::build() + .with_criteria(stop_factory) + .with_solver(inner_solver_factory) + .on(this->exec); + + ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory); + ASSERT_EQ(factory->get_parameters().solver, inner_solver_factory); +} + + } // namespace diff --git a/core/test/solver/multigrid.cpp b/core/test/solver/multigrid.cpp index 856f9651ebe..bab6bcaf863 100644 --- a/core/test/solver/multigrid.cpp +++ b/core/test/solver/multigrid.cpp @@ -153,11 +153,10 @@ class Multigrid : public ::testing::Test { multigrid_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(exec), + gko::stop::Iteration::build().with_max_iters(3u), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(gko::remove_complex{1e-6}) - .on(exec)) + .with_reduction_factor(gko::remove_complex{1e-6})) .with_max_levels(2u) .with_coarsest_solver(lo_factory) .with_pre_smoother(lo_factory) @@ -287,8 +286,7 @@ TYPED_TEST(Multigrid, ApplyUsesInitialGuessReturnsFalseWhenZeroGuess) using Solver = typename TestFixture::Solver; auto multigrid_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(3u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(3u)) .with_max_levels(2u) .with_coarsest_solver(this->lo_factory) .with_pre_smoother(this->lo_factory) @@ -904,4 +902,32 @@ TYPED_TEST(Multigrid, CustomCoarsestSolverSelector) } +TYPED_TEST(Multigrid, DeferredFactoryParameter) +{ + using Solver = typename TestFixture::Solver; + using DummyRPFactory = typename TestFixture::DummyRPFactory; + using DummyFactory = typename TestFixture::DummyFactory; + + auto solver = Solver::build() + .with_mg_level(DummyRPFactory::build()) + .with_pre_smoother(DummyFactory::build()) + .with_mid_smoother(DummyFactory::build()) + .with_post_smoother(DummyFactory::build()) + .with_criteria(gko::stop::Iteration::build()) + .with_coarsest_solver(DummyFactory::build()) + .on(this->exec); + + GKO_ASSERT_DYNAMIC_TYPE(solver->get_parameters().mg_level[0], + typename DummyRPFactory::Factory); + GKO_ASSERT_DYNAMIC_TYPE(solver->get_parameters().pre_smoother[0], + typename DummyFactory::Factory); + GKO_ASSERT_DYNAMIC_TYPE(solver->get_parameters().mid_smoother[0], + typename DummyFactory::Factory); + GKO_ASSERT_DYNAMIC_TYPE(solver->get_parameters().post_smoother[0], + typename DummyFactory::Factory); + GKO_ASSERT_DYNAMIC_TYPE(solver->get_parameters().coarsest_solver[0], + typename DummyFactory::Factory); +} + + } // namespace diff --git a/core/test/solver/workspace.cpp b/core/test/solver/workspace.cpp index ffbab815dc6..3dc53fb6abe 100644 --- a/core/test/solver/workspace.cpp +++ b/core/test/solver/workspace.cpp @@ -256,8 +256,8 @@ TEST_F(Workspace, CanCreateOperators) ASSERT_EQ(op2->get_size(), size2); ASSERT_EQ(op1->get_stride(), stride1); ASSERT_EQ(op2->get_stride(), stride2); - ASSERT_EQ(typeid(*op1), typeid(DummyLinOp)); - ASSERT_EQ(typeid(*op2), typeid(DummyLinOp2)); + GKO_ASSERT_DYNAMIC_TYPE(op1, DummyLinOp); + GKO_ASSERT_DYNAMIC_TYPE(op2, DummyLinOp2); ASSERT_EQ(op1, ws.get_op(1)); ASSERT_EQ(op2, ws.get_op(0)); } @@ -288,7 +288,7 @@ TEST_F(Workspace, ChecksExactOperatorType) 0, [&] { return std::make_unique(exec); }, typeid(DerivedDummyLinOp), {}, 0); - ASSERT_EQ(typeid(*op1), typeid(DerivedDummyLinOp)); + GKO_ASSERT_DYNAMIC_TYPE(op1, DerivedDummyLinOp); } diff --git a/core/test/utils/assertions.hpp b/core/test/utils/assertions.hpp index 153907cf2cf..d723d5a8964 100644 --- a/core/test/utils/assertions.hpp +++ b/core/test/utils/assertions.hpp @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include @@ -52,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include @@ -1010,6 +1012,45 @@ ::testing::AssertionResult matrices_equal_sparsity( } +template +::testing::AssertionResult dynamic_type_eq(const std::string& expr1, + const std::string& expr2, + const Ptr1& ptr1, const Ptr2& ptr2) +{ + auto& ref1 = *ptr1; + auto& ref2 = *ptr2; + if (typeid(ref1) == typeid(ref2)) { + return ::testing::AssertionSuccess(); + } else { + return ::testing::AssertionFailure() + << "mismatching dynamic types\n" + << expr1 << " is\n\t" + << gko::name_demangling::get_type_name(typeid(ref1)) << "\n" + << expr2 << " is\n\t" + << gko::name_demangling::get_type_name(typeid(ref2)) << "\n"; + } +} + + +template +::testing::AssertionResult dynamic_type_is(const std::string& expr, + const std::string&, const Ptr& ptr, + const std::type_info& type) +{ + auto& ref = *ptr; + if (typeid(ref) == type) { + return ::testing::AssertionSuccess(); + } else { + return ::testing::AssertionFailure() + << "unexpected dynamic type\n" + << expr << " is\n\t" + << gko::name_demangling::get_type_name(typeid(ref)) << "\n" + << "but we expected\n\t" + << gko::name_demangling::get_type_name(type) << "\n"; + } +} + + namespace detail { @@ -1249,4 +1290,51 @@ T* plain_ptr(T* ptr) } +/** + * Checks if the dynamic types of the objects referenced by two pointers are + * equal. + * + * @param _ptr1 the first pointer + * @param _ptr2 the second pointer + */ +#define GKO_ASSERT_DYNAMIC_TYPE_EQ(_ptr1, _ptr2) \ + { \ + ASSERT_PRED_FORMAT2(::gko::test::assertions::dynamic_type_eq, _ptr1, \ + _ptr2); \ + } + + +/** + * @copydoc GKO_ASSERT_DYNAMIC_TYPE_EQ + */ +#define GKO_EXPECT_DYNAMIC_TYPE_EQ(_ptr1, _ptr2) \ + { \ + EXPECT_PRED_FORMAT2(::gko::test::assertions::dynamic_type_eq, _ptr1, \ + _ptr2); \ + } + + +/** + * Checks if the dynamic type of a pointer to an object matches a given type + * + * @param _ptr the pointer + * @param _type the expected type + */ +#define GKO_ASSERT_DYNAMIC_TYPE(_ptr, _type) \ + { \ + ASSERT_PRED_FORMAT2(::gko::test::assertions::dynamic_type_is, _ptr, \ + typeid(_type)); \ + } + + +/** + * @copydoc GKO_ASSERT_DYNAMIC_TYPE + */ +#define GKO_EXPECT_DYNAMIC_TYPE(_ptr, _type) \ + { \ + EXPECT_PRED_FORMAT2(::gko::test::assertions::dynamic_type_is, _ptr, \ + typeid(_type)); \ + } + + #endif // GKO_CORE_TEST_UTILS_ASSERTIONS_HPP_ diff --git a/examples/adaptiveprecision-blockjacobi/adaptiveprecision-blockjacobi.cpp b/examples/adaptiveprecision-blockjacobi/adaptiveprecision-blockjacobi.cpp index 79b197aacc8..b673024c6fe 100644 --- a/examples/adaptiveprecision-blockjacobi/adaptiveprecision-blockjacobi.cpp +++ b/examples/adaptiveprecision-blockjacobi/adaptiveprecision-blockjacobi.cpp @@ -110,18 +110,14 @@ int main(int argc, char* argv[]) const RealValueType reduction_factor = 1e-7; auto solver_gen = cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(10000u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(10000u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) // Add preconditioner, these 2 lines are the only // difference from the simple solver example - .with_preconditioner(bj::build() - .with_max_block_size(16u) - .with_storage_optimization( - gko::precision_reduction::autodetect()) - .on(exec)) + .with_preconditioner( + bj::build().with_max_block_size(16u).with_storage_optimization( + gko::precision_reduction::autodetect())) .on(exec); // Create solver std::shared_ptr> logger = diff --git a/examples/cb-gmres/cb-gmres.cpp b/examples/cb-gmres/cb-gmres.cpp index b096e48c71a..915035fd642 100644 --- a/examples/cb-gmres/cb-gmres.cpp +++ b/examples/cb-gmres/cb-gmres.cpp @@ -154,12 +154,10 @@ int main(int argc, char* argv[]) // storage type auto solver_gen_keep = cb_gmres::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1000u).on(exec), - gko::stop::ResidualNorm::build() - .with_baseline(gko::stop::mode::rhs_norm) - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1000u), + gko::stop::ResidualNorm::build() + .with_baseline(gko::stop::mode::rhs_norm) + .with_reduction_factor(reduction_factor)) .with_krylov_dim(100u) .with_storage_precision( gko::solver::cb_gmres::storage_precision::keep) @@ -167,12 +165,10 @@ int main(int argc, char* argv[]) auto solver_gen_reduce = cb_gmres::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1000u).on(exec), - gko::stop::ResidualNorm::build() - .with_baseline(gko::stop::mode::rhs_norm) - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1000u), + gko::stop::ResidualNorm::build() + .with_baseline(gko::stop::mode::rhs_norm) + .with_reduction_factor(reduction_factor)) .with_krylov_dim(100u) .with_storage_precision( gko::solver::cb_gmres::storage_precision::reduce1) diff --git a/examples/custom-logger/custom-logger.cpp b/examples/custom-logger/custom-logger.cpp index 7e6cf531edd..e44303b81a2 100644 --- a/examples/custom-logger/custom-logger.cpp +++ b/examples/custom-logger/custom-logger.cpp @@ -290,11 +290,9 @@ int main(int argc, char* argv[]) // object needs to be built on. auto solver_gen = cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(20u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(20u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) .on(exec); // Instantiate a ResidualLogger logger. diff --git a/examples/custom-matrix-format/custom-matrix-format.cpp b/examples/custom-matrix-format/custom-matrix-format.cpp index 4610413fe9c..bcaa126cdaa 100644 --- a/examples/custom-matrix-format/custom-matrix-format.cpp +++ b/examples/custom-matrix-format/custom-matrix-format.cpp @@ -291,12 +291,10 @@ int main(int argc, char* argv[]) const RealValueType reduction_factor{1e-7}; // Generate solver and solve the system cg::build() - .with_criteria(gko::stop::Iteration::build() - .with_max_iters(discretization_points) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria( + gko::stop::Iteration::build().with_max_iters(discretization_points), + gko::stop::ResidualNorm::build().with_reduction_factor( + reduction_factor)) .on(exec) // notice how our custom StencilMatrix can be used in the same way as // any built-in type diff --git a/examples/custom-stopping-criterion/custom-stopping-criterion.cpp b/examples/custom-stopping-criterion/custom-stopping-criterion.cpp index 800846cfbd9..e4c7d88785c 100644 --- a/examples/custom-stopping-criterion/custom-stopping-criterion.cpp +++ b/examples/custom-stopping-criterion/custom-stopping-criterion.cpp @@ -109,13 +109,12 @@ void run_solver(volatile bool* stop_iteration_process, auto x = gko::read(std::ifstream("data/x0.mtx"), exec); // Create solver factory and solve system - auto solver = bicg::build() - .with_criteria(ByInteraction::build() - .with_stop_iteration_process( - stop_iteration_process) - .on(exec)) - .on(exec) - ->generate(A); + auto solver = + bicg::build() + .with_criteria(ByInteraction::build().with_stop_iteration_process( + stop_iteration_process)) + .on(exec) + ->generate(A); solver->add_logger(gko::log::Stream::create( gko::log::Logger::iteration_complete_mask, std::cout, true)); solver->apply(b, x); diff --git a/examples/distributed-solver/distributed-solver.cpp b/examples/distributed-solver/distributed-solver.cpp index 123f93775f5..1b758d186a4 100644 --- a/examples/distributed-solver/distributed-solver.cpp +++ b/examples/distributed-solver/distributed-solver.cpp @@ -222,19 +222,15 @@ int main(int argc, char* argv[]) const gko::remove_complex reduction_factor{1e-8}; std::shared_ptr> logger = gko::log::Convergence::create(); - auto Ainv = - solver::build() - .with_preconditioner(schwarz::build() - .with_local_solver_factory(local_solver) - .on(exec)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(num_iters).on( - exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) - .on(exec) - ->generate(A); + auto Ainv = solver::build() + .with_preconditioner( + schwarz::build().with_local_solver(local_solver)) + .with_criteria( + gko::stop::Iteration::build().with_max_iters(num_iters), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) + .on(exec) + ->generate(A); // Add logger to the generated solver to log the iteration count and // residual norm Ainv->add_logger(logger); diff --git a/examples/external-lib-interfacing/external-lib-interfacing.cpp b/examples/external-lib-interfacing/external-lib-interfacing.cpp index 1766af3001f..04824cb9578 100644 --- a/examples/external-lib-interfacing/external-lib-interfacing.cpp +++ b/examples/external-lib-interfacing/external-lib-interfacing.cpp @@ -880,11 +880,9 @@ void AdvectionProblem::solve() auto solver_gen = bicgstab::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(1000).on(exec), - gko::stop::ResidualNorm<>::build() - .with_reduction_factor(1e-12) - .on(exec)) - .with_preconditioner(bj::build().on(exec)) + gko::stop::Iteration::build().with_max_iters(1000), + gko::stop::ResidualNorm<>::build().with_reduction_factor(1e-12)) + .with_preconditioner(bj::build()) .on(exec); auto solver = solver_gen->generate(gko::give(A)); diff --git a/examples/ginkgo-overhead/ginkgo-overhead.cpp b/examples/ginkgo-overhead/ginkgo-overhead.cpp index 5bd90ba0bad..f3f308c495f 100644 --- a/examples/ginkgo-overhead/ginkgo-overhead.cpp +++ b/examples/ginkgo-overhead/ginkgo-overhead.cpp @@ -72,8 +72,7 @@ int main(int argc, char* argv[]) auto cg_factory = cg::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(num_iters).on( - exec)) + gko::stop::Iteration::build().with_max_iters(num_iters)) .on(exec); auto A = gko::initialize({1.0}, exec); auto b = gko::initialize({std::nan("")}, exec); diff --git a/examples/heat-equation/heat-equation.cpp b/examples/heat-equation/heat-equation.cpp index eae87f7e64f..8e69931b250 100644 --- a/examples/heat-equation/heat-equation.cpp +++ b/examples/heat-equation/heat-equation.cpp @@ -192,11 +192,10 @@ int main(int argc, char* argv[]) // stopping at 1e-10 relative accuracy auto solver = gko::solver::Cg<>::build() - .with_preconditioner(gko::preconditioner::Ic<>::build().on(exec)) + .with_preconditioner(gko::preconditioner::Ic<>::build()) .with_criteria(gko::stop::ResidualNorm<>::build() .with_baseline(gko::stop::mode::rhs_norm) - .with_reduction_factor(1e-10) - .on(exec)) + .with_reduction_factor(1e-10)) .on(exec) ->generate(stencil_matrix); // time stamp of the last output frame (initialized to a sentinel value) diff --git a/examples/ilu-preconditioned-solver/ilu-preconditioned-solver.cpp b/examples/ilu-preconditioned-solver/ilu-preconditioned-solver.cpp index 33946b7de44..acebd9d96ff 100644 --- a/examples/ilu-preconditioned-solver/ilu-preconditioned-solver.cpp +++ b/examples/ilu-preconditioned-solver/ilu-preconditioned-solver.cpp @@ -114,11 +114,9 @@ int main(int argc, char* argv[]) const RealValueType reduction_factor{1e-7}; auto ilu_gmres_factory = gmres::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1000u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1000u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) .with_generated_preconditioner(ilu_preconditioner) .on(exec); diff --git a/examples/inverse-iteration/inverse-iteration.cpp b/examples/inverse-iteration/inverse-iteration.cpp index 460370b7e00..2b584e0ca4f 100644 --- a/examples/inverse-iteration/inverse-iteration.cpp +++ b/examples/inverse-iteration/inverse-iteration.cpp @@ -118,12 +118,10 @@ int main(int argc, char* argv[]) // Generate solver operator (A - zI)^-1 auto solver = solver_type::build() - .with_criteria(gko::stop::Iteration::build() - .with_max_iters(system_max_iterations) - .on(exec), + .with_criteria(gko::stop::Iteration::build().with_max_iters( + system_max_iterations), gko::stop::ResidualNorm::build() - .with_reduction_factor(system_residual_goal) - .on(exec)) + .with_reduction_factor(system_residual_goal)) .on(exec) ->generate(system_matrix); diff --git a/examples/ir-ilu-preconditioned-solver/ir-ilu-preconditioned-solver.cpp b/examples/ir-ilu-preconditioned-solver/ir-ilu-preconditioned-solver.cpp index 407a083e548..be7e8261f2c 100644 --- a/examples/ir-ilu-preconditioned-solver/ir-ilu-preconditioned-solver.cpp +++ b/examples/ir-ilu-preconditioned-solver/ir-ilu-preconditioned-solver.cpp @@ -119,18 +119,16 @@ int main(int argc, char* argv[]) auto trisolve_factory = ir::build() .with_solver(bj_factory) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(sweeps).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(sweeps)) .on(exec); // Generate an ILU preconditioner factory by setting lower and upper // triangular solver - in this case the previously defined iterative // refinement method. - auto ilu_pre_factory = - gko::preconditioner::Ilu::build() - .with_l_solver_factory(gko::clone(trisolve_factory)) - .with_u_solver_factory(gko::clone(trisolve_factory)) - .on(exec); + auto ilu_pre_factory = gko::preconditioner::Ilu::build() + .with_l_solver(gko::clone(trisolve_factory)) + .with_u_solver(gko::clone(trisolve_factory)) + .on(exec); // Use incomplete factors to generate ILU preconditioner auto ilu_preconditioner = gko::share(ilu_pre_factory->generate(par_ilu)); diff --git a/examples/iterative-refinement/iterative-refinement.cpp b/examples/iterative-refinement/iterative-refinement.cpp index 14384eaab52..711d43049a1 100644 --- a/examples/iterative-refinement/iterative-refinement.cpp +++ b/examples/iterative-refinement/iterative-refinement.cpp @@ -113,19 +113,13 @@ int main(int argc, char* argv[]) RealValueType inner_reduction_factor{1e-2}; auto solver_gen = ir::build() - .with_solver( - cg::build() - .with_criteria( - gko::stop::ResidualNorm::build() - .with_reduction_factor(inner_reduction_factor) - .on(exec)) - .on(exec)) + .with_solver(cg::build().with_criteria( + gko::stop::ResidualNorm::build() + .with_reduction_factor(inner_reduction_factor))) .with_criteria( - gko::stop::Iteration::build().with_max_iters(max_iters).on( - exec), + gko::stop::Iteration::build().with_max_iters(max_iters), gko::stop::ResidualNorm::build() - .with_reduction_factor(outer_reduction_factor) - .on(exec)) + .with_reduction_factor(outer_reduction_factor)) .on(exec); // Create solver auto solver = solver_gen->generate(A); diff --git a/examples/kokkos_assembly/kokkos_assembly.cpp b/examples/kokkos_assembly/kokkos_assembly.cpp index ba579199ee3..88ff261b759 100644 --- a/examples/kokkos_assembly/kokkos_assembly.cpp +++ b/examples/kokkos_assembly/kokkos_assembly.cpp @@ -208,13 +208,11 @@ int main(int argc, char* argv[]) const RealValueType reduction_factor{1e-7}; // Generate solver and solve the system cg::build() - .with_criteria(gko::stop::Iteration::build() - .with_max_iters(discretization_points) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) - .with_preconditioner(bj::build().on(exec)) + .with_criteria( + gko::stop::Iteration::build().with_max_iters(discretization_points), + gko::stop::ResidualNorm::build().with_reduction_factor( + reduction_factor)) + .with_preconditioner(bj::build()) .on(exec) ->generate(A) ->apply(rhs, u); diff --git a/examples/minimal-cuda-solver/minimal-cuda-solver.cpp b/examples/minimal-cuda-solver/minimal-cuda-solver.cpp index 5a7a8c086af..ccbdaadfc41 100644 --- a/examples/minimal-cuda-solver/minimal-cuda-solver.cpp +++ b/examples/minimal-cuda-solver/minimal-cuda-solver.cpp @@ -44,12 +44,10 @@ int main() // Create the solver auto solver = gko::solver::Cg<>::build() - .with_preconditioner(gko::preconditioner::Jacobi<>::build().on(gpu)) + .with_preconditioner(gko::preconditioner::Jacobi<>::build()) .with_criteria( - gko::stop::Iteration::build().with_max_iters(20u).on(gpu), - gko::stop::ResidualNorm<>::build() - .with_reduction_factor(1e-15) - .on(gpu)) + gko::stop::Iteration::build().with_max_iters(20u), + gko::stop::ResidualNorm<>::build().with_reduction_factor(1e-15)) .on(gpu); // Solve system solver->generate(give(A))->apply(b, x); diff --git a/examples/mixed-multigrid-preconditioned-solver/mixed-multigrid-preconditioned-solver.cpp b/examples/mixed-multigrid-preconditioned-solver/mixed-multigrid-preconditioned-solver.cpp index cef918983e9..3834fa7f33f 100644 --- a/examples/mixed-multigrid-preconditioned-solver/mixed-multigrid-preconditioned-solver.cpp +++ b/examples/mixed-multigrid-preconditioned-solver/mixed-multigrid-preconditioned-solver.cpp @@ -139,15 +139,13 @@ int main(int argc, char* argv[]) ir::build() .with_solver(inner_solver_gen) .with_relaxation_factor(static_cast(0.9)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec)); auto smoother_gen_f = gko::share( ir_f::build() .with_solver(inner_solver_gen_f) .with_relaxation_factor(static_cast(0.9)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec)); // Create MultigridLevel factory auto mg_level_gen = @@ -159,15 +157,13 @@ int main(int argc, char* argv[]) ir::build() .with_solver(inner_solver_gen) .with_relaxation_factor(static_cast(0.9)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(exec)); auto coarsest_gen_f = gko::share( ir_f::build() .with_solver(inner_solver_gen_f) .with_relaxation_factor(static_cast(0.9)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(exec)); // Create multigrid factory std::shared_ptr multigrid_gen; @@ -192,8 +188,7 @@ int main(int argc, char* argv[]) .with_coarsest_solver(coarsest_gen_f) .with_default_initial_guess( gko::solver::initial_guess_mode::zero) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec); } else { multigrid_gen = @@ -206,8 +201,7 @@ int main(int argc, char* argv[]) .with_coarsest_solver(coarsest_gen) .with_default_initial_guess( gko::solver::initial_guess_mode::zero) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec); } // Create solver factory diff --git a/examples/mixed-multigrid-solver/mixed-multigrid-solver.cpp b/examples/mixed-multigrid-solver/mixed-multigrid-solver.cpp index 4241a74cdf2..33684198c83 100644 --- a/examples/mixed-multigrid-solver/mixed-multigrid-solver.cpp +++ b/examples/mixed-multigrid-solver/mixed-multigrid-solver.cpp @@ -125,17 +125,15 @@ int main(int argc, char* argv[]) // Create smoother factory (ir with bj) auto smoother_gen = gko::share( ir::build() - .with_solver(bj::build().with_max_block_size(1u).on(exec)) + .with_solver(bj::build().with_max_block_size(1u)) .with_relaxation_factor(static_cast(0.9)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec)); auto smoother_gen2 = gko::share( ir2::build() - .with_solver(bj2::build().with_max_block_size(1u).on(exec)) + .with_solver(bj2::build().with_max_block_size(1u)) .with_relaxation_factor(static_cast(0.9)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec)); // Create RestrictProlong factory auto mg_level_gen = @@ -145,17 +143,15 @@ int main(int argc, char* argv[]) // Create CoarsesSolver factory auto coarsest_solver_gen = gko::share( ir::build() - .with_solver(bj::build().with_max_block_size(1u).on(exec)) + .with_solver(bj::build().with_max_block_size(1u)) .with_relaxation_factor(static_cast(0.9)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(exec)); auto coarsest_solver_gen2 = gko::share( ir2::build() - .with_solver(bj2::build().with_max_block_size(1u).on(exec)) + .with_solver(bj2::build().with_max_block_size(1u)) .with_relaxation_factor(static_cast(0.9)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(4u)) .on(exec)); // Create multigrid factory std::shared_ptr multigrid_gen; diff --git a/examples/mixed-precision-ir/mixed-precision-ir.cpp b/examples/mixed-precision-ir/mixed-precision-ir.cpp index 0882d755cdc..0083ca15162 100644 --- a/examples/mixed-precision-ir/mixed-precision-ir.cpp +++ b/examples/mixed-precision-ir/mixed-precision-ir.cpp @@ -124,12 +124,10 @@ int main(int argc, char* argv[]) // Create inner solver auto inner_solver = cg::build() - .with_criteria(gko::stop::ResidualNorm::build() - .with_reduction_factor(inner_reduction_factor) - .on(exec), - gko::stop::Iteration::build() - .with_max_iters(max_inner_iters) - .on(exec)) + .with_criteria( + gko::stop::ResidualNorm::build() + .with_reduction_factor(inner_reduction_factor), + gko::stop::Iteration::build().with_max_iters(max_inner_iters)) .on(exec) ->generate(give(solver_A)); diff --git a/examples/multigrid-preconditioned-solver-customized/multigrid-preconditioned-solver-customized.cpp b/examples/multigrid-preconditioned-solver-customized/multigrid-preconditioned-solver-customized.cpp index f82a603d662..d63dedf486b 100644 --- a/examples/multigrid-preconditioned-solver-customized/multigrid-preconditioned-solver-customized.cpp +++ b/examples/multigrid-preconditioned-solver-customized/multigrid-preconditioned-solver-customized.cpp @@ -130,8 +130,7 @@ int main(int argc, char* argv[]) // iterative refinement with two iterations and an Ic solver. auto ic_gen = gko::share( ic::build() - .with_factorization_factory( - gko::factorization::Ic::build().on(exec)) + .with_factorization(gko::factorization::Ic::build()) .on(exec)); auto smoother_gen = gko::share( gko::solver::build_smoother(ic_gen, 2u, static_cast(0.9))); @@ -159,8 +158,7 @@ int main(int argc, char* argv[]) .with_mg_level(mg_level_gen) .with_coarsest_solver(coarsest_gen) .with_default_initial_guess(gko::solver::initial_guess_mode::zero) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec); // Create solver factory auto solver_gen = cg::build() diff --git a/examples/multigrid-preconditioned-solver/multigrid-preconditioned-solver.cpp b/examples/multigrid-preconditioned-solver/multigrid-preconditioned-solver.cpp index b31b7906902..0bb51e6fee9 100644 --- a/examples/multigrid-preconditioned-solver/multigrid-preconditioned-solver.cpp +++ b/examples/multigrid-preconditioned-solver/multigrid-preconditioned-solver.cpp @@ -108,19 +108,16 @@ int main(int argc, char* argv[]) std::shared_ptr multigrid_gen; multigrid_gen = mg::build() - .with_mg_level(pgm::build().with_deterministic(true).on(exec)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_mg_level(pgm::build().with_deterministic(true)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec); const gko::remove_complex tolerance = 1e-8; auto solver_gen = cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on(exec), - gko::stop::ResidualNorm::build() - .with_baseline(gko::stop::mode::absolute) - .with_reduction_factor(tolerance) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(100u), + gko::stop::ResidualNorm::build() + .with_baseline(gko::stop::mode::absolute) + .with_reduction_factor(tolerance)) .with_preconditioner(multigrid_gen) .on(exec); // Create solver diff --git a/examples/nine-pt-stencil-solver/nine-pt-stencil-solver.cpp b/examples/nine-pt-stencil-solver/nine-pt-stencil-solver.cpp index 05ee0503a5f..be3cc958baf 100644 --- a/examples/nine-pt-stencil-solver/nine-pt-stencil-solver.cpp +++ b/examples/nine-pt-stencil-solver/nine-pt-stencil-solver.cpp @@ -282,12 +282,10 @@ void solve_system(const std::string& executor_string, // Generate solver auto solver_gen = cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(dp_2).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) - .with_preconditioner(bj::build().on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(dp_2), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) + .with_preconditioner(bj::build()) .on(exec); auto solver = solver_gen->generate(gko::give(matrix)); diff --git a/examples/papi-logging/papi-logging.cpp b/examples/papi-logging/papi-logging.cpp index 1ae2ae9ec08..0b26e56dd80 100644 --- a/examples/papi-logging/papi-logging.cpp +++ b/examples/papi-logging/papi-logging.cpp @@ -177,11 +177,9 @@ int main(int argc, char* argv[]) const RealValueType reduction_factor{1e-7}; auto solver_gen = cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(20u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(20u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) .on(exec); auto solver = solver_gen->generate(A); diff --git a/examples/performance-debugging/performance-debugging.cpp b/examples/performance-debugging/performance-debugging.cpp index 5f036728924..c8f741114d2 100644 --- a/examples/performance-debugging/performance-debugging.cpp +++ b/examples/performance-debugging/performance-debugging.cpp @@ -416,10 +416,8 @@ int main(int argc, char* argv[]) solver::build() .with_criteria( gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec), - gko::stop::Iteration::build().with_max_iters(max_iters).on( - exec)) + .with_reduction_factor(reduction_factor), + gko::stop::Iteration::build().with_max_iters(max_iters)) .with_preconditioner(preconditioner::create(exec)) .on(exec); diff --git a/examples/poisson-solver/poisson-solver.cpp b/examples/poisson-solver/poisson-solver.cpp index e16f0b26968..eba163fb281 100644 --- a/examples/poisson-solver/poisson-solver.cpp +++ b/examples/poisson-solver/poisson-solver.cpp @@ -184,13 +184,11 @@ int main(int argc, char* argv[]) const gko::remove_complex reduction_factor = 1e-7; // Generate solver and solve the system cg::build() - .with_criteria(gko::stop::Iteration::build() - .with_max_iters(discretization_points) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) - .with_preconditioner(bj::build().on(exec)) + .with_criteria( + gko::stop::Iteration::build().with_max_iters(discretization_points), + gko::stop::ResidualNorm::build().with_reduction_factor( + reduction_factor)) + .with_preconditioner(bj::build()) .on(exec) ->generate(clone(exec, matrix)) // copy the matrix to the executor ->apply(rhs, u); diff --git a/examples/preconditioned-solver/preconditioned-solver.cpp b/examples/preconditioned-solver/preconditioned-solver.cpp index b64b588c4ef..cb3d34be8bc 100644 --- a/examples/preconditioned-solver/preconditioned-solver.cpp +++ b/examples/preconditioned-solver/preconditioned-solver.cpp @@ -95,14 +95,12 @@ int main(int argc, char* argv[]) // Create solver factory auto solver_gen = cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(20u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(20u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) // Add preconditioner, these 2 lines are the only // difference from the simple solver example - .with_preconditioner(bj::build().with_max_block_size(8u).on(exec)) + .with_preconditioner(bj::build().with_max_block_size(8u)) .on(exec); // Create solver auto solver = solver_gen->generate(A); diff --git a/examples/preconditioner-export/preconditioner-export.cpp b/examples/preconditioner-export/preconditioner-export.cpp index 81aeece1cb1..16baffc6472 100644 --- a/examples/preconditioner-export/preconditioner-export.cpp +++ b/examples/preconditioner-export/preconditioner-export.cpp @@ -193,13 +193,11 @@ int main(int argc, char* argv[]) auto factory = gko::preconditioner::Ilu, gko::preconditioner::UpperIsai<>>::build() - .with_factorization_factory(fact_factory) - .with_l_solver_factory(gko::preconditioner::LowerIsai<>::build() - .with_sparsity_power(sparsity_power) - .on(exec)) - .with_u_solver_factory(gko::preconditioner::UpperIsai<>::build() - .with_sparsity_power(sparsity_power) - .on(exec)) + .with_factorization(fact_factory) + .with_l_solver(gko::preconditioner::LowerIsai<>::build() + .with_sparsity_power(sparsity_power)) + .with_u_solver(gko::preconditioner::UpperIsai<>::build() + .with_sparsity_power(sparsity_power)) .on(exec); auto ilu_isai = try_generate([&] { return factory->generate(mtx); }); output(ilu_isai->get_l_solver()->get_approximate_inverse(), @@ -220,13 +218,11 @@ int main(int argc, char* argv[]) auto factory = gko::preconditioner::Ilu, gko::preconditioner::UpperIsai<>>::build() - .with_factorization_factory(fact_factory) - .with_l_solver_factory(gko::preconditioner::LowerIsai<>::build() - .with_sparsity_power(sparsity_power) - .on(exec)) - .with_u_solver_factory(gko::preconditioner::UpperIsai<>::build() - .with_sparsity_power(sparsity_power) - .on(exec)) + .with_factorization(fact_factory) + .with_l_solver(gko::preconditioner::LowerIsai<>::build() + .with_sparsity_power(sparsity_power)) + .with_u_solver(gko::preconditioner::UpperIsai<>::build() + .with_sparsity_power(sparsity_power)) .on(exec); auto ilu_isai = try_generate([&] { return factory->generate(mtx); }); output(ilu_isai->get_l_solver()->get_approximate_inverse(), @@ -250,13 +246,11 @@ int main(int argc, char* argv[]) auto factory = gko::preconditioner::Ilu, gko::preconditioner::UpperIsai<>>::build() - .with_factorization_factory(fact_factory) - .with_l_solver_factory(gko::preconditioner::LowerIsai<>::build() - .with_sparsity_power(sparsity_power) - .on(exec)) - .with_u_solver_factory(gko::preconditioner::UpperIsai<>::build() - .with_sparsity_power(sparsity_power) - .on(exec)) + .with_factorization(fact_factory) + .with_l_solver(gko::preconditioner::LowerIsai<>::build() + .with_sparsity_power(sparsity_power)) + .with_u_solver(gko::preconditioner::UpperIsai<>::build() + .with_sparsity_power(sparsity_power)) .on(exec); auto ilu_isai = try_generate([&] { return factory->generate(mtx); }); output(ilu_isai->get_l_solver()->get_approximate_inverse(), diff --git a/examples/simple-solver-logging/simple-solver-logging.cpp b/examples/simple-solver-logging/simple-solver-logging.cpp index 02318dd7784..2ef47524612 100644 --- a/examples/simple-solver-logging/simple-solver-logging.cpp +++ b/examples/simple-solver-logging/simple-solver-logging.cpp @@ -136,9 +136,8 @@ int main(int argc, char* argv[]) // Generate solver auto solver_gen = cg::build() - .with_criteria( - residual_criterion, - gko::stop::Iteration::build().with_max_iters(20u).on(exec)) + .with_criteria(residual_criterion, + gko::stop::Iteration::build().with_max_iters(20u)) .on(exec); auto solver = solver_gen->generate(A); diff --git a/examples/simple-solver/simple-solver.cpp b/examples/simple-solver/simple-solver.cpp index 81dc9ee6d74..d80c0633ab8 100644 --- a/examples/simple-solver/simple-solver.cpp +++ b/examples/simple-solver/simple-solver.cpp @@ -130,11 +130,9 @@ int main(int argc, char* argv[]) const RealValueType reduction_factor{1e-7}; auto solver_gen = cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(20u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(20u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(reduction_factor)) .on(exec); // Generate the solver from the matrix. The solver factory built in the // previous step takes a "matrix"(a gko::LinOp to be more general) as an diff --git a/examples/three-pt-stencil-solver/three-pt-stencil-solver.cpp b/examples/three-pt-stencil-solver/three-pt-stencil-solver.cpp index 63adfaa5571..f4af38882b0 100644 --- a/examples/three-pt-stencil-solver/three-pt-stencil-solver.cpp +++ b/examples/three-pt-stencil-solver/three-pt-stencil-solver.cpp @@ -216,13 +216,11 @@ void solve_system(const std::string& executor_string, // Generate solver auto solver_gen = cg::build() - .with_criteria(gko::stop::Iteration::build() - .with_max_iters(gko::size_type(dp)) - .on(exec), + .with_criteria(gko::stop::Iteration::build().with_max_iters( + gko::size_type(dp)), gko::stop::ResidualNorm::build() - .with_reduction_factor(reduction_factor) - .on(exec)) - .with_preconditioner(bj::build().on(exec)) + .with_reduction_factor(reduction_factor)) + .with_preconditioner(bj::build()) .on(exec); auto solver = solver_gen->generate(gko::give(matrix)); diff --git a/include/ginkgo/core/base/abstract_factory.hpp b/include/ginkgo/core/base/abstract_factory.hpp index 1c5043c186f..cca440afe6c 100644 --- a/include/ginkgo/core/base/abstract_factory.hpp +++ b/include/ginkgo/core/base/abstract_factory.hpp @@ -34,6 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define GKO_PUBLIC_CORE_BASE_ABSTRACT_FACTORY_HPP_ +#include + + #include @@ -257,7 +260,11 @@ class enable_parameters_type { */ std::unique_ptr on(std::shared_ptr exec) const { - auto factory = std::unique_ptr(new Factory(exec, *self())); + ConcreteParametersType copy = *self(); + for (const auto& item : deferred_factories) { + item.second(exec, copy); + } + auto factory = std::unique_ptr(new Factory(exec, copy)); for (auto& logger : loggers) { factory->add_logger(logger); }; @@ -271,9 +278,346 @@ class enable_parameters_type { * Loggers to be attached to the factory and generated object. */ std::vector> loggers{}; + + /** + * Deferred factory parameter initialization functions that will be called + * in on(). Their names usually correspond to the variable names in the + * parameter type. They will be provided the executor and the parameter + * object currently being initialized from the generators. + */ + std::unordered_map exec, + ConcreteParametersType&)>> + deferred_factories; }; +/** + * This Macro will generate a new type containing the parameters for the factory + * `_factory_name`. For more details, see #GKO_ENABLE_LIN_OP_FACTORY(). + * It is required to use this macro **before** calling the + * macro #GKO_ENABLE_LIN_OP_FACTORY(). + * It is also required to use the same names for all parameters between both + * macros. + * + * @param _parameters_name name of the parameters member in the class + * @param _factory_name name of the generated factory type + * + * @ingroup LinOp + */ +#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name) \ +public: \ + class _factory_name; \ + struct _parameters_name##_type \ + : public ::gko::enable_parameters_type<_parameters_name##_type, \ + _factory_name> + + +/** + * Represents a factory parameter of factory type that can either initialized by + * a pre-existing factory or by passing in a factory_parameters object whose + * `.on(exec)` will be called to instantiate a factory. + * + * @tparam FactoryType the type of factory that can be instantiated from this + * object. + */ +template +class deferred_factory_parameter { +public: + /** Creates an empty deferred factory parameter. */ + deferred_factory_parameter() = default; + + /** Creates a deferred factory parameter returning a nullptr. */ + deferred_factory_parameter(std::nullptr_t) + { + generator_ = [](std::shared_ptr) { return nullptr; }; + } + + /** + * Creates a deferred factory parameter from a preexisting factory with + * shared ownership. + */ + template >::value>* = nullptr> + deferred_factory_parameter(std::shared_ptr factory) + { + generator_ = + [factory = std::shared_ptr(std::move(factory))]( + std::shared_ptr) { return factory; }; + } + + /** + * Creates a deferred factory parameter by taking ownership of a + * preexisting factory with unique ownership. + */ + template >::value>* = nullptr> + deferred_factory_parameter( + std::unique_ptr factory) + { + generator_ = + [factory = std::shared_ptr(std::move(factory))]( + std::shared_ptr) { return factory; }; + } + + /** + * Creates a deferred factory parameter object from a + * factory_parameters-like object. To instantiate the actual factory, the + * parameter's `.on(exec)` function will be called. + */ + template ().on( + std::shared_ptr{}))> + deferred_factory_parameter(ParametersType parameters) + { + generator_ = [parameters](std::shared_ptr exec) + -> std::shared_ptr { + return parameters.on(exec); + }; + } + + /** + * Instantiates the deferred parameter into an actual factory. This will + * throw if the deferred factory parameter is empty. + */ + std::shared_ptr on( + std::shared_ptr exec) const + { + if (this->is_empty()) { + GKO_NOT_SUPPORTED(*this); + } + return generator_(exec); + } + + /** Returns true iff the parameter is empty. */ + bool is_empty() const { return !bool(generator_); } + +private: + std::function( + std::shared_ptr)> + generator_; +}; + + +/** + * Defines a build method for the factory, simplifying its construction by + * removing the repetitive typing of factory's name. + * + * @param _factory_name the factory for which to define the method + * + * @ingroup LinOp + */ +#define GKO_ENABLE_BUILD_METHOD(_factory_name) \ + static auto build()->decltype(_factory_name::create()) \ + { \ + return _factory_name::create(); \ + } \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") + + +#if !(defined(__CUDACC__) || defined(__HIPCC__)) +/** + * Creates a factory parameter in the factory parameters structure. + * + * @param _name name of the parameter + * @param __VA_ARGS__ default value of the parameter + * + * @see GKO_ENABLE_LIN_OP_FACTORY for more details, and usage example + * + * @deprecated Use GKO_FACTORY_PARAMETER_SCALAR or GKO_FACTORY_PARAMETER_VECTOR + * + * @ingroup LinOp + */ +#define GKO_FACTORY_PARAMETER(_name, ...) \ + mutable _name{__VA_ARGS__}; \ + \ + template \ + auto with_##_name(Args&&... _value)->std::decay_t& \ + { \ + using type = decltype(this->_name); \ + this->_name = type{std::forward(_value)...}; \ + return *this; \ + } \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") + +/** + * Creates a scalar factory parameter in the factory parameters structure. + * + * Scalar in this context means that the constructor for this type only takes + * a single parameter. + * + * @param _name name of the parameter + * @param _default default value of the parameter + * + * @see GKO_ENABLE_LIN_OP_FACTORY for more details, and usage example + * + * @ingroup LinOp + */ +#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default) \ + GKO_FACTORY_PARAMETER(_name, _default) + +/** + * Creates a vector factory parameter in the factory parameters structure. + * + * Vector in this context means that the constructor for this type takes + * multiple parameters. + * + * @param _name name of the parameter + * @param _default default value of the parameter + * + * @see GKO_ENABLE_LIN_OP_FACTORY for more details, and usage example + * + * @ingroup LinOp + */ +#define GKO_FACTORY_PARAMETER_VECTOR(_name, ...) \ + GKO_FACTORY_PARAMETER(_name, __VA_ARGS__) +#else // defined(__CUDACC__) || defined(__HIPCC__) +// A workaround for the NVCC compiler - parameter pack expansion does not work +// properly, because while the assignment to a scalar value is translated by +// cudafe into a C-style cast, the parameter pack expansion is not removed and +// `Args&&... args` is still kept as a parameter pack. +#define GKO_FACTORY_PARAMETER(_name, ...) \ + mutable _name{__VA_ARGS__}; \ + \ + template \ + auto with_##_name(Args&&... _value)->std::decay_t& \ + { \ + GKO_NOT_IMPLEMENTED; \ + return *this; \ + } \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") + +#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default) \ + mutable _name{_default}; \ + \ + template \ + auto with_##_name(Arg&& _value)->std::decay_t& \ + { \ + using type = decltype(this->_name); \ + this->_name = type{std::forward(_value)}; \ + return *this; \ + } \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") + +#define GKO_FACTORY_PARAMETER_VECTOR(_name, ...) \ + mutable _name{__VA_ARGS__}; \ + \ + template \ + auto with_##_name(Args&&... _value)->std::decay_t& \ + { \ + using type = decltype(this->_name); \ + this->_name = type{std::forward(_value)...}; \ + return *this; \ + } \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") +#endif // defined(__CUDACC__) || defined(__HIPCC__) + +/** + * Creates a factory parameter of factory type. The parameter can either be set + * directly, or its creation can be deferred until the executor is set in the + * `.on(exec)` function call, by using a deferred_factory_parameter. + * + * @param _name name of the parameter + * @param _type pointee type of the parameter, e.g. LinOpFactory + * + */ +#define GKO_DEFERRED_FACTORY_PARAMETER(_name, _type) \ +public: \ + std::shared_ptr _name{}; \ + parameters_type& with_##_name(deferred_factory_parameter<_type> factory) \ + { \ + this->_name##_generator_ = std::move(factory); \ + this->deferred_factories[#_name] = [](const auto& exec, \ + auto& params) { \ + if (!params._name##_generator_.is_empty()) { \ + params._name = params._name##_generator_.on(exec); \ + } \ + }; \ + return *this; \ + } \ + \ +private: \ + deferred_factory_parameter<_type> _name##_generator_; \ + \ +public: \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") + +/** + * Creates a factory parameter representing a vector of factories type. The + * parameter can either be set directly, or its creation can be deferred until + * the executor is set in the + * `.on(exec)` function call, by using a vector of deferred_factory_parameters. + * + * @param _name name of the parameter + * @param _type pointee type of the vector entries, e.g. LinOpFactory + * + */ +#define GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(_name, _type) \ +public: \ + std::vector> _name{}; \ + template >...>::value>> \ + parameters_type& with_##_name(Args&&... factories) \ + { \ + this->_name##_generator_ = {deferred_factory_parameter<_type>{ \ + std::forward(factories)}...}; \ + this->deferred_factories[#_name] = [](const auto& exec, \ + auto& params) { \ + if (!params._name##_generator_.empty()) { \ + params._name.clear(); \ + for (auto& generator : params._name##_generator_) { \ + params._name.push_back(generator.on(exec)); \ + } \ + } \ + }; \ + return *this; \ + } \ + template \ + parameters_type& with_##_name(const std::vector& factories) \ + { \ + this->_name##_generator_.clear(); \ + for (const auto& factory : factories) { \ + this->_name##_generator_.push_back(factory); \ + } \ + this->deferred_factories[#_name] = [](const auto& exec, \ + auto& params) { \ + if (!params._name##_generator_.empty()) { \ + params._name.clear(); \ + for (auto& generator : params._name##_generator_) { \ + params._name.push_back(generator.on(exec)); \ + } \ + } \ + }; \ + return *this; \ + } \ + \ +private: \ + std::vector> _name##_generator_; \ + \ +public: \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") + + } // namespace gko diff --git a/include/ginkgo/core/base/lin_op.hpp b/include/ginkgo/core/base/lin_op.hpp index c06c43bbb6e..407fafda0d1 100644 --- a/include/ginkgo/core/base/lin_op.hpp +++ b/include/ginkgo/core/base/lin_op.hpp @@ -949,26 +949,6 @@ using EnableDefaultLinOpFactory = EnableDefaultFactory; -/** - * This Macro will generate a new type containing the parameters for the factory - * `_factory_name`. For more details, see #GKO_ENABLE_LIN_OP_FACTORY(). - * It is required to use this macro **before** calling the - * macro #GKO_ENABLE_LIN_OP_FACTORY(). - * It is also required to use the same names for all parameters between both - * macros. - * - * @param _parameters_name name of the parameters member in the class - * @param _factory_name name of the generated factory type - * - * @ingroup LinOp - */ -#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name) \ -public: \ - class _factory_name; \ - struct _parameters_name##_type \ - : public ::gko::enable_parameters_type<_parameters_name##_type, \ - _factory_name> - /** * This macro will generate a default implementation of a LinOpFactory for the @@ -1084,134 +1064,6 @@ public: \ "semi-colon warnings") -/** - * Defines a build method for the factory, simplifying its construction by - * removing the repetitive typing of factory's name. - * - * @param _factory_name the factory for which to define the method - * - * @ingroup LinOp - */ -#define GKO_ENABLE_BUILD_METHOD(_factory_name) \ - static auto build()->decltype(_factory_name::create()) \ - { \ - return _factory_name::create(); \ - } \ - static_assert(true, \ - "This assert is used to counter the false positive extra " \ - "semi-colon warnings") - - -#if !(defined(__CUDACC__) || defined(__HIPCC__)) -/** - * Creates a factory parameter in the factory parameters structure. - * - * @param _name name of the parameter - * @param __VA_ARGS__ default value of the parameter - * - * @see GKO_ENABLE_LIN_OP_FACTORY for more details, and usage example - * - * @deprecated Use GKO_FACTORY_PARAMETER_SCALAR or GKO_FACTORY_PARAMETER_VECTOR - * - * @ingroup LinOp - */ -#define GKO_FACTORY_PARAMETER(_name, ...) \ - mutable _name{__VA_ARGS__}; \ - \ - template \ - auto with_##_name(Args&&... _value) \ - const->const std::decay_t& \ - { \ - using type = decltype(this->_name); \ - this->_name = type{std::forward(_value)...}; \ - return *this; \ - } \ - static_assert(true, \ - "This assert is used to counter the false positive extra " \ - "semi-colon warnings") - -/** - * Creates a scalar factory parameter in the factory parameters structure. - * - * Scalar in this context means that the constructor for this type only takes - * a single parameter. - * - * @param _name name of the parameter - * @param _default default value of the parameter - * - * @see GKO_ENABLE_LIN_OP_FACTORY for more details, and usage example - * - * @ingroup LinOp - */ -#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default) \ - GKO_FACTORY_PARAMETER(_name, _default) - -/** - * Creates a vector factory parameter in the factory parameters structure. - * - * Vector in this context means that the constructor for this type takes - * multiple parameters. - * - * @param _name name of the parameter - * @param _default default value of the parameter - * - * @see GKO_ENABLE_LIN_OP_FACTORY for more details, and usage example - * - * @ingroup LinOp - */ -#define GKO_FACTORY_PARAMETER_VECTOR(_name, ...) \ - GKO_FACTORY_PARAMETER(_name, __VA_ARGS__) -#else // defined(__CUDACC__) || defined(__HIPCC__) -// A workaround for the NVCC compiler - parameter pack expansion does not work -// properly, because while the assignment to a scalar value is translated by -// cudafe into a C-style cast, the parameter pack expansion is not removed and -// `Args&&... args` is still kept as a parameter pack. -#define GKO_FACTORY_PARAMETER(_name, ...) \ - mutable _name{__VA_ARGS__}; \ - \ - template \ - auto with_##_name(Args&&... _value) \ - const->const std::decay_t& \ - { \ - GKO_NOT_IMPLEMENTED; \ - return *this; \ - } \ - static_assert(true, \ - "This assert is used to counter the false positive extra " \ - "semi-colon warnings") - -#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default) \ - mutable _name{_default}; \ - \ - template \ - auto with_##_name(Arg&& _value) \ - const->const std::decay_t& \ - { \ - using type = decltype(this->_name); \ - this->_name = type{std::forward(_value)}; \ - return *this; \ - } \ - static_assert(true, \ - "This assert is used to counter the false positive extra " \ - "semi-colon warnings") - -#define GKO_FACTORY_PARAMETER_VECTOR(_name, ...) \ - mutable _name{__VA_ARGS__}; \ - \ - template \ - auto with_##_name(Args&&... _value) \ - const->const std::decay_t& \ - { \ - using type = decltype(this->_name); \ - this->_name = type{std::forward(_value)...}; \ - return *this; \ - } \ - static_assert(true, \ - "This assert is used to counter the false positive extra " \ - "semi-colon warnings") -#endif // defined(__CUDACC__) || defined(__HIPCC__) - - } // namespace gko diff --git a/include/ginkgo/core/base/std_extensions.hpp b/include/ginkgo/core/base/std_extensions.hpp index 69629f98e06..1064ae464f0 100644 --- a/include/ginkgo/core/base/std_extensions.hpp +++ b/include/ginkgo/core/base/std_extensions.hpp @@ -128,6 +128,16 @@ constexpr bool less_equal(const T&& lhs, const T&& rhs) } +// available in with C++17 +template +struct conjunction : std::true_type {}; +template +struct conjunction : B1 {}; +template +struct conjunction + : std::conditional_t, B1> {}; + + } // namespace xstd } // namespace gko diff --git a/include/ginkgo/core/distributed/preconditioner/schwarz.hpp b/include/ginkgo/core/distributed/preconditioner/schwarz.hpp index 441bc63d22c..f31bd96aa2e 100644 --- a/include/ginkgo/core/distributed/preconditioner/schwarz.hpp +++ b/include/ginkgo/core/distributed/preconditioner/schwarz.hpp @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if GINKGO_BUILD_MPI +#include #include #include #include @@ -93,8 +94,7 @@ class Schwarz /** * Local solver factory. */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - local_solver_factory, nullptr); + GKO_DEFERRED_FACTORY_PARAMETER(local_solver, LinOpFactory); }; GKO_ENABLE_LIN_OP_FACTORY(Schwarz, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/include/ginkgo/core/preconditioner/ic.hpp b/include/ginkgo/core/preconditioner/ic.hpp index aa19a004dc1..97e7fe37871 100644 --- a/include/ginkgo/core/preconditioner/ic.hpp +++ b/include/ginkgo/core/preconditioner/ic.hpp @@ -119,19 +119,68 @@ class Ic : public EnableLinOp>, public Transposable { using index_type = IndexType; using transposed_type = Ic; - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { + class Factory; + + struct parameters_type + : public enable_parameters_type { /** * Factory for the L solver */ - std::shared_ptr - GKO_FACTORY_PARAMETER_SCALAR(l_solver_factory, nullptr); + std::shared_ptr + l_solver_factory{}; /** * Factory for the factorization */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - factorization_factory, nullptr); + std::shared_ptr factorization_factory{}; + + [[deprecated("use with_l_solver instead")]] parameters_type& + with_l_solver_factory( + deferred_factory_parameter solver) + { + return with_l_solver(std::move(solver)); + } + + parameters_type& with_l_solver( + deferred_factory_parameter solver) + { + this->l_solver_generator = std::move(solver); + this->deferred_factories["l_solver"] = [](const auto& exec, + auto& params) { + if (!params.l_solver_generator.is_empty()) { + params.l_solver_factory = + params.l_solver_generator.on(exec); + } + }; + return *this; + } + + [[deprecated("use with_factorization instead")]] parameters_type& + with_factorization_factory( + deferred_factory_parameter factorization) + { + return with_factorization(std::move(factorization)); + } + + parameters_type& with_factorization( + deferred_factory_parameter factorization) + { + this->factorization_generator = std::move(factorization); + this->deferred_factories["factorization"] = [](const auto& exec, + auto& params) { + if (!params.factorization_generator.is_empty()) { + params.factorization_factory = + params.factorization_generator.on(exec); + } + }; + return *this; + } + + private: + deferred_factory_parameter + l_solver_generator; + + deferred_factory_parameter factorization_generator; }; GKO_ENABLE_LIN_OP_FACTORY(Ic, parameters, Factory); @@ -365,12 +414,10 @@ class Ic : public EnableLinOp>, public Transposable { static_cast(mtx->get_size()[0])}; return SolverType::build() - .with_criteria(gko::stop::Iteration::build() - .with_max_iters(default_max_iters) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(default_reduce_residual) - .on(exec)) + .with_criteria( + gko::stop::Iteration::build().with_max_iters(default_max_iters), + gko::stop::ResidualNorm::build() + .with_reduction_factor(default_reduce_residual)) .on(exec) ->generate(mtx); } diff --git a/include/ginkgo/core/preconditioner/ilu.hpp b/include/ginkgo/core/preconditioner/ilu.hpp index 7db9d19c7c2..d0f32c18c8c 100644 --- a/include/ginkgo/core/preconditioner/ilu.hpp +++ b/include/ginkgo/core/preconditioner/ilu.hpp @@ -131,25 +131,98 @@ class Ilu : public EnableLinOp< Ilu; - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { + class Factory; + + struct parameters_type + : public enable_parameters_type { /** * Factory for the L solver */ - std::shared_ptr - GKO_FACTORY_PARAMETER_SCALAR(l_solver_factory, nullptr); + std::shared_ptr + l_solver_factory{}; /** * Factory for the U solver */ - std::shared_ptr - GKO_FACTORY_PARAMETER_SCALAR(u_solver_factory, nullptr); + std::shared_ptr + u_solver_factory{}; /** * Factory for the factorization */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - factorization_factory, nullptr); + std::shared_ptr factorization_factory{}; + + [[deprecated("use with_l_solver instead")]] parameters_type& + with_l_solver_factory( + deferred_factory_parameter solver) + { + return with_l_solver(std::move(solver)); + } + + parameters_type& with_l_solver( + deferred_factory_parameter solver) + { + this->l_solver_generator = std::move(solver); + this->deferred_factories["l_solver"] = [](const auto& exec, + auto& params) { + if (!params.l_solver_generator.is_empty()) { + params.l_solver_factory = + params.l_solver_generator.on(exec); + } + }; + return *this; + } + + [[deprecated("use with_u_solver instead")]] parameters_type& + with_u_solver_factory( + deferred_factory_parameter solver) + { + return with_u_solver(std::move(solver)); + } + + parameters_type& with_u_solver( + deferred_factory_parameter solver) + { + this->u_solver_generator = std::move(solver); + this->deferred_factories["u_solver"] = [](const auto& exec, + auto& params) { + if (!params.u_solver_generator.is_empty()) { + params.u_solver_factory = + params.u_solver_generator.on(exec); + } + }; + return *this; + } + + [[deprecated("use with_factorization instead")]] parameters_type& + with_factorization_factory( + deferred_factory_parameter factorization) + { + return with_factorization(std::move(factorization)); + } + + parameters_type& with_factorization( + deferred_factory_parameter factorization) + { + this->factorization_generator = std::move(factorization); + this->deferred_factories["factorization"] = [](const auto& exec, + auto& params) { + if (!params.factorization_generator.is_empty()) { + params.factorization_factory = + params.factorization_generator.on(exec); + } + }; + return *this; + } + + private: + deferred_factory_parameter + l_solver_generator; + + deferred_factory_parameter + u_solver_generator; + + deferred_factory_parameter factorization_generator; }; GKO_ENABLE_LIN_OP_FACTORY(Ilu, parameters, Factory); @@ -393,12 +466,10 @@ class Ilu : public EnableLinOp< static_cast(mtx->get_size()[0])}; return SolverType::build() - .with_criteria(gko::stop::Iteration::build() - .with_max_iters(default_max_iters) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(default_reduce_residual) - .on(exec)) + .with_criteria( + gko::stop::Iteration::build().with_max_iters(default_max_iters), + gko::stop::ResidualNorm::build() + .with_reduction_factor(default_reduce_residual)) .on(exec) ->generate(mtx); } diff --git a/include/ginkgo/core/solver/bicg.hpp b/include/ginkgo/core/solver/bicg.hpp index c7b47a0e807..205be85df6c 100644 --- a/include/ginkgo/core/solver/bicg.hpp +++ b/include/ginkgo/core/solver/bicg.hpp @@ -99,27 +99,12 @@ class Bicg */ bool apply_uses_initial_guess() const override { return true; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - }; + class Factory; + + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> {}; + GKO_ENABLE_LIN_OP_FACTORY(Bicg, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/include/ginkgo/core/solver/bicgstab.hpp b/include/ginkgo/core/solver/bicgstab.hpp index 214e669b2ff..58d76c5e0df 100644 --- a/include/ginkgo/core/solver/bicgstab.hpp +++ b/include/ginkgo/core/solver/bicgstab.hpp @@ -98,27 +98,11 @@ class Bicgstab */ bool apply_uses_initial_guess() const override { return true; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - }; + class Factory; + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> {}; + GKO_ENABLE_LIN_OP_FACTORY(Bicgstab, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/include/ginkgo/core/solver/cb_gmres.hpp b/include/ginkgo/core/solver/cb_gmres.hpp index a2dbb1efce1..9bf4cf91a76 100644 --- a/include/ginkgo/core/solver/cb_gmres.hpp +++ b/include/ginkgo/core/solver/cb_gmres.hpp @@ -153,38 +153,23 @@ class CbGmres : public EnableLinOp>, return parameters_.storage_precision; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { + class Factory; + + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> { /** * Determines which storage type is used. */ cb_gmres::storage_precision GKO_FACTORY_PARAMETER_SCALAR( storage_precision, cb_gmres::storage_precision::reduce1); - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - /** * Krylov dimension factory. */ size_type GKO_FACTORY_PARAMETER_SCALAR(krylov_dim, 100u); }; + GKO_ENABLE_LIN_OP_FACTORY(CbGmres, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/include/ginkgo/core/solver/cg.hpp b/include/ginkgo/core/solver/cg.hpp index bc0861cf270..c0fff29fedd 100644 --- a/include/ginkgo/core/solver/cg.hpp +++ b/include/ginkgo/core/solver/cg.hpp @@ -92,27 +92,12 @@ class Cg : public EnableLinOp>, */ bool apply_uses_initial_guess() const override { return true; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - }; + class Factory; + + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> {}; + GKO_ENABLE_LIN_OP_FACTORY(Cg, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/include/ginkgo/core/solver/cgs.hpp b/include/ginkgo/core/solver/cgs.hpp index 22f81d8a292..57a834b0ead 100644 --- a/include/ginkgo/core/solver/cgs.hpp +++ b/include/ginkgo/core/solver/cgs.hpp @@ -90,27 +90,12 @@ class Cgs */ bool apply_uses_initial_guess() const override { return true; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - }; + class Factory; + + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> {}; + GKO_ENABLE_LIN_OP_FACTORY(Cgs, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/include/ginkgo/core/solver/direct.hpp b/include/ginkgo/core/solver/direct.hpp index 4a9a69731be..ee6783ff96d 100644 --- a/include/ginkgo/core/solver/direct.hpp +++ b/include/ginkgo/core/solver/direct.hpp @@ -74,8 +74,9 @@ class Direct : public EnableLinOp>, std::unique_ptr conj_transpose() const override; - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { + class Factory; + + struct parameters_type : enable_parameters_type { /** * Number of right hand sides. * @@ -86,8 +87,7 @@ class Direct : public EnableLinOp>, gko::size_type GKO_FACTORY_PARAMETER_SCALAR(num_rhs, 1u); /** The factorization factory to use for generating the factors. */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - factorization, nullptr); + GKO_DEFERRED_FACTORY_PARAMETER(factorization, LinOpFactory); }; GKO_ENABLE_LIN_OP_FACTORY(Direct, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/include/ginkgo/core/solver/fcg.hpp b/include/ginkgo/core/solver/fcg.hpp index cad7a29fc27..b6715f07512 100644 --- a/include/ginkgo/core/solver/fcg.hpp +++ b/include/ginkgo/core/solver/fcg.hpp @@ -98,27 +98,12 @@ class Fcg */ bool apply_uses_initial_guess() const override { return true; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - }; + class Factory; + + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> {}; + GKO_ENABLE_LIN_OP_FACTORY(Fcg, parameters, Factory); GKO_ENABLE_BUILD_METHOD(Factory); diff --git a/include/ginkgo/core/solver/gcr.hpp b/include/ginkgo/core/solver/gcr.hpp index fdc95d30c8f..8dc68e6e33d 100644 --- a/include/ginkgo/core/solver/gcr.hpp +++ b/include/ginkgo/core/solver/gcr.hpp @@ -108,30 +108,12 @@ class Gcr */ void set_krylov_dim(size_type other) { parameters_.krylov_dim = other; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - - /** - * Krylov dimension factory. - */ + class Factory; + + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> { + /** Krylov subspace dimension/restart value. */ size_type GKO_FACTORY_PARAMETER_SCALAR(krylov_dim, 0u); }; GKO_ENABLE_LIN_OP_FACTORY(Gcr, parameters, Factory); diff --git a/include/ginkgo/core/solver/gmres.hpp b/include/ginkgo/core/solver/gmres.hpp index d7d0f57a8a4..0ea056c9333 100644 --- a/include/ginkgo/core/solver/gmres.hpp +++ b/include/ginkgo/core/solver/gmres.hpp @@ -109,35 +109,16 @@ class Gmres */ void set_krylov_dim(size_type other) { parameters_.krylov_dim = other; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); - - /** - * Krylov dimension factory. - */ + + class Factory; + + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> { + /** Krylov subspace dimension/restart value. */ size_type GKO_FACTORY_PARAMETER_SCALAR(krylov_dim, 0u); - /** - * Flexible GMRES - */ + /** Flexible GMRES */ bool GKO_FACTORY_PARAMETER_SCALAR(flexible, false); }; GKO_ENABLE_LIN_OP_FACTORY(Gmres, parameters, Factory); diff --git a/include/ginkgo/core/solver/idr.hpp b/include/ginkgo/core/solver/idr.hpp index fc677f33171..a7b8af31bf4 100644 --- a/include/ginkgo/core/solver/idr.hpp +++ b/include/ginkgo/core/solver/idr.hpp @@ -180,27 +180,11 @@ class Idr parameters_.complex_subspace = other; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); - - /** - * Preconditioner factory. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - preconditioner, nullptr); - - /** - * Already generated preconditioner. If one is provided, the factory - * `preconditioner` will be ignored. - */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - generated_preconditioner, nullptr); + class Factory; + struct parameters_type + : enable_preconditioned_iterative_solver_factory_parameters< + parameters_type, Factory> { /** * Dimension of the subspace S. Determines how many intermediate * residuals are computed in each iteration. diff --git a/include/ginkgo/core/solver/ir.hpp b/include/ginkgo/core/solver/ir.hpp index c5c69c1fb67..468e539f487 100644 --- a/include/ginkgo/core/solver/ir.hpp +++ b/include/ginkgo/core/solver/ir.hpp @@ -177,19 +177,14 @@ class Ir : public EnableLinOp>, */ Ir(Ir&&); - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); + class Factory; + struct parameters_type + : enable_iterative_solver_factory_parameters { /** * Inner solver factory. */ - std::shared_ptr GKO_FACTORY_PARAMETER_SCALAR( - solver, nullptr); + GKO_DEFERRED_FACTORY_PARAMETER(solver, LinOpFactory); /** * Already generated solver. If one is provided, the factory `solver` @@ -319,8 +314,7 @@ auto build_smoother(std::shared_ptr factory, return Ir::build() .with_solver(factory) .with_relaxation_factor(relaxation_factor) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(iteration).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(iteration)) .on(exec); } @@ -344,8 +338,7 @@ auto build_smoother(std::shared_ptr solver, return Ir::build() .with_generated_solver(solver) .with_relaxation_factor(relaxation_factor) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(iteration).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(iteration)) .on(exec); } diff --git a/include/ginkgo/core/solver/multigrid.hpp b/include/ginkgo/core/solver/multigrid.hpp index 2d04a889445..21860844d3e 100644 --- a/include/ginkgo/core/solver/multigrid.hpp +++ b/include/ginkgo/core/solver/multigrid.hpp @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include #include #include #include @@ -215,19 +216,16 @@ class Multigrid : public EnableLinOp, */ void set_cycle(multigrid::cycle cycle) { parameters_.cycle = cycle; } - GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory) - { - /** - * Criterion factories. - */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr); + class Factory; + + struct parameters_type + : public enable_iterative_solver_factory_parameters { /** * MultigridLevel Factory list */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(mg_level, nullptr); + GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(mg_level, LinOpFactory); /** * Custom selector size_type (size_type level, const LinOp* fine_matrix) @@ -272,17 +270,14 @@ class Multigrid : public EnableLinOp, * If any element in the vector is a `nullptr` then the smoother * application at the corresponding level is skipped. */ - using smoother_list = std::vector>; - smoother_list GKO_FACTORY_PARAMETER_VECTOR(pre_smoother, - smoother_list{}); + GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(pre_smoother, LinOpFactory); /** * Post-smooth Factory list. * It is similar to Pre-smooth Factory list. It is ignored if * the factory parameter post_uses_pre is set to true. */ - smoother_list GKO_FACTORY_PARAMETER_VECTOR(post_smoother, - smoother_list{}); + GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(post_smoother, LinOpFactory); /** * Mid-smooth Factory list. If it contains available elements, multigrid @@ -291,8 +286,7 @@ class Multigrid : public EnableLinOp, * Pre-smooth Factory list. It is ignored if the factory parameter * mid_case is not mid. */ - smoother_list GKO_FACTORY_PARAMETER_VECTOR(mid_smoother, - smoother_list{}); + GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(mid_smoother, LinOpFactory); /** * Whether post-smoothing-related calls use corresponding @@ -332,8 +326,7 @@ class Multigrid : public EnableLinOp, * If not set, then a direct LU solver will be used as solver on the * coarsest level. */ - std::vector> - GKO_FACTORY_PARAMETER_VECTOR(coarsest_solver, nullptr); + GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(coarsest_solver, LinOpFactory); /** * Custom coarsest_solver selector diff --git a/include/ginkgo/core/solver/solver_base.hpp b/include/ginkgo/core/solver/solver_base.hpp index 53909337554..3888d7fe62d 100644 --- a/include/ginkgo/core/solver/solver_base.hpp +++ b/include/ginkgo/core/solver/solver_base.hpp @@ -35,11 +35,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include #include #include #include +#include #include #include #include @@ -859,6 +861,114 @@ class EnablePreconditionedIterativeSolver }; +/** + * The parameter type shared between all iterative solvers. + * @see GKO_CREATE_FACTORY_PARAMETERS + */ +struct iterative_solver_factory_parameters { + /** + * Stopping criteria to be used by the solver. + */ + std::vector> criteria{}; +}; + + +template +struct enable_iterative_solver_factory_parameters + : enable_parameters_type, + iterative_solver_factory_parameters { + /** + * Provides stopping criteria via stop::CriterionFactory instances to be + * used by the iterative solver in a fluent interface. + */ + template + Parameters& with_criteria(Args&&... value) + { + this->criterion_generators = { + deferred_factory_parameter{ + std::forward(value)}...}; + this->deferred_factories["criteria"] = [](const auto& exec, + auto& params) { + if (!params.criterion_generators.empty()) { + params.criteria.clear(); + for (auto& generator : params.criterion_generators) { + params.criteria.push_back(generator.on(exec)); + } + } + }; + return *self(); + } + +private: + GKO_ENABLE_SELF(Parameters); + + std::vector> + criterion_generators; +}; + + +/** + * The parameter type shared between all preconditioned iterative solvers, + * excluding the parameters available in iterative_solver_factory_parameters. + * @see GKO_CREATE_FACTORY_PARAMETERS + */ +struct preconditioned_iterative_solver_factory_parameters { + /** + * The preconditioner to be used by the iterative solver. By default, no + * preconditioner is used. + */ + std::shared_ptr preconditioner{nullptr}; + + /** + * Already generated preconditioner. If one is provided, the factory + * `preconditioner` will be ignored. + */ + std::shared_ptr generated_preconditioner{nullptr}; +}; + + +template +struct enable_preconditioned_iterative_solver_factory_parameters + : enable_iterative_solver_factory_parameters, + preconditioned_iterative_solver_factory_parameters { + /** + * Provides a preconditioner factory to be used by the iterative solver in a + * fluent interface. + * @see preconditioned_iterative_solver_factory_parameters::preconditioner + */ + Parameters& with_preconditioner( + deferred_factory_parameter preconditioner) + { + this->preconditioner_generator = std::move(preconditioner); + this->deferred_factories["preconditioner"] = [](const auto& exec, + auto& params) { + if (!params.preconditioner_generator.is_empty()) { + params.preconditioner = + params.preconditioner_generator.on(exec); + } + }; + return *self(); + } + + /** + * Provides a concrete preconditioner to be used by the iterative solver in + * a fluent interface. + * @see preconditioned_iterative_solver_factory_parameters::preconditioner + */ + Parameters& with_generated_preconditioner( + std::shared_ptr generated_preconditioner) + { + this->generated_preconditioner = std::move(generated_preconditioner); + return *self(); + } + +private: + GKO_ENABLE_SELF(Parameters); + + deferred_factory_parameter preconditioner_generator; +}; + + } // namespace solver } // namespace gko diff --git a/reference/test/matrix/csr_kernels.cpp b/reference/test/matrix/csr_kernels.cpp index d56201ade02..d0265e462f2 100644 --- a/reference/test/matrix/csr_kernels.cpp +++ b/reference/test/matrix/csr_kernels.cpp @@ -56,6 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "core/matrix/csr_kernels.hpp" #include "core/matrix/csr_lookup.hpp" #include "core/test/utils.hpp" +#include "core/test/utils/assertions.hpp" namespace { @@ -810,7 +811,7 @@ TYPED_TEST(Csr, ConvertsToPrecision) GKO_ASSERT_MTX_NEAR(this->mtx2, res, residual); auto first_strategy = this->mtx2->get_strategy(); auto second_strategy = res->get_strategy(); - ASSERT_EQ(typeid(*first_strategy), typeid(*second_strategy)); + GKO_ASSERT_DYNAMIC_TYPE_EQ(first_strategy, second_strategy); } @@ -835,7 +836,7 @@ TYPED_TEST(Csr, MovesToPrecision) GKO_ASSERT_MTX_NEAR(this->mtx2, res, residual); auto first_strategy = this->mtx2->get_strategy(); auto second_strategy = res->get_strategy(); - ASSERT_EQ(typeid(*first_strategy), typeid(*second_strategy)); + GKO_ASSERT_DYNAMIC_TYPE_EQ(first_strategy, second_strategy); } diff --git a/reference/test/preconditioner/ilu.cpp b/reference/test/preconditioner/ilu.cpp index ce3ea72725f..5150626c898 100644 --- a/reference/test/preconditioner/ilu.cpp +++ b/reference/test/preconditioner/ilu.cpp @@ -80,37 +80,29 @@ class Ilu : public ::testing::Test { u_factor(gko::initialize( {{2., 1., 1.}, {0., 4., 1.}, {0., 0., 3.}}, exec)), l_u_composition(Composition::create(l_factor, u_factor)), - l_factory( - l_solver_type::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(10u).on( - exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)), - u_factory( - u_solver_type::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(10u).on( - exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)), + l_factory(l_solver_type::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(10u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)), + u_factory(u_solver_type::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(10u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)), ilu_pre_factory(ilu_prec_type::build() - .with_l_solver_factory(l_factory) - .with_u_solver_factory(u_factory) + .with_l_solver(l_factory) + .with_u_solver(u_factory) .on(exec)), ilu_rev_pre_factory(ilu_rev_prec_type::build() - .with_l_solver_factory(l_factory) - .with_u_solver_factory(u_factory) + .with_l_solver(l_factory) + .with_u_solver(u_factory) .on(exec)) {} @@ -622,9 +614,8 @@ TEST_F(DefaultIlu, CanBeUsedAsPreconditioner) { auto solver = gko::solver::Bicgstab<>::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(this->exec)) - .with_preconditioner(default_ilu_prec_type::build().on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) + .with_preconditioner(default_ilu_prec_type::build()) .on(this->exec) ->generate(this->mtx); auto x = Mtx::create(this->exec, gko::dim<2>{3, 1}); @@ -643,8 +634,7 @@ TEST_F(DefaultIlu, CanBeUsedAsGeneratedPreconditioner) default_ilu_prec_type::build().on(this->exec)->generate(this->mtx); auto solver = gko::solver::Bicgstab<>::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .with_generated_preconditioner(precond) .on(this->exec) ->generate(this->mtx); diff --git a/reference/test/preconditioner/isai_kernels.cpp b/reference/test/preconditioner/isai_kernels.cpp index eea171d60fe..86d0f40142a 100644 --- a/reference/test/preconditioner/isai_kernels.cpp +++ b/reference/test/preconditioner/isai_kernels.cpp @@ -82,16 +82,13 @@ class Isai : public ::testing::Test { : exec{gko::ReferenceExecutor::create()}, excess_solver_factory( excess_solver_type::build() - .with_preconditioner( - bj::build().with_max_block_size(16u).on(exec)) + .with_preconditioner(bj::build().with_max_block_size(16u)) .with_criteria( - gko::stop::Iteration::build().with_max_iters(1000u).on( - exec), + gko::stop::Iteration::build().with_max_iters(1000u), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::rhs_norm) .with_reduction_factor( - gko::remove_complex{1e-6}) - .on(exec)) + gko::remove_complex{1e-6})) .on(exec)), a_dense{gko::initialize({{2, 1, 2}, {1, -2, 3}, {-1, 1, 1}}, exec)}, diff --git a/reference/test/reorder/scaled_reordered.cpp b/reference/test/reorder/scaled_reordered.cpp index 8789ded37ca..edadc245b33 100644 --- a/reference/test/reorder/scaled_reordered.cpp +++ b/reference/test/reorder/scaled_reordered.cpp @@ -110,11 +110,9 @@ class ScaledReordered : public ::testing::Test { solver_factory( Bicgstab::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), tol{r::value} { diff --git a/reference/test/solver/bicg_kernels.cpp b/reference/test/solver/bicg_kernels.cpp index e317677b2de..aa27eb4afa3 100644 --- a/reference/test/solver/bicg_kernels.cpp +++ b/reference/test/solver/bicg_kernels.cpp @@ -64,17 +64,14 @@ class Bicg : public ::testing::Test { {{2, -1.0, 0.0}, {-1.0, 2, -1.0}, {0.0, -1.0, 2}}, exec)), stopped{}, non_stopped{}, - bicg_factory( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)), + bicg_factory(Solver::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(4u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)), mtx_big(gko::initialize( {{8828.0, 2673.0, 4150.0, -3139.5, 3829.5, 5856.0}, {2673.0, 10765.5, 1805.0, 73.0, 1966.0, 3919.5}, @@ -86,20 +83,16 @@ class Bicg : public ::testing::Test { bicg_factory_big( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), bicg_factory_big2( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ImplicitResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), mtx_non_symmetric(gko::initialize( {{1.0, 2.0, 3.0}, {3.0, 2.0, -1.0}, {0.0, -1.0, 2}}, exec)) diff --git a/reference/test/solver/bicgstab_kernels.cpp b/reference/test/solver/bicgstab_kernels.cpp index ec44b6b6f17..70302e95796 100644 --- a/reference/test/solver/bicgstab_kernels.cpp +++ b/reference/test/solver/bicgstab_kernels.cpp @@ -69,36 +69,29 @@ class Bicgstab : public ::testing::Test { bicgstab_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(8u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(8u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), bicgstab_factory2( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(8u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(8u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), gko::stop::ImplicitResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), bicgstab_factory_precision( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on( - exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)) { auto small_size = gko::dim<2>{2, 2}; diff --git a/reference/test/solver/cb_gmres_kernels.cpp b/reference/test/solver/cb_gmres_kernels.cpp index 1127d7caff7..60d2a32b9ee 100644 --- a/reference/test/solver/cb_gmres_kernels.cpp +++ b/reference/test/solver/cb_gmres_kernels.cpp @@ -77,15 +77,12 @@ class CbGmres : public ::testing::Test { gmres_type::build() .with_storage_precision(storage_prec) .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(100u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(this->reduction_factor()) - .on(exec)) + .with_reduction_factor(this->reduction_factor())) .on(exec)), mtx_big(gko::initialize( {{2295.7, -764.8, 1166.5, 428.9, 291.7, -774.5}, @@ -99,12 +96,10 @@ class CbGmres : public ::testing::Test { gmres_type::build() .with_storage_precision(storage_prec) .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(this->reduction_factor()) - .on(exec)) + .with_reduction_factor(this->reduction_factor())) .on(exec)), mtx_medium( gko::initialize({{-86.40, 153.30, -108.90, 8.60, -61.60}, @@ -271,16 +266,12 @@ TYPED_TEST(CbGmres, SolvesStencilSystem2) auto factory = gmres_type::build() .with_storage_precision(this->storage_prec) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - this->exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(this->exec), - gko::stop::ResidualNorm::build() - .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(this->reduction_factor()) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(100u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), + gko::stop::ResidualNorm::build() + .with_baseline(gko::stop::mode::initial_resnorm) + .with_reduction_factor(this->reduction_factor())) .on(this->exec); auto solver = factory->generate(this->mtx2); auto b = gko::initialize({33.0, 20.0, 20.0}, this->exec); @@ -526,13 +517,10 @@ TYPED_TEST(CbGmres, SolvesBigDenseSystem1WithRestart) gmres_type::build() .with_krylov_dim(4u) .with_storage_precision(this->storage_prec) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(200u).on( - this->exec), - gko::stop::ResidualNorm::build() - .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(this->reduction_factor()) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(200u), + gko::stop::ResidualNorm::build() + .with_baseline(gko::stop::mode::initial_resnorm) + .with_reduction_factor(this->reduction_factor())) .on(this->exec); auto solver = cb_gmres_factory_restart->generate(this->mtx_medium); auto b = gko::initialize( @@ -554,17 +542,13 @@ TYPED_TEST(CbGmres, SolvesWithPreconditioner) auto cb_gmres_factory_preconditioner = gmres_type::build() .with_storage_precision(this->storage_prec) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - this->exec), - gko::stop::ResidualNorm::build() - .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(this->reduction_factor()) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(100u), + gko::stop::ResidualNorm::build() + .with_baseline(gko::stop::mode::initial_resnorm) + .with_reduction_factor(this->reduction_factor())) .with_preconditioner( gko::preconditioner::Jacobi::build() - .with_max_block_size(3u) - .on(this->exec)) + .with_max_block_size(3u)) .on(this->exec); auto solver = cb_gmres_factory_preconditioner->generate(this->mtx_big); auto b = gko::initialize( diff --git a/reference/test/solver/cg_kernels.cpp b/reference/test/solver/cg_kernels.cpp index 76b8cf55946..c089442488f 100644 --- a/reference/test/solver/cg_kernels.cpp +++ b/reference/test/solver/cg_kernels.cpp @@ -64,18 +64,14 @@ class Cg : public ::testing::Test { {{2, -1.0, 0.0}, {-1.0, 2, -1.0}, {0.0, -1.0, 2}}, exec)), stopped{}, non_stopped{}, - cg_factory( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(400u).on( - exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)), + cg_factory(Solver::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(400u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)), mtx_big(gko::initialize( {{8828.0, 2673.0, 4150.0, -3139.5, 3829.5, 5856.0}, {2673.0, 10765.5, 1805.0, 73.0, 1966.0, 3919.5}, @@ -87,20 +83,16 @@ class Cg : public ::testing::Test { cg_factory_big( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), cg_factory_big2( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ImplicitResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)) { auto small_size = gko::dim<2>{2, 2}; diff --git a/reference/test/solver/cgs_kernels.cpp b/reference/test/solver/cgs_kernels.cpp index 9c3ce2071a7..91c7c1e821b 100644 --- a/reference/test/solver/cgs_kernels.cpp +++ b/reference/test/solver/cgs_kernels.cpp @@ -65,15 +65,12 @@ class Cgs : public ::testing::Test { {{1.0, -3.0, 0.0}, {-4.0, 1.0, -3.0}, {2.0, -1.0, 2.0}}, exec)), stopped{}, non_stopped{}, - cgs_factory( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(40u).on( - exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)), + cgs_factory(Solver::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(40u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)), mtx_big( gko::initialize({{-99.0, 87.0, -67.0, -62.0, -68.0, -19.0}, {-30.0, -17.0, -1.0, 9.0, 23.0, 77.0}, @@ -85,20 +82,16 @@ class Cgs : public ::testing::Test { cgs_factory_big( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), cgs_factory_big2( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ImplicitResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)) { auto small_size = gko::dim<2>{2, 2}; diff --git a/reference/test/solver/direct.cpp b/reference/test/solver/direct.cpp index 617015bac1f..f69846b548d 100644 --- a/reference/test/solver/direct.cpp +++ b/reference/test/solver/direct.cpp @@ -77,8 +77,7 @@ class Direct : public ::testing::Test { .with_factorization( gko::experimental::factorization::Lu::build() - .with_symmetric_sparsity(true) - .on(exec)) + .with_symmetric_sparsity(true)) .on(exec); solver = factory->generate(mtx); std::normal_distribution> dist(0, 1); diff --git a/reference/test/solver/fcg_kernels.cpp b/reference/test/solver/fcg_kernels.cpp index e8163752689..3dd4149405e 100644 --- a/reference/test/solver/fcg_kernels.cpp +++ b/reference/test/solver/fcg_kernels.cpp @@ -65,17 +65,14 @@ class Fcg : public ::testing::Test { {{2, -1.0, 0.0}, {-1.0, 2, -1.0}, {0.0, -1.0, 2}}, exec)), stopped{}, non_stopped{}, - fcg_factory( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)), + fcg_factory(Solver::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(4u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)), mtx_big(gko::initialize( {{8828.0, 2673.0, 4150.0, -3139.5, 3829.5, 5856.0}, {2673.0, 10765.5, 1805.0, 73.0, 1966.0, 3919.5}, @@ -87,20 +84,16 @@ class Fcg : public ::testing::Test { fcg_factory_big( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), fcg_factory_big2( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ImplicitResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)) { auto small_size = gko::dim<2>{2, 2}; diff --git a/reference/test/solver/gcr_kernels.cpp b/reference/test/solver/gcr_kernels.cpp index 888cbc3b4fe..8943a131d2b 100644 --- a/reference/test/solver/gcr_kernels.cpp +++ b/reference/test/solver/gcr_kernels.cpp @@ -72,18 +72,15 @@ class Gcr : public ::testing::Test { non_stopped{}, mtx(gko::initialize( {{1.0, 2.0, 3.0}, {3.0, 2.0, -1.0}, {0.0, -1.0, 2}}, exec)), - gcr_factory( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .with_krylov_dim(3u) - .on(exec)), + gcr_factory(Solver::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(4u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .with_krylov_dim(3u) + .on(exec)), mtx_big(gko::initialize( {{2295.7, -764.8, 1166.5, 428.9, 291.7, -774.5}, {2752.6, -1127.7, 1212.8, -299.1, 987.7, 786.8}, @@ -95,20 +92,16 @@ class Gcr : public ::testing::Test { gcr_factory_big( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), gcr_factory_big2( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ImplicitResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), mtx_medium( gko::initialize({{-86.40, 153.30, -108.90, 8.60, -61.60}, @@ -581,12 +574,9 @@ TYPED_TEST(Gcr, SolvesBigDenseSystem1WithRestart) auto gcr_factory_restart = Solver::build() .with_krylov_dim(4u) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(200u).on( - this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(200u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) .on(this->exec); auto solver = gcr_factory_restart->generate(this->mtx_medium); auto b = gko::initialize( @@ -607,16 +597,12 @@ TYPED_TEST(Gcr, SolvesWithPreconditioner) using value_type = typename TestFixture::value_type; auto gcr_factory_preconditioner = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(100u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) .with_preconditioner( gko::preconditioner::Jacobi::build() - .with_max_block_size(3u) - .on(this->exec)) + .with_max_block_size(3u)) .on(this->exec); auto solver = gcr_factory_preconditioner->generate(this->mtx_big); auto b = gko::initialize( diff --git a/reference/test/solver/gmres_kernels.cpp b/reference/test/solver/gmres_kernels.cpp index 585fec833bc..4c651e7917b 100644 --- a/reference/test/solver/gmres_kernels.cpp +++ b/reference/test/solver/gmres_kernels.cpp @@ -76,13 +76,11 @@ class Gmres : public ::testing::Test { gmres_factory( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(4u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .with_krylov_dim(3u) .on(exec)), mtx_big(gko::initialize( @@ -96,20 +94,16 @@ class Gmres : public ::testing::Test { gmres_factory_big( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), gmres_factory_big2( Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - exec), + gko::stop::Iteration::build().with_max_iters(100u), gko::stop::ImplicitResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), mtx_medium( gko::initialize({{-86.40, 153.30, -108.90, 8.60, -61.60}, @@ -724,12 +718,9 @@ TYPED_TEST(Gmres, SolvesBigDenseSystem1WithRestart) auto gmres_factory_restart = Solver::build() .with_krylov_dim(4u) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(200u).on( - this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(200u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) .on(this->exec); auto solver = gmres_factory_restart->generate(this->mtx_medium); auto b = gko::initialize( @@ -750,16 +741,12 @@ TYPED_TEST(Gmres, SolvesWithPreconditioner) using value_type = typename TestFixture::value_type; auto gmres_factory_preconditioner = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(100u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) .with_preconditioner( gko::preconditioner::Jacobi::build() - .with_max_block_size(3u) - .on(this->exec)) + .with_max_block_size(3u)) .on(this->exec); auto solver = gmres_factory_preconditioner->generate(this->mtx_big); auto b = gko::initialize( diff --git a/reference/test/solver/idr_kernels.cpp b/reference/test/solver/idr_kernels.cpp index 3e74e0c319b..da1b73a035c 100644 --- a/reference/test/solver/idr_kernels.cpp +++ b/reference/test/solver/idr_kernels.cpp @@ -62,30 +62,24 @@ class Idr : public ::testing::Test { : exec(gko::ReferenceExecutor::create()), mtx(gko::initialize( {{1.0, -3.0, 0.0}, {-4.0, 1.0, -3.0}, {2.0, -1.0, 2.0}}, exec)), - idr_factory( - Solver::build() - .with_deterministic(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(8u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)), + idr_factory(Solver::build() + .with_deterministic(true) + .with_criteria( + gko::stop::Iteration::build().with_max_iters(8u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)), idr_factory_precision( Solver::build() .with_deterministic(true) .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on( - exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)) {} diff --git a/reference/test/solver/ir_kernels.cpp b/reference/test/solver/ir_kernels.cpp index 8b4255b72ef..fc6154f3366 100644 --- a/reference/test/solver/ir_kernels.cpp +++ b/reference/test/solver/ir_kernels.cpp @@ -65,15 +65,12 @@ class Ir : public ::testing::Test { // Eigenvalues of mtx are 0.9, 1.0 and 1.1 // Richardson iteration, converges since // | relaxation_factor * lambda - 1 | < 1 - ir_factory( - Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(30u).on( - exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(exec)) - .on(exec)) + ir_factory(Solver::build() + .with_criteria( + gko::stop::Iteration::build().with_max_iters(30u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value)) + .on(exec)) {} std::shared_ptr exec; @@ -187,11 +184,9 @@ TYPED_TEST(Ir, SolvesTriangularSystemWithIterativeInnerSolver) auto solver_factory = gko::solver::Ir::build() - .with_criteria(gko::stop::Iteration::build().with_max_iters(30u).on( - this->exec), + .with_criteria(gko::stop::Iteration::build().with_max_iters(30u), gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) + .with_reduction_factor(r::value)) .with_solver(inner_solver_factory) .on(this->exec); auto b = gko::initialize({3.9, 9.0, 2.2}, this->exec); @@ -354,16 +349,15 @@ TYPED_TEST(Ir, RichardsonSolvesTriangularSystem) { using Mtx = typename TestFixture::Mtx; using value_type = typename TestFixture::value_type; - auto solver = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) - .with_relaxation_factor(value_type{0.9}) - .on(this->exec) - ->generate(this->mtx); + auto solver = + gko::solver::Ir::build() + .with_criteria(gko::stop::Iteration::build().with_max_iters(100u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value) + .on(this->exec)) + .with_relaxation_factor(value_type{0.9}) + .on(this->exec) + ->generate(this->mtx); auto b = gko::initialize({3.9, 9.0, 2.2}, this->exec); auto x = gko::initialize({0.0, 0.0, 0.0}, this->exec); @@ -386,12 +380,10 @@ TYPED_TEST(Ir, RichardsonSolvesTriangularSystemWithIterativeInnerSolver) .on(this->exec)); auto solver_factory = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(100u).on( - this->exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(r::value) - .on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(100u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(r::value) + .on(this->exec)) .with_relaxation_factor(value_type{0.9}) .with_solver(inner_solver_factory) .on(this->exec); @@ -410,8 +402,7 @@ TYPED_TEST(Ir, RichardsonTransposedSolvesTriangularSystem) using value_type = typename TestFixture::value_type; auto solver = gko::solver::Ir::build() - .with_criteria(gko::stop::Iteration::build().with_max_iters(30u).on( - this->exec), + .with_criteria(gko::stop::Iteration::build().with_max_iters(30u), gko::stop::ResidualNorm::build() .with_reduction_factor(r::value) .on(this->exec)) @@ -433,8 +424,7 @@ TYPED_TEST(Ir, RichardsonConjTransposedSolvesTriangularSystem) using value_type = typename TestFixture::value_type; auto solver = gko::solver::Ir::build() - .with_criteria(gko::stop::Iteration::build().with_max_iters(30u).on( - this->exec), + .with_criteria(gko::stop::Iteration::build().with_max_iters(30u), gko::stop::ResidualNorm::build() .with_reduction_factor(r::value) .on(this->exec)) @@ -457,8 +447,7 @@ TYPED_TEST(Ir, ApplyWithGivenInitialGuessModeIsEquivalentToRef) using initial_guess_mode = gko::solver::initial_guess_mode; auto ref_solver = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(this->exec) ->generate(this->mtx); auto b = gko::initialize({3.9, 9.0, 2.2}, this->exec); @@ -466,9 +455,7 @@ TYPED_TEST(Ir, ApplyWithGivenInitialGuessModeIsEquivalentToRef) initial_guess_mode::zero}) { auto solver = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on( - this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .with_default_initial_guess(guess) .on(this->exec) ->generate(this->mtx); diff --git a/reference/test/solver/multigrid_kernels.cpp b/reference/test/solver/multigrid_kernels.cpp index 3efb9d41c5e..c35db0b1427 100644 --- a/reference/test/solver/multigrid_kernels.cpp +++ b/reference/test/solver/multigrid_kernels.cpp @@ -289,30 +289,26 @@ class Multigrid : public ::testing::Test { .on(exec)), smoother_factory(gko::give( Smoother::build() - .with_solver( - InnerSolver::build().with_max_block_size(1u).on(exec)) + .with_solver(InnerSolver::build().with_max_block_size(1u)) .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + gko::stop::Iteration::build().with_max_iters(1u)) .on(exec))), coarsest_factory( CoarsestSolver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(4u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .on(exec)), coarsestnext_factory( CoarsestNextSolver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec)) + gko::stop::Iteration::build().with_max_iters(4u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6))) .on(exec)), rp_factory(DummyRPFactory::build().on(exec)), lo_factory(DummyFactory::build().on(exec)), @@ -357,14 +353,12 @@ class Multigrid : public ::testing::Test { .with_mid_case(gko::solver::multigrid::mid_smooth_type::both) .with_mg_level(coarse_factory) .with_criteria( - gko::stop::Iteration::build().with_max_iters(4u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(6)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(4u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(6)), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .with_cycle(cycle) .with_min_coarse_rows(1u) .on(exec)); @@ -382,14 +376,12 @@ class Multigrid : public ::testing::Test { .with_mid_case(gko::solver::multigrid::mid_smooth_type::both) .with_mg_level(coarse_factory, coarsenext_factory) .with_criteria( - gko::stop::Iteration::build().with_max_iters(200u).on(exec), - gko::stop::Time::build() - .with_time_limit(std::chrono::seconds(100)) - .on(exec), + gko::stop::Iteration::build().with_max_iters(200u), + gko::stop::Time::build().with_time_limit( + std::chrono::seconds(100)), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::initial_resnorm) - .with_reduction_factor(r::value) - .on(exec)) + .with_reduction_factor(r::value)) .with_cycle(cycle) .with_min_coarse_rows(1u) .on(exec)); @@ -413,9 +405,7 @@ class Multigrid : public ::testing::Test { gko::matrix::IdentityFactory::create(exec)) .with_post_uses_pre(false) .with_mid_case(mid_case) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on( - this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .with_cycle(cycle) .with_min_coarse_rows(1u) .on(this->exec)); @@ -435,9 +425,7 @@ class Multigrid : public ::testing::Test { .with_coarsest_solver(this->lo_factory) .with_post_uses_pre(true) .with_mid_case(mid_case) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on( - this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .with_cycle(cycle) .with_min_coarse_rows(1u) .on(this->exec)); @@ -1273,8 +1261,7 @@ TYPED_TEST(Multigrid, ZeroGuessIgnoresInput) .with_coarsest_solver(this->coarsest_factory) .with_max_levels(2u) .with_mg_level(this->coarse_factory) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(this->exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .with_min_coarse_rows(1u); auto normal_mg = common_part .with_default_initial_guess( diff --git a/test/matrix/matrix.cpp b/test/matrix/matrix.cpp index 9192b2eeebe..9b78ae21d6c 100644 --- a/test/matrix/matrix.cpp +++ b/test/matrix/matrix.cpp @@ -155,7 +155,7 @@ struct CsrWithDefaultStrategy : CsrBase { CsrBase::assert_empty_state(mtx); auto first_strategy = mtx->create_default()->get_strategy(); auto second_strategy = mtx->get_strategy(); - ASSERT_EQ(typeid(*first_strategy), typeid(*second_strategy)); + GKO_ASSERT_DYNAMIC_TYPE_EQ(first_strategy, second_strategy); } }; diff --git a/test/mpi/preconditioner/schwarz.cpp b/test/mpi/preconditioner/schwarz.cpp index 3c9e3a8d69f..8d07ba44046 100644 --- a/test/mpi/preconditioner/schwarz.cpp +++ b/test/mpi/preconditioner/schwarz.cpp @@ -197,7 +197,7 @@ TYPED_TEST(SchwarzPreconditioner, CanApplyPreconditionedSolver) cg::build() .with_preconditioner( prec::build() - .with_local_solver_factory(this->local_solver_factory) + .with_local_solver(this->local_solver_factory) .on(this->exec)) .with_criteria(iter_stop, tol_stop) .on(this->exec); @@ -225,10 +225,9 @@ TYPED_TEST(SchwarzPreconditioner, CanApplyPreconditioner) using cg = typename TestFixture::solver_type; using prec = typename TestFixture::dist_prec_type; - auto precond_factory = - prec::build() - .with_local_solver_factory(this->local_solver_factory) - .on(this->exec); + auto precond_factory = prec::build() + .with_local_solver(this->local_solver_factory) + .on(this->exec); auto local_precond = this->local_solver_factory->generate(this->non_dist_mat); auto precond = precond_factory->generate(this->dist_mat); @@ -249,10 +248,9 @@ TYPED_TEST(SchwarzPreconditioner, CanAdvancedApplyPreconditioner) using cg = typename TestFixture::solver_type; using prec = typename TestFixture::dist_prec_type; - auto precond_factory = - prec::build() - .with_local_solver_factory(this->local_solver_factory) - .on(this->exec); + auto precond_factory = prec::build() + .with_local_solver(this->local_solver_factory) + .on(this->exec); auto local_precond = this->local_solver_factory->generate(this->non_dist_mat); auto precond = precond_factory->generate(this->dist_mat); diff --git a/test/mpi/solver/solver.cpp b/test/mpi/solver/solver.cpp index 59462a9be59..f53b2784124 100644 --- a/test/mpi/solver/solver.cpp +++ b/test/mpi/solver/solver.cpp @@ -107,9 +107,7 @@ struct SimpleSolverTest { std::shared_ptr exec) { return solver_type::build().with_criteria( - gko::stop::Iteration::build() - .with_max_iters(iteration_count()) - .on(exec), + gko::stop::Iteration::build().with_max_iters(iteration_count()), gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::absolute) .with_reduction_factor(reduction_factor()) @@ -164,17 +162,11 @@ struct Ir : SimpleSolverTest> { std::shared_ptr exec) { return SimpleSolverTest>::build(exec) - .with_solver( - gko::solver::Cg::build() - .with_criteria( - gko::stop::Iteration::build() - .with_max_iters(iteration_count()) - .on(exec), - gko::stop::ResidualNorm::build() - .with_baseline(gko::stop::mode::absolute) - .with_reduction_factor(2 * reduction_factor()) - .on(exec)) - .on(exec)) + .with_solver(gko::solver::Cg::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(iteration_count()), + gko::stop::ResidualNorm::build() + .with_baseline(gko::stop::mode::absolute) + .with_reduction_factor(2 * reduction_factor()))) .with_relaxation_factor(0.9); } }; diff --git a/test/solver/bicg_kernels.cpp b/test/solver/bicg_kernels.cpp index a62ab3f6d72..d35e6de227d 100644 --- a/test/solver/bicg_kernels.cpp +++ b/test/solver/bicg_kernels.cpp @@ -239,19 +239,15 @@ TEST_F(Bicg, ApplyWithSpdMatrixIsEquivalentToRef) auto d_b = gko::clone(exec, b); auto bicg_factory = gko::solver::Bicg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on(ref), - gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(::r::value)) .on(ref); auto d_bicg_factory = gko::solver::Bicg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(::r::value)) .on(exec); auto solver = bicg_factory->generate(std::move(mtx)); auto d_solver = d_bicg_factory->generate(std::move(d_mtx)); @@ -271,19 +267,15 @@ TEST_F(Bicg, ApplyWithSuiteSparseMatrixIsEquivalentToRef) auto d_b = gko::clone(exec, b); auto bicg_factory = gko::solver::Bicg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on(ref), - gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(::r::value)) .on(ref); auto d_bicg_factory = gko::solver::Bicg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(::r::value)) .on(exec); auto solver = bicg_factory->generate(std::move(mtx_ani)); auto d_solver = d_bicg_factory->generate(std::move(d_mtx_ani)); diff --git a/test/solver/bicgstab_kernels.cpp b/test/solver/bicgstab_kernels.cpp index 15eda2a74cb..422d51c86ad 100644 --- a/test/solver/bicgstab_kernels.cpp +++ b/test/solver/bicgstab_kernels.cpp @@ -71,19 +71,17 @@ class Bicgstab : public CommonTestFixture { exec_bicgstab_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(246u).on(exec), + gko::stop::Iteration::build().with_max_iters(246u), gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(exec)) + .with_reduction_factor(::r::value)) .on(exec); ref_bicgstab_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(246u).on(ref), + gko::stop::Iteration::build().with_max_iters(246u), gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(ref)) + .with_reduction_factor(::r::value)) .on(ref); } diff --git a/test/solver/cg_kernels.cpp b/test/solver/cg_kernels.cpp index a51ac48c59b..dcb4b0147f6 100644 --- a/test/solver/cg_kernels.cpp +++ b/test/solver/cg_kernels.cpp @@ -203,19 +203,15 @@ TEST_F(Cg, ApplyIsEquivalentToRef) auto d_b = gko::clone(exec, b); auto cg_factory = gko::solver::Cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on(ref), - gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(::r::value)) .on(ref); auto d_cg_factory = gko::solver::Cg::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(::r::value)) .on(exec); auto solver = cg_factory->generate(std::move(mtx)); auto d_solver = d_cg_factory->generate(std::move(d_mtx)); diff --git a/test/solver/cgs_kernels.cpp b/test/solver/cgs_kernels.cpp index b1b124ed420..35914d4afa6 100644 --- a/test/solver/cgs_kernels.cpp +++ b/test/solver/cgs_kernels.cpp @@ -70,18 +70,16 @@ class Cgs : public CommonTestFixture { exec_cgs_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(246u).on(exec), + gko::stop::Iteration::build().with_max_iters(246u), gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(exec)) + .with_reduction_factor(::r::value)) .on(exec); ref_cgs_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(246u).on(ref), + gko::stop::Iteration::build().with_max_iters(246u), gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(ref)) + .with_reduction_factor(::r::value)) .on(ref); } diff --git a/test/solver/direct.cpp b/test/solver/direct.cpp index 0a30f7ba67f..31b7bd976ce 100644 --- a/test/solver/direct.cpp +++ b/test/solver/direct.cpp @@ -93,22 +93,22 @@ class Direct : public CommonTestFixture { mtx = gko::read(s_mtx, ref); dmtx = gko::clone(exec, mtx); const auto num_rows = mtx->get_size()[0]; - factory = solver_type::build() - .with_factorization(factorization_type::build() - .with_symmetric_sparsity(true) - .on(ref)) - .with_num_rhs(static_cast(nrhs)) - .on(ref); + factory = + solver_type::build() + .with_factorization( + factorization_type::build().with_symmetric_sparsity(true)) + .with_num_rhs(static_cast(nrhs)) + .on(ref); alpha = gen_mtx(1, 1); beta = gen_mtx(1, 1); input = gen_mtx(num_rows, nrhs); output = gen_mtx(num_rows, nrhs); - dfactory = solver_type::build() - .with_factorization(factorization_type::build() - .with_symmetric_sparsity(true) - .on(exec)) - .with_num_rhs(static_cast(nrhs)) - .on(exec); + dfactory = + solver_type::build() + .with_factorization( + factorization_type::build().with_symmetric_sparsity(true)) + .with_num_rhs(static_cast(nrhs)) + .on(exec); dalpha = gko::clone(exec, alpha); dbeta = gko::clone(exec, beta); dinput = gko::clone(exec, input); diff --git a/test/solver/fcg_kernels.cpp b/test/solver/fcg_kernels.cpp index 0d1ced86f85..d8a3a1ef9b2 100644 --- a/test/solver/fcg_kernels.cpp +++ b/test/solver/fcg_kernels.cpp @@ -212,19 +212,15 @@ TEST_F(Fcg, ApplyIsEquivalentToRef) auto d_b = gko::clone(exec, b); auto fcg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on(ref), - gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(::r::value)) .on(ref); auto d_fcg_factory = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(50u).on(exec), - gko::stop::ResidualNorm::build() - .with_reduction_factor(::r::value) - .on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(50u), + gko::stop::ResidualNorm::build() + .with_reduction_factor(::r::value)) .on(exec); auto solver = fcg_factory->generate(std::move(mtx)); auto d_solver = d_fcg_factory->generate(std::move(d_mtx)); diff --git a/test/solver/gcr_kernels.cpp b/test/solver/gcr_kernels.cpp index 8f02c431f98..8db5570a6f0 100644 --- a/test/solver/gcr_kernels.cpp +++ b/test/solver/gcr_kernels.cpp @@ -74,19 +74,17 @@ class Gcr : public CommonTestFixture { exec_gcr_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(246u).on(exec), + gko::stop::Iteration::build().with_max_iters(246u), gko::stop::ResidualNorm::build() - .with_reduction_factor(value_type{1e-15}) - .on(exec)) + .with_reduction_factor(value_type{1e-15})) .on(exec); ref_gcr_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(246u).on(ref), + gko::stop::Iteration::build().with_max_iters(246u), gko::stop::ResidualNorm::build() - .with_reduction_factor(value_type{1e-15}) - .on(ref)) + .with_reduction_factor(value_type{1e-15})) .on(ref); } diff --git a/test/solver/gmres_kernels.cpp b/test/solver/gmres_kernels.cpp index 5c2541da1a7..7752ff4dda6 100644 --- a/test/solver/gmres_kernels.cpp +++ b/test/solver/gmres_kernels.cpp @@ -70,19 +70,17 @@ class Gmres : public CommonTestFixture { exec_gmres_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(246u).on(exec), + gko::stop::Iteration::build().with_max_iters(246u), gko::stop::ResidualNorm::build() - .with_reduction_factor(value_type{1e-15}) - .on(exec)) + .with_reduction_factor(value_type{1e-15})) .on(exec); ref_gmres_factory = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(246u).on(ref), + gko::stop::Iteration::build().with_max_iters(246u), gko::stop::ResidualNorm::build() - .with_reduction_factor(value_type{1e-15}) - .on(ref)) + .with_reduction_factor(value_type{1e-15})) .on(ref); } diff --git a/test/solver/idr_kernels.cpp b/test/solver/idr_kernels.cpp index 959c857cb71..0019c05b9d4 100644 --- a/test/solver/idr_kernels.cpp +++ b/test/solver/idr_kernels.cpp @@ -76,15 +76,13 @@ class Idr : public CommonTestFixture { exec_idr_factory = Solver::build() .with_deterministic(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec); ref_idr_factory = Solver::build() .with_deterministic(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(ref); } @@ -295,15 +293,13 @@ TEST_F(Idr, IdrIterationWithComplexSubspaceOneRHSIsEquivalentToRef) Solver::build() .with_deterministic(true) .with_complex_subspace(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec); ref_idr_factory = Solver::build() .with_deterministic(true) .with_complex_subspace(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(ref); auto ref_solver = ref_idr_factory->generate(mtx); auto exec_solver = exec_idr_factory->generate(d_mtx); @@ -337,15 +333,13 @@ TEST_F(Idr, IdrIterationWithComplexSubspaceMultipleRHSIsEquivalentToRef) Solver::build() .with_deterministic(true) .with_complex_subspace(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec); ref_idr_factory = Solver::build() .with_deterministic(true) .with_complex_subspace(true) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(ref); auto exec_solver = exec_idr_factory->generate(d_mtx); auto ref_solver = ref_idr_factory->generate(mtx); diff --git a/test/solver/ir_kernels.cpp b/test/solver/ir_kernels.cpp index c21f6da3f66..9374b7867ce 100644 --- a/test/solver/ir_kernels.cpp +++ b/test/solver/ir_kernels.cpp @@ -105,13 +105,11 @@ TEST_F(Ir, ApplyIsEquivalentToRef) // both executors auto ir_factory = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .on(ref); auto d_ir_factory = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .on(exec); auto solver = ir_factory->generate(std::move(mtx)); auto d_solver = d_ir_factory->generate(std::move(d_mtx)); @@ -134,25 +132,15 @@ TEST_F(Ir, ApplyWithIterativeInnerSolverIsEquivalentToRef) auto ir_factory = gko::solver::Ir::build() - .with_solver( - gko::solver::Gmres::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on( - ref)) - .on(ref)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(ref)) + .with_solver(gko::solver::Gmres::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(1u))) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .on(ref); auto d_ir_factory = gko::solver::Ir::build() - .with_solver( - gko::solver::Gmres::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on( - exec)) - .on(exec)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(exec)) + .with_solver(gko::solver::Gmres::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(1u))) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .on(exec); auto solver = ir_factory->generate(std::move(mtx)); auto d_solver = d_ir_factory->generate(std::move(d_mtx)); @@ -180,14 +168,12 @@ TEST_F(Ir, RichardsonApplyIsEquivalentToRef) // both executors auto ir_factory = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .with_relaxation_factor(value_type{0.9}) .on(ref); auto d_ir_factory = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .with_relaxation_factor(value_type{0.9}) .on(exec); auto solver = ir_factory->generate(std::move(mtx)); @@ -210,26 +196,16 @@ TEST_F(Ir, RichardsonApplyWithIterativeInnerSolverIsEquivalentToRef) auto d_b = clone(exec, b); auto ir_factory = gko::solver::Ir::build() - .with_solver( - gko::solver::Gmres::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on( - ref)) - .on(ref)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(ref)) + .with_solver(gko::solver::Gmres::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(1u))) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .with_relaxation_factor(value_type{0.9}) .on(ref); auto d_ir_factory = gko::solver::Ir::build() - .with_solver( - gko::solver::Gmres::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on( - exec)) - .on(exec)) - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(exec)) + .with_solver(gko::solver::Gmres::build().with_criteria( + gko::stop::Iteration::build().with_max_iters(1u))) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .with_relaxation_factor(value_type{0.9}) .on(exec); auto solver = ir_factory->generate(std::move(mtx)); @@ -258,14 +234,12 @@ TEST_F(Ir, ApplyWithGivenInitialGuessModeIsEquivalentToRef) auto d_x = clone(exec, x); auto ir_factory = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(ref)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .with_default_initial_guess(guess) .on(ref); auto d_ir_factory = gko::solver::Ir::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(2u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(2u)) .with_default_initial_guess(guess) .on(exec); auto solver = ir_factory->generate(mtx); diff --git a/test/solver/solver.cpp b/test/solver/solver.cpp index b6f228c13f5..6bb59507f17 100644 --- a/test/solver/solver.cpp +++ b/test/solver/solver.cpp @@ -101,9 +101,7 @@ struct SimpleSolverTest { gko::size_type iteration_count, bool check_residual = true) { return solver_type::build().with_criteria( - gko::stop::Iteration::build() - .with_max_iters(iteration_count) - .on(exec), + gko::stop::Iteration::build().with_max_iters(iteration_count), check_residual ? gko::stop::ResidualNorm::build() .with_baseline(gko::stop::mode::absolute) .with_reduction_factor(1e-30) @@ -116,8 +114,7 @@ struct SimpleSolverTest { gko::size_type iteration_count, bool check_residual = true) { return build(exec, iteration_count, check_residual) - .with_preconditioner( - precond_type::build().with_max_block_size(1u).on(exec)); + .with_preconditioner(precond_type::build().with_max_block_size(1u)); } static const gko::LinOp* get_preconditioner( @@ -185,8 +182,7 @@ struct Idr : SimpleSolverTest> { gko::size_type iteration_count, bool check_residual = true) { return build(exec, iteration_count, check_residual) - .with_preconditioner( - precond_type::build().with_max_block_size(1u).on(exec)); + .with_preconditioner(precond_type::build().with_max_block_size(1u)); } }; @@ -200,8 +196,7 @@ struct Ir : SimpleSolverTest> { { return SimpleSolverTest>::build( exec, iteration_count, check_residual) - .with_solver( - precond_type::build().with_max_block_size(1u).on(exec)); + .with_solver(precond_type::build().with_max_block_size(1u)); } static const gko::LinOp* get_preconditioner( @@ -232,8 +227,7 @@ struct CbGmres : SimpleSolverTest> { gko::size_type iteration_count, bool check_residual = true) { return build(exec, iteration_count, check_residual) - .with_preconditioner( - precond_type::build().with_max_block_size(1u).on(exec)); + .with_preconditioner(precond_type::build().with_max_block_size(1u)); } }; @@ -254,8 +248,7 @@ struct Gmres : SimpleSolverTest> { gko::size_type iteration_count, bool check_residual = true) { return build(exec, iteration_count, check_residual) - .with_preconditioner( - precond_type::build().with_max_block_size(1u).on(exec)); + .with_preconditioner(precond_type::build().with_max_block_size(1u)); } }; @@ -277,8 +270,7 @@ struct FGmres : SimpleSolverTest> { gko::size_type iteration_count, bool check_residual = true) { return build(exec, iteration_count, check_residual) - .with_preconditioner( - precond_type::build().with_max_block_size(1u).on(exec)) + .with_preconditioner(precond_type::build().with_max_block_size(1u)) .with_flexible(true); } }; @@ -300,8 +292,7 @@ struct Gcr : SimpleSolverTest> { gko::size_type iteration_count, bool check_residual = true) { return build(exec, iteration_count, check_residual) - .with_preconditioner( - precond_type::build().with_max_block_size(1u).on(exec)); + .with_preconditioner(precond_type::build().with_max_block_size(1u)); } }; diff --git a/test/test_install/test_install.cpp b/test/test_install/test_install.cpp index d2c273b4e0f..d442647a985 100644 --- a/test/test_install/test_install.cpp +++ b/test/test_install/test_install.cpp @@ -104,11 +104,9 @@ void check_solver(std::shared_ptr exec, auto solver_gen = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(num_iters).on( - exec), - gko::stop::ResidualNorm<>::build() - .with_reduction_factor(reduction_factor) - .on(exec)) + gko::stop::Iteration::build().with_max_iters(num_iters), + gko::stop::ResidualNorm<>::build().with_reduction_factor( + reduction_factor)) .on(exec); #if HAS_REFERENCE A->read(A_raw); @@ -126,11 +124,9 @@ void check_solver(std::shared_ptr exec, auto solver_gen_ref = Solver::build() .with_criteria( - gko::stop::Iteration::build().with_max_iters(num_iters).on( - exec_ref), - gko::stop::ResidualNorm<>::build() - .with_reduction_factor(reduction_factor) - .on(exec_ref)) + gko::stop::Iteration::build().with_max_iters(num_iters), + gko::stop::ResidualNorm<>::build().with_reduction_factor( + reduction_factor)) .on(exec_ref); auto x_ref = gko::clone(exec_ref, x); solver_gen->generate(A_ref)->apply(b, x_ref); @@ -493,8 +489,7 @@ int main() using Solver = gko::solver::Ir<>; auto test = Solver::build() - .with_criteria( - gko::stop::Iteration::build().with_max_iters(1u).on(exec)) + .with_criteria(gko::stop::Iteration::build().with_max_iters(1u)) .on(exec); }