Skip to content

Commit ea61fcd

Browse files
committed
add minres config parsing
1 parent a32cc6c commit ea61fcd

File tree

6 files changed

+80
-18
lines changed

6 files changed

+80
-18
lines changed

core/config/config_helper.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum class LinOpFactoryType : int {
4949
Gcr,
5050
Gmres,
5151
CbGmres,
52+
Minres,
5253
Direct,
5354
LowerTrs,
5455
UpperTrs,

core/config/registry.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -29,6 +29,7 @@ configuration_map generate_config_map()
2929
{"solver::Gcr", parse<LinOpFactoryType::Gcr>},
3030
{"solver::Gmres", parse<LinOpFactoryType::Gmres>},
3131
{"solver::CbGmres", parse<LinOpFactoryType::CbGmres>},
32+
{"solver::Minres", parse<LinOpFactoryType::Minres>},
3233
{"solver::Direct", parse<LinOpFactoryType::Direct>},
3334
{"solver::LowerTrs", parse<LinOpFactoryType::LowerTrs>},
3435
{"solver::UpperTrs", parse<LinOpFactoryType::UpperTrs>},

core/config/solver_config.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -18,6 +18,7 @@
1818
#include <ginkgo/core/solver/gmres.hpp>
1919
#include <ginkgo/core/solver/idr.hpp>
2020
#include <ginkgo/core/solver/ir.hpp>
21+
#include <ginkgo/core/solver/minres.hpp>
2122
#include <ginkgo/core/solver/multigrid.hpp>
2223
#include <ginkgo/core/solver/triangular.hpp>
2324

@@ -40,6 +41,7 @@ GKO_PARSE_VALUE_TYPE(Idr, gko::solver::Idr);
4041
GKO_PARSE_VALUE_TYPE(Gcr, gko::solver::Gcr);
4142
GKO_PARSE_VALUE_TYPE(Gmres, gko::solver::Gmres);
4243
GKO_PARSE_VALUE_TYPE_BASE(CbGmres, gko::solver::CbGmres);
44+
GKO_PARSE_VALUE_TYPE(Minres, gko::solver::Minres);
4345
GKO_PARSE_VALUE_AND_INDEX_TYPE(Direct, gko::experimental::solver::Direct);
4446
GKO_PARSE_VALUE_AND_INDEX_TYPE(LowerTrs, gko::solver::LowerTrs);
4547
GKO_PARSE_VALUE_AND_INDEX_TYPE(UpperTrs, gko::solver::UpperTrs);

core/solver/minres.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ginkgo/core/base/precision_dispatch.hpp>
1313
#include <ginkgo/core/solver/minres.hpp>
1414

15+
#include "core/config/solver_config.hpp"
1516
#include "core/distributed/helpers.hpp"
1617
#include "core/solver/minres_kernels.hpp"
1718
#include "core/solver/solver_boilerplate.hpp"
@@ -58,6 +59,13 @@ std::unique_ptr<LinOp> Minres<ValueType>::conj_transpose() const
5859
}
5960

6061

62+
template <typename ValueType>
63+
bool Minres<ValueType>::apply_uses_initial_guess() const
64+
{
65+
return true;
66+
}
67+
68+
6169
template <typename ValueType>
6270
void Minres<ValueType>::apply_impl(const LinOp* b, LinOp* x) const
6371
{
@@ -72,6 +80,17 @@ void Minres<ValueType>::apply_impl(const LinOp* b, LinOp* x) const
7280
}
7381

7482

