Skip to content

Commit

Permalink
review update and add create_criterion
Browse files Browse the repository at this point in the history
- add subspace_dim and kappa for idr
- remove unnecessary header
- add create_critrion to keep the consistent criteria

Co-authored-by: Thomas Grützmacher <thomas.gruetzmacher@kit.edu>
Co-authored-by: Tobias Ribizel <ribizel@kit.edu>
  • Loading branch information
3 people committed Dec 2, 2020
1 parent 73cd857 commit 6445756
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions benchmark/solver/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <fstream>
#include <iomanip>
#include <iostream>


#include <ginkgo/core/preconditioner/isai.hpp>
#include <vector>


#include "benchmark/utils/formats.hpp"
Expand Down Expand Up @@ -79,6 +77,13 @@ DEFINE_uint32(
DEFINE_uint32(gmres_restart, 100,
"What maximum dimension of the Krylov space to use in GMRES");

DEFINE_uint32(idr_subspace_dim, 2,
"What dimension of the subspace to use in IDR");

DEFINE_double(
idr_kappa, 0.7,
"the number to check whether Av_n and v_n are too close or not in IDR");

DEFINE_bool(random_rhs, false,
"Use a random vector for the rhs (otherwise use all ones)");

Expand Down Expand Up @@ -120,11 +125,8 @@ void validate_option_object(const rapidjson::Value &value)
}


// solver mapping
template <typename SolverType>
std::unique_ptr<gko::LinOpFactory> create_solver(
std::shared_ptr<const gko::Executor> exec,
std::shared_ptr<const gko::LinOpFactory> precond)
std::shared_ptr<const gko::stop::CriterionFactory> create_criterion(
std::shared_ptr<const gko::Executor> exec)
{
std::shared_ptr<const gko::stop::CriterionFactory> residual_stop;
if (FLAGS_rel_residual) {
Expand All @@ -137,10 +139,22 @@ std::unique_ptr<gko::LinOpFactory> create_solver(
.with_reduction_factor(FLAGS_rel_res_goal)
.on(exec));
}
auto iteration_stop = gko::share(
gko::stop::Iteration::build().with_max_iters(FLAGS_max_iters).on(exec));
std::vector<std::shared_ptr<const gko::stop::CriterionFactory>>
criterion_vector{residual_stop, iteration_stop};
return gko::stop::combine(criterion_vector);
}


// solver mapping
template <typename SolverType>
std::unique_ptr<gko::LinOpFactory> create_solver(
std::shared_ptr<const gko::Executor> exec,
std::shared_ptr<const gko::LinOpFactory> precond)
{
return SolverType::build()
.with_criteria(residual_stop, gko::stop::Iteration::build()
.with_max_iters(FLAGS_max_iters)
.on(exec))
.with_criteria(create_criterion(exec))
.with_preconditioner(give(precond))
.on(exec);
}
Expand All @@ -154,18 +168,21 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
{"cg", create_solver<gko::solver::Cg<>>},
{"cgs", create_solver<gko::solver::Cgs<>>},
{"fcg", create_solver<gko::solver::Fcg<>>},
{"idr", create_solver<gko::solver::Idr<>>},
{"idr",
[](std::shared_ptr<const gko::Executor> exec,
std::shared_ptr<const gko::LinOpFactory> precond) {
return gko::solver::Idr<>::build()
.with_criteria(create_criterion(exec))
.with_subspace_dim(FLAGS_idr_subspace_dim)
.with_kappa(FLAGS_idr_kappa)
.with_preconditioner(give(precond))
.on(exec);
}},
{"gmres",
[](std::shared_ptr<const gko::Executor> exec,
std::shared_ptr<const gko::LinOpFactory> precond) {
return gko::solver::Gmres<>::build()
.with_criteria(
gko::stop::ResidualNormReduction<>::build()
.with_reduction_factor(FLAGS_rel_res_goal)
.on(exec),
gko::stop::Iteration::build()
.with_max_iters(FLAGS_max_iters)
.on(exec))
.with_criteria(create_criterion(exec))
.with_krylov_dim(FLAGS_gmres_restart)
.with_preconditioner(give(precond))
.on(exec);
Expand Down

0 comments on commit 6445756

Please sign in to comment.