diff --git a/benchmark/solver/solver.cpp b/benchmark/solver/solver.cpp index 11169effae8..a02c8d1a30c 100644 --- a/benchmark/solver/solver.cpp +++ b/benchmark/solver/solver.cpp @@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "benchmark/utils/formats.hpp" @@ -76,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)"); @@ -117,11 +125,8 @@ void validate_option_object(const rapidjson::Value &value) } -// solver mapping -template -std::unique_ptr create_solver( - std::shared_ptr exec, - std::shared_ptr precond) +std::shared_ptr create_criterion( + std::shared_ptr exec) { std::shared_ptr residual_stop; if (FLAGS_rel_residual) { @@ -134,10 +139,22 @@ std::unique_ptr 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> + criterion_vector{residual_stop, iteration_stop}; + return gko::stop::combine(criterion_vector); +} + + +// solver mapping +template +std::unique_ptr create_solver( + std::shared_ptr exec, + std::shared_ptr 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); } @@ -151,17 +168,21 @@ const std::map( {"cg", create_solver>}, {"cgs", create_solver>}, {"fcg", create_solver>}, + {"idr", + [](std::shared_ptr exec, + std::shared_ptr 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 exec, std::shared_ptr 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);