83+
template <typename ValueType>
84+
typename Minres<ValueType>::parameters_type Minres<ValueType>::parse(
85+
const config::pnode& config, const config::registry& context,
86+
const config::type_descriptor& td_for_child)
87+
{
88+
auto params = Minres::build();
89+
common_solver_parse(params, config, context, td_for_child);
90+
return params;
91+
}
92+
93+
7594
/**
7695
* This Minres implementation is based on Anne Grennbaum's 'Iterative Methods
7796
* for Solving Linear Systems' (DOI: 10.1137/1.9781611970937) Ch. 2 and Ch. 8.
@@ -281,6 +300,23 @@ void Minres<ValueType>::apply_impl(const LinOp* alpha, const LinOp* b,
281300
}
282301

283302

303+
template <typename ValueType>
304+
Minres<ValueType>::Minres(std::shared_ptr<const Executor> exec)
305+
: EnableLinOp<Minres>(std::move(exec))
306+
{}
307+
308+
309+
template <typename ValueType>
310+
Minres<ValueType>::Minres(const Factory* factory,
311+
std::shared_ptr<const LinOp> system_matrix)
312+
: EnableLinOp<Minres>(factory->get_executor(),
313+
gko::transpose(system_matrix->get_size())),
314+
EnablePreconditionedIterativeSolver<ValueType, Minres>{
315+
std::move(system_matrix), factory->get_parameters()},
316+
parameters_{factory->get_parameters()}
317+
{}
318+
319+
284320
template <typename ValueType>
285321
int workspace_traits<Minres<ValueType>>::num_vectors(const Solver&)
286322
{

core/test/config/solver.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -20,6 +20,7 @@
2020
#include <ginkgo/core/solver/gmres.hpp>
2121
#include <ginkgo/core/solver/idr.hpp>
2222
#include <ginkgo/core/solver/ir.hpp>
23+
#include <ginkgo/core/solver/minres.hpp>
2324
#include <ginkgo/core/solver/triangular.hpp>
2425
#include <ginkgo/core/stop/iteration.hpp>
2526

@@ -340,6 +341,15 @@ struct CbGmres : SolverConfigTest<gko::solver::CbGmres<float>,
340341
};
341342

342343

344+
struct Minres : SolverConfigTest<gko::solver::Minres<float>,
345+
gko::solver::Minres<double>> {
346+
static pnode::map_type setup_base()
347+
{
348+
return {{"type", pnode{"solver::Minres"}}};
349+
}
350+
};
351+
352+
343353
struct Direct
344354
: SolverConfigTest<gko::experimental::solver::Direct<float, int>,
345355
gko::experimental::solver::Direct<double, int>> {
@@ -468,7 +478,8 @@ class Solver : public ::testing::Test {
468478

469479
using SolverTypes =
470480
::testing::Types<::Cg, ::Fcg, ::Cgs, ::Bicg, ::Bicgstab, ::Ir, ::Idr, ::Gcr,
471-
::Gmres, ::CbGmres, ::Direct, ::LowerTrs, ::UpperTrs>;
481+
::Gmres, ::CbGmres, ::Minres, ::Direct, ::LowerTrs,
482+
::UpperTrs>;
472483

473484

474485
TYPED_TEST_SUITE(Solver, SolverTypes, TypenameNameGenerator);

include/ginkgo/core/solver/minres.hpp

+25-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <ginkgo/core/base/lin_op.hpp>
1414
#include <ginkgo/core/base/math.hpp>
1515
#include <ginkgo/core/base/types.hpp>
16+
#include <ginkgo/core/config/property_tree.hpp>
17+
#include <ginkgo/core/config/registry.hpp>
18+
#include <ginkgo/core/config/type_descriptor.hpp>
1619
#include <ginkgo/core/log/logger.hpp>
1720
#include <ginkgo/core/solver/solver_base.hpp>
1821
#include <ginkgo/core/stop/combined.hpp>
@@ -25,7 +28,7 @@ namespace solver {
2528

2629
/**
2730
* Minres is an iterative type Krylov subspace method, which is suitable for
28-
* indefinite and full-rank symmetric/hermitian operators. It is an
31+
* indefinite and full-rank symmetric/hermitian operators. It is a
2932
* specialization of the Gmres method for symmetric/hermitian operators, and can
3033
* be computed using short recurrences, similar to the CG method.
3134
*
@@ -68,10 +71,8 @@ class Minres
6871

6972
/**
7073
* Return true as iterative solvers use the data in x as an initial guess.
71-
*
72-
* @return true as iterative solvers use the data in x as an initial guess.
7374
*/
74-
bool apply_uses_initial_guess() const override { return true; }
75+
bool apply_uses_initial_guess() const override;
7576

7677
class Factory;
7778

@@ -82,6 +83,24 @@ class Minres
8283
GKO_ENABLE_LIN_OP_FACTORY(Minres, parameters, Factory);
8384
GKO_ENABLE_BUILD_METHOD(Factory);
8485

86+
/**
87+
* Create the parameters from the property_tree.
88+
* Because this is directly tied to the specific type, the value/index type
89+
* settings within config are ignored and type_descriptor is only used
90+
* for children configs.
91+
*
92+
* @param config the property tree for setting
93+
* @param context the registry
94+
* @param td_for_child the type descriptor for children configs. The
95+
* default uses the value type of this class.
96+
*
97+
* @return parameters
98+
*/
99+
static parameters_type parse(const config::pnode& config,
100+
const config::registry& context,
101+
const config::type_descriptor& td_for_child =
102+
config::make_type_descriptor<ValueType>());
103+
85104
protected:
86105
void apply_impl(const LinOp* b, LinOp* x) const override;
87106

@@ -91,18 +110,10 @@ class Minres
91110
void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
92111
LinOp* x) const override;
93112

94-
explicit Minres(std::shared_ptr<const Executor> exec)
95-
: EnableLinOp<Minres>(std::move(exec))
96-
{}
113+
explicit Minres(std::shared_ptr<const Executor> exec);
97114

98115
explicit Minres(const Factory* factory,
99-
std::shared_ptr<const LinOp> system_matrix)
100-
: EnableLinOp<Minres>(factory->get_executor(),
101-
gko::transpose(system_matrix->get_size())),
102-
EnablePreconditionedIterativeSolver<ValueType, Minres>{
103-
std::move(system_matrix), factory->get_parameters()},
104-
parameters_{factory->get_parameters()}
105-
{}
116+
std::shared_ptr<const LinOp> system_matrix);
106117
};
107118

108119

0 commit comments

Comments
 (0)