Skip to content

Commit aa12d70

Browse files
committed
add minres config parsing
1 parent 34bc634 commit aa12d70

File tree

6 files changed

+81
-19
lines changed

6 files changed

+81
-19
lines changed

core/config/config_helper.hpp

+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

@@ -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/matrix/dense.hpp>
1821
#include <ginkgo/core/matrix/identity.hpp>
@@ -27,7 +30,7 @@ namespace solver {
2730

2831
/**
2932
* Minres is an iterative type Krylov subspace method, which is suitable for
30-
* indefinite and full-rank symmetric/hermitian operators. It is an
33+
* indefinite and full-rank symmetric/hermitian operators. It is a
3134
* specialization of the Gmres method for symmetric/hermitian operators, and can
3235
* be computed using short recurrences, similar to the CG method.
3336
*
@@ -63,10 +66,8 @@ class Minres
6366

6467
/**
6568
* Return true as iterative solvers use the data in x as an initial guess.
66-
*
67-
* @return true as iterative solvers use the data in x as an initial guess.
6869
*/
69-
bool apply_uses_initial_guess() const override { return true; }
70+
bool apply_uses_initial_guess() const override;
7071

7172
class Factory;
7273

@@ -77,6 +78,24 @@ class Minres
7778
GKO_ENABLE_LIN_OP_FACTORY(Minres, parameters, Factory);
7879
GKO_ENABLE_BUILD_METHOD(Factory);
7980

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

@@ -86,18 +105,10 @@ class Minres
86105
void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
87106
LinOp* x) const override;
88107

89-
explicit Minres(std::shared_ptr<const Executor> exec)
90-
: EnableLinOp<Minres>(std::move(exec))
91-
{}
108+
explicit Minres(std::shared_ptr<const Executor> exec);
92109

93110
explicit Minres(const Factory* factory,
94-
std::shared_ptr<const LinOp> system_matrix)
95-
: EnableLinOp<Minres>(factory->get_executor(),
96-
gko::transpose(system_matrix->get_size())),
97-
EnablePreconditionedIterativeSolver<ValueType, Minres>{
98-
std::move(system_matrix), factory->get_parameters()},
99-
parameters_{factory->get_parameters()}
100-
{}
111+
std::shared_ptr<const LinOp> system_matrix);
101112
};
102113

103114

0 commit comments

Comments
 (0)