Skip to content

Commit

Permalink
remove unnecessary .on(...) calls
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Aug 8, 2023
1 parent 9084251 commit 1e170cb
Show file tree
Hide file tree
Showing 83 changed files with 517 additions and 796 deletions.
9 changes: 3 additions & 6 deletions benchmark/solver/solver_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,18 @@ std::unique_ptr<gko::LinOpFactory> generate_solver(
return gko::experimental::solver::Direct<etype, itype>::build()
.with_factorization(
gko::experimental::factorization::Cholesky<etype,
itype>::build()
.on(exec))
itype>::build())
.on(exec);
} else if (description == "symm_direct") {
return gko::experimental::solver::Direct<etype, itype>::build()
.with_factorization(
gko::experimental::factorization::Lu<etype, itype>::build()
.with_symmetric_sparsity(true)
.on(exec))
.with_symmetric_sparsity(true))
.on(exec);
} else if (description == "direct") {
return gko::experimental::solver::Direct<etype, itype>::build()
.with_factorization(
gko::experimental::factorization::Lu<etype, itype>::build().on(
exec))
gko::experimental::factorization::Lu<etype, itype>::build())
.on(exec);
} else if (description == "overhead") {
return add_criteria_precond_finalize<gko::Overhead<etype>>(
Expand Down
27 changes: 6 additions & 21 deletions benchmark/utils/overhead_linop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,12 @@ class Overhead : public EnableLinOp<Overhead<ValueType>>,
friend class EnablePolymorphicObject<Overhead, LinOp>;

public:
GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
{
/**
* Criterion factories.
*/
std::vector<std::shared_ptr<const stop::CriterionFactory>>
GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr);

/**
* Preconditioner factory.
*/
std::shared_ptr<const LinOpFactory> GKO_FACTORY_PARAMETER_SCALAR(
preconditioner, nullptr);

/**
* Already generated preconditioner. If one is provided, the factory
* `preconditioner` will be ignored.
*/
std::shared_ptr<const LinOp> 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);
Expand Down
45 changes: 22 additions & 23 deletions benchmark/utils/preconditioners.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
.on(exec));
return gko::preconditioner::Ic<gko::solver::LowerTrs<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"parict",
Expand All @@ -137,7 +137,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::
Ilu<gko::solver::LowerTrs<etype, itype>,
gko::solver::UpperTrs<etype, itype>, false, itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"parilu",
Expand All @@ -150,7 +150,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::
Ilu<gko::solver::LowerTrs<etype, itype>,
gko::solver::UpperTrs<etype, itype>, false, itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"parilut",
Expand All @@ -165,7 +165,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::
Ilu<gko::solver::LowerTrs<etype, itype>,
gko::solver::UpperTrs<etype, itype>, false, itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"ic",
Expand All @@ -174,7 +174,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
gko::factorization::Ic<etype, itype>::build().on(exec));
return gko::preconditioner::Ic<gko::solver::LowerTrs<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"ilu",
Expand All @@ -184,7 +184,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::
Ilu<gko::solver::LowerTrs<etype, itype>,
gko::solver::UpperTrs<etype, itype>, false, itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"paric-isai",
Expand All @@ -201,8 +201,8 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::Ic<
gko::preconditioner::LowerIsai<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_factorization(fact)
.with_l_solver(lisai)
.on(exec);
}},
{"parict-isai",
Expand All @@ -221,8 +221,8 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::Ic<
gko::preconditioner::LowerIsai<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_factorization(fact)
.with_l_solver(lisai)
.on(exec);
}},
{"parilu-isai",
Expand All @@ -244,9 +244,9 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
gko::preconditioner::LowerIsai<etype, itype>,
gko::preconditioner::UpperIsai<etype, itype>, 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",
Expand All @@ -270,9 +270,9 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
gko::preconditioner::LowerIsai<etype, itype>,
gko::preconditioner::UpperIsai<etype, itype>, 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",
Expand All @@ -286,8 +286,8 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::Ic<
gko::preconditioner::LowerIsai<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_factorization(fact)
.with_l_solver(lisai)
.on(exec);
}},
{"ilu-isai",
Expand All @@ -306,9 +306,9 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
gko::preconditioner::LowerIsai<etype, itype>,
gko::preconditioner::UpperIsai<etype, itype>, 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",
Expand All @@ -326,8 +326,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
{"overhead", [](std::shared_ptr<const gko::Executor> exec) {
return gko::Overhead<etype>::build()
.with_criteria(gko::stop::ResidualNorm<etype>::build()
.with_reduction_factor(rc_etype{})
.on(exec))
.with_reduction_factor(rc_etype{}))
.on(exec);
}}};

