Skip to content

Conversation

@jalvesz
Copy link
Contributor

@jalvesz jalvesz commented May 17, 2025

This PR introduces the base for iterative solvers.

Two methods are proposed:

  • Conjugate Gradient (CG)
  • Preconditioned Conjugate Gradient (PCG)

Each method is made public with two public interface flavors:

  • stdlib_solve_<method>_kernel: All arguments are mandatory (no optionals/no internal allocations), it contains the methods steps. The linear system (and preconditioner) is defined through a public DT stdlib_linop which enables to extend two key procedures: matvec equivalent to a matrix-vector product and inner_product equivalent to the dot_product. This is the interface recommended to extend the method when dealing with a matrix type not available in stdlib or when working in distributed-memory frameworks for which the matvec, dot_product and factorization steps need to be adapted to account for parallel synchronization.
  • stdlib_solve_<method>: API with optional arguments, the linear system can be defined with dense or CSR_<>_type matrices. For the PCG, the following preconditioners are available: none (identity), jacobi (1/diagonal). It internally uses stdlib_solve_<method>_kernel.
  • tests
  • examples
  • documentation

jalvesz and others added 30 commits March 2, 2025 22:26
@jalvesz
Copy link
Contributor Author

jalvesz commented Sep 19, 2025

@jvdp1 thanks for your reviews. I think I managed to address all of them. Let me know your thoughts.

Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jalvesz. LGTM.

@jalvesz
Copy link
Contributor Author

jalvesz commented Sep 25, 2025

With no more comments I'll go ahead and merge this.

@jalvesz jalvesz merged commit fb404bb into fortran-lang:master Sep 25, 2025
16 checks passed
@jalvesz jalvesz deleted the iterative branch September 26, 2025 10:22
Mahmood-Sinan pushed a commit to Mahmood-Sinan/stdlib that referenced this pull request Dec 17, 2025
* start iterative solvers

* simplify workspace

* add pccg solver and example

* complete cg with dirichlet flag, add example, fix di filter

* add other sparse matrices

* add example for custom solver extending the generic interface

* small simplifications for working data

* make default inner_product point to a default dot_product add enum for workspace sizes

* make preconditionner a linop

* use facility size

* Add a customizable logger facility, change linop matvec to apply

* change internal procedure names for custom example

* refactor to remove hard dependency on dirichlet BCs

* add forward/backward solvers for preconditionning

* fix solve forward/backward

* fix colum index

* add preconditionners

* fix cmake

* add factorizations

* backward solve to use Lt marix

* start unit testing

* review csr factorization

* change name generic for kernel

* shorten factorization procedures names

* change precond ldl name

* rename to pcg

* start working on the documentation

* clean docstrings

* add cg and pcg tests

* Update example/linalg/example_solve_cg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* add _type suffix

* reduce PR scope

* rename wksp size constants

* rename constant

* change signature of linop apply to matvec and add operator input argument

* Update doc/specs/stdlib_linalg_iterative_solvers.md

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update test/linalg/test_linalg_solve_iterative.fypp

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update test/linalg/test_linalg_solve_iterative.fypp

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update src/stdlib_linalg_iterative_solvers_cg.fypp

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update src/stdlib_linalg_iterative_solvers_cg.fypp

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update doc/specs/stdlib_linalg_iterative_solvers.md

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_cg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update doc/specs/stdlib_linalg_iterative_solvers.md

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update doc/specs/stdlib_linalg_iterative_solvers.md

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update doc/specs/stdlib_linalg_iterative_solvers.md

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update doc/specs/stdlib_linalg_iterative_solvers.md

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_cg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_cg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_custom.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_custom.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_custom.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_custom.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_custom.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_custom.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_custom.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_pcg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_pcg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_pcg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_pcg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_pcg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update example/linalg/example_solve_pcg.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update src/stdlib_linalg_iterative_solvers_cg.fypp

Co-authored-by: Jeremie Vandenplas <[email protected]>

* small fixes

* add documentation information

* forgotten attribute in doc

* use optval

* explicit use of private/public

* Update doc/specs/stdlib_linalg_iterative_solvers.md

Co-authored-by: Jeremie Vandenplas <[email protected]>

* rename with stdlib_ prefix

* Update example/linalg/example_solve_custom.f90

Co-authored-by: Jeremie Vandenplas <[email protected]>

* Update src/stdlib_linalg_iterative_solvers_pcg.fypp

Co-authored-by: Jeremie Vandenplas <[email protected]>

* replace tol by rtol and atol for convergence test

* change rtol and atol defaults

---------

Co-authored-by: Jeremie Vandenplas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants