You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat (linalg_iterative) : add gmres solver to the iterative methods library (#1186)
* start gmres draft
* add comments
* remove kdim from test
* use dot_product
* gmres: add Hilbert matrix test
* linalg: add MGS reorthogonalization to GMRES
* fix: rename loop variable to avoid fypp collision
* fix: hilbert sp tolerance test
* fix: hilbert sp tolerance test
* fix: hilbert dp tolerance test
* fix: hilbert dp tolerance test for Intel 2024 1 cmake
* Update test/linalg/test_linalg_solve_iterative.fypp
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
* Update test/linalg/test_linalg_solve_iterative.fypp
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
* Update test/linalg/test_linalg_solve_iterative.fypp
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
* Update test/linalg/test_linalg_solve_iterative.fypp
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
* Update test/linalg/test_linalg_solve_iterative.fypp
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
* fix declarations
* make gmres implementation flexible by allowing switching between memory efficiency or runtime speed
* add example
* convert static enum to integer helper function to determine the number of colums of the gmres workspace
* simplify iterations logic
* replace manual given rotations and the triangular solve by lapack kernels
* try removing the hilbert test for sp as it is meaningless for the selected size
* Refactor coverage report generation in workflow
Test proposal by copilot to fix coverage report issues. Testing in an actual PR exhibiting coverage issues because of the examples.
* Restrict fpm-deployment coverage upload to the filtered `src/` report (#13)
* Initial plan
* Disable Codecov auto-search in coverage job
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
* add review corrections
* parametrize system size
---------
Co-authored-by: AlexanderGSC <alexander.gsc@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Implements the restarted Generalized Minimal Residual (GMRES) method for solving the linear system \( Ax = b \), where \( A \) is a general linear operator defined via the `stdlib_linop` type. This is the core implementation, allowing custom matrix types, custom preconditioners, and user-managed workspace.
`A`: `class(stdlib_linop_<kind>_type)` defining the linear operator. This argument is `intent(in)`.
375
+
376
+
`M`: `class(stdlib_linop_<kind>_type)` defining the preconditioner linear operator. This argument is `intent(in)`.
377
+
378
+
`b`: 1-D array of `real(<kind>)` defining the loading conditions of the linear system. This argument is `intent(in)`.
379
+
380
+
`x`: 1-D array of `real(<kind>)` which serves as the input initial guess and the output solution. This argument is `intent(inout)`.
381
+
382
+
`rtol` and `atol`: scalars of type `real(<kind>)` specifying the convergence test. For convergence, the following criterion is used \( || b - Ax ||^2 <= max(rtol^2 * || b ||^2 , atol^2 ) \). These arguments are `intent(in)`.
383
+
384
+
`maxiter`: scalar of type `integer` defining the maximum allowed number of iterations. This argument is `intent(in)`.
385
+
386
+
`kdim`: scalar of type `integer` defining the Krylov subspace size before restart. This argument is `intent(in)`.
387
+
388
+
`workspace`: scalar derived type of `type(stdlib_solver_workspace_<kind>_type)` holding the work array for the solver. This argument is `intent(inout)`.
389
+
390
+
`compact`: scalar of type `logical`. If true, GMRES stores only one preconditioned basis vector at a time and rebuilds the cycle-end correction through the preconditioner, reducing memory usage. If false, GMRES caches the full preconditioned basis for a faster cycle-end update at the cost of additional memory. Default is `.true.`. This argument is `intent(in)`.
391
+
392
+
#### Note
393
+
394
+
GMRES trades increasing memory and orthogonalization cost for robust convergence on general non-symmetric systems. The `compact` option allows choosing between a lower-memory layout and a slightly faster restart update.
Provides a user-friendly interface to the restarted GMRES method for solving \( Ax = b \), supporting `dense` and `CSR_<kind>_type` matrices. GMRES is suitable for general non-symmetric systems and supports optional preconditioning, workspace reuse, and a storage-mode choice for balancing memory use against cycle-end update speed.
402
+
403
+
#### Syntax
404
+
405
+
`call `[[stdlib_linalg_iterative_solvers(module):stdlib_solve_gmres(interface)]]` (A, b, x [, di, rtol, atol, maxiter, restart, kdim, precond, M, workspace, compact])`
406
+
407
+
#### Status
408
+
409
+
Experimental
410
+
411
+
#### Class
412
+
413
+
Subroutine
414
+
415
+
#### Argument(s)
416
+
417
+
`A`: `dense` or `CSR_<kind>_type` matrix defining the linear system. This argument is `intent(in)`.
418
+
419
+
`b`: 1-D array of `real(<kind>)` defining the loading conditions of the linear system. This argument is `intent(in)`.
420
+
421
+
`x`: 1-D array of `real(<kind>)` which serves as the input initial guess and the output solution. This argument is `intent(inout)`.
422
+
423
+
`di` (optional): 1-D mask array of type `logical(int8)` defining the degrees of freedom subject to dirichlet boundary conditions. The actual boundary condition values should be stored in the `b` load array. This argument is `intent(in)`.
424
+
425
+
`rtol` and `atol` (optional): scalars of type `real(<kind>)` specifying the convergence test. For convergence, the following criterion is used \( || b - Ax ||^2 <= max(rtol^2 * || b ||^2 , atol^2 ) \). Default values are `rtol=1.e-5` and `atol=epsilon(1._<kind>)`. These arguments are `intent(in)`.
426
+
427
+
`maxiter` (optional): scalar of type `integer` defining the maximum allowed number of iterations. If no value is given, a default of `N` is set, where `N = size(b)`. This argument is `intent(in)`.
428
+
429
+
`restart` (optional): scalar of type `logical` indicating whether to restart the iteration with zero initial guess. Default is `.true.`. This argument is `intent(in)`.
430
+
431
+
`kdim` (optional): scalar of type `integer` defining the Krylov subspace size before restart. If no value is given, a default of `min(30, N)` is used. This argument is `intent(in)`.
432
+
433
+
`precond` (optional): scalar of type `integer` enabling to switch among the default preconditioners available with the following enum (`pc_none`, `pc_jacobi`). If no value is given, no preconditioning will be applied. This argument is `intent(in)`.
434
+
435
+
`M` (optional): scalar derived type of `class(stdlib_linop_<kind>_type)` defining a custom preconditioner linear operator. If given, `precond` will have no effect, and a pointer is set to this custom preconditioner. This argument is `intent(in)`.
436
+
437
+
`workspace` (optional): scalar derived type of `type(stdlib_solver_workspace_<kind>_type)` holding the work temporal array for the solver. If the user passes its own `workspace`, then internally a pointer is set to it, otherwise, memory will be internally allocated and deallocated before exiting the procedure. This argument is `intent(inout)`.
438
+
439
+
`compact` (optional): scalar of type `logical`. If true, GMRES stores only one preconditioned basis vector per iteration cycle and minimizes memory use. If false, GMRES caches the full preconditioned basis to speed up the cycle-end update. Default is `.true.`. This argument is `intent(in)`.
440
+
441
+
#### Note
442
+
443
+
GMRES is especially useful for general non-symmetric systems where CG and PCG do not apply. Its main cost is the Krylov basis storage and orthogonalization work within each restart cycle. With `compact=.true.`, the solver reduces workspace requirements significantly. With `compact=.false.`, it retains the previous cached-basis update strategy.
0 commit comments