Expand Down
4 changes: 2 additions & 2 deletions core/distributed/preconditioner/schwarz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ template <typename ValueType, typename LocalIndexType, typename GlobalIndexType>
void Schwarz<ValueType, LocalIndexType, GlobalIndexType>::generate(
std::shared_ptr<const LinOp> 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<experimental::distributed::Matrix<ValueType, LocalIndexType,
GlobalIndexType>>(
system_matrix)
Expand Down
10 changes: 4 additions & 6 deletions core/preconditioner/isai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,15 @@ void Isai<IsaiType, ValueType, IndexType>::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<ValueType>::build()
.with_baseline(gko::stop::mode::rhs_norm)
.with_reduction_factor(
remove_complex<ValueType>{
excess_solver_reduction})
.on(exec))
excess_solver_reduction}))
.on(exec);
excess_solution->copy_from(excess_rhs);
} else if (is_lower) {
Expand Down
14 changes: 5 additions & 9 deletions core/solver/multigrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,30 +569,26 @@ void Multigrid::generate()
using absolute_value_type = remove_complex<value_type>;
return solver::Gmres<value_type>::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<value_type>::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<value_type>::build()
.with_max_block_size(1u)
.on(exec))
.with_max_block_size(1u))
.on(exec)
->generate(matrix);
} else {
return experimental::solver::Direct<value_type,
int32>::build()
.with_factorization(
experimental::factorization::Lu<value_type,
int32>::build()
.on(exec))
int32>::build())
.on(exec)
->generate(matrix);
}
Expand Down
3 changes: 1 addition & 2 deletions core/test/log/convergence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class Convergence : public ::testing::Test {
gko::initialize<AbsoluteDense>({6}, exec);
std::unique_ptr<gko::LinOp> system =
gko::solver::Ir<T>::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<Dense>(I<I<T>>{{1, 2}, {0, 3}}, exec));
std::unique_ptr<Dense> rhs = gko::initialize<Dense>({15, 25}, exec);
Expand Down
3 changes: 1 addition & 2 deletions core/test/log/profiler_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ TEST(ProfilerHook, LogsIteration)
auto alpha = gko::share(gko::initialize<Vec>({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");
Expand Down
9 changes: 3 additions & 6 deletions core/test/log/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));
Expand Down Expand Up @@ -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<Dense>({1.1}, exec));
auto right_hand_side = gko::initialize<Dense>({-5.5}, exec);
Expand Down
9 changes: 3 additions & 6 deletions core/test/log/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,7 @@ TYPED_TEST(Stream, CatchesLinopFactoryGenerateStarted)
gko::log::Logger::linop_factory_generate_started_mask, out);
auto factory =
gko::solver::Bicgstab<TypeParam>::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<TypeParam>::create(exec));
std::stringstream ptrstream_factory;
Expand All @@ -633,8 +632,7 @@ TYPED_TEST(Stream, CatchesLinopFactoryGenerateCompleted)
gko::log::Logger::linop_factory_generate_completed_mask, out);
auto factory =
gko::solver::Bicgstab<TypeParam>::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<TypeParam>::create(exec));
auto output =
Expand Down Expand Up @@ -815,8 +813,7 @@ TYPED_TEST(Stream, CatchesIterationsWithVerbose)

auto factory =
gko::solver::Bicgstab<TypeParam>::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<Dense>({1.1}, exec));
auto right_hand_side = gko::initialize<Dense>({-5.5}, exec);
Expand Down
14 changes: 7 additions & 7 deletions core/test/mpi/distributed/preconditioner/schwarz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -83,8 +83,8 @@ class SchwarzFactory : public ::testing::Test {
gko::ptr_param<const Schwarz> 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<const gko::Executor> exec;
Expand All @@ -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);
}

Expand All @@ -125,7 +125,7 @@ TYPED_TEST(SchwarzFactory, CanBeCopied)
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(bj)
.on(this->exec)
->generate(Mtx::create(this->exec, MPI_COMM_WORLD));

Expand All @@ -143,7 +143,7 @@ TYPED_TEST(SchwarzFactory, CanBeMoved)
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(bj)
.on(this->exec)
->generate(Mtx::create(this->exec, MPI_COMM_WORLD));

Expand All @@ -158,7 +158,7 @@ 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);
}


Expand Down
Loading

0 comments on commit 1e170cb

Please sign in to comment.