selah_anderson
SELAH, L1: Anderson acceleration of the fixed-point iteration of an implicit stage.
The implicit stage U = E + gamma R(U) is the fixed point of G(U) = E + gamma R(U); the plain iteration U <- G(U) contracts only where |gamma lambda| < 1. Anderson's acceleration (Anderson 1965; Walker & Ni 2011, Algorithm AA) mixes the last m iterates instead: with f_k = G(x_k) - x_k and the differences dF_i = f_{i+1} - f_i, dG_i = G(x_{i+1}) - G(x_i) of the last m_k = min(m, k) iterations,
x_{k+1} = G(x_k) - sum_i c_i dG_i, c = argmin || f_k - sum_i c_i dF_i ||_2.
On a linear residual it is a Krylov method (GMRES's iterates, Walker & Ni 2011, with m at least the iterations), so it converges where the plain iteration diverges, with no Jacobian.
anderson_mixing is driven by its caller inside the stage (D1 of #11): with the stage state x and R(x) in the stage's register, residual makes G(x), f and the new differences, and returns the partial sums of the iteration (f.f, G.G, dF_i.dF_new, dF_i.f) over its box; the caller sums them over its boxes and ranks (one reduction per iteration) and asks converged(sums); if not, mix(bx, x, sums) writes x_{k+1} into the stage state, by the least-squares solve on the host (the normal equations of the m_k x m_k Gram matrix, by Cholesky; the oldest differences dropped while it is not positive definite to rounding). Its registers (2 m + 2 of the field's size) are allocated at the first residual, from the field's bounds, on the device in a device build. Converged means ||f|| <= atol + rtol ||G(x)|| (2-norms over the whole field): then R(x) is the stage's residual, and the stepper's update E + gamma R(x) = G(x).
Source: src/lib/selah_anderson.F90
Dependencies
Contents
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
ANDERSON_MAX_DEPTH | integer(kind=I4P) | parameter | The largest depth m. |
Derived Types
anderson_mixing
Anderson acceleration of depth m.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
m | integer(kind=I4P) | Depth. | |
atol | real(kind=R_P) | Absolute tolerance on ||f||. | |
rtol | real(kind=R_P) | Relative tolerance, of ||G(x)||. | |
max_iterations | integer(kind=I4P) | Iterations before converged stops the run. | |
iterations | integer(kind=I4P) | residual calls since start. | |
mk | integer(kind=I4P) | Differences held. | |
newest | integer(kind=I4P) | The ring slot of the newest difference. | |
gram | real(kind=R_P) | allocatable | dF_i.dF_j, by ring slot. |
coef | real(kind=R_P) | allocatable | The mixing coefficients, by ring slot (host). |
coef_d | real(kind=R_P) | pointer | Their device copy. |
regs | real(kind=R_P) | pointer | f, G(x), then dF and dG by ring slot. |
lbr | integer(kind=I4P) | The registers' bounds. | |
ubr | integer(kind=I4P) | The registers' bounds. |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
initialize | pass(self) | Depth and tolerances. |
destroy | pass(self) | Free the registers. |
start | pass(self) | A new solve. |
sums_size | pass(self) | The number of partial sums (2 m + 2). |
residual | pass(self) | G(x), f, the differences; the partial sums of the box. |
converged | pass(self) | ||f|| within the tolerance, from the reduced sums. |
mix | pass(self) | x_{k+1} into the stage state. |
anderson_mixing%initialize
Depth m (1 .. ANDERSON_MAX_DEPTH) and the tolerances (defaults: atol 0, rtol 1e-12, 100 iterations).
subroutine initialize(self, m, atol, rtol, max_iterations)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(anderson_mixing) | inout | Mixing. | |
m | integer(kind=I4P) | in | Depth. | |
atol | real(kind=R_P) | in | optional | Absolute tolerance. |
rtol | real(kind=R_P) | in | optional | Relative tolerance. |
max_iterations | integer(kind=I4P) | in | optional | Iterations allowed. |
Call graph
anderson_mixing%destroy
Free the registers.
subroutine destroy(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(anderson_mixing) | inout | Mixing. |
anderson_mixing%start
A new solve: no differences held.
subroutine start(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(anderson_mixing) | inout | Mixing. |
anderson_mixing%sums_size
The partial sums residual returns: f.f, G.G, then dF_i.dF_new and dF_i.f for the m ring slots.
Attributes: pure
Returns: integer(kind=I4P)
function sums_size(self) result(n)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(anderson_mixing) | in | Mixing. |
anderson_mixing%residual
With r = R(x): G(x) = e + gam r, f = G(x) - x, the new differences dF = f - f_prev, dG = G(x) - G_prev (from the second call of a solve), and the box's partial sums: sums(1) = f.f, sums(2) = G.G, sums(2 + i) = dF_i.dF_new, sums(2 + m + i) = dF_i.f (ring slot i; 0 for an empty slot). The caller sums them over its boxes and ranks.
subroutine residual(self, bx, gam, e, r, x, sums)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(anderson_mixing) | inout | Mixing. | |
bx | type(box) | in | Box. | |
gam | real(kind=R_P) | in | gamma = dt stage_gamma(k). | |
e | real(kind=R_P) | in | Explicit part E. | |
r | real(kind=R_P) | in | R(x). | |
x | real(kind=R_P) | in | The iterate (the stage state). | |
sums | real(kind=R_P) | out | Partial sums [2 m + 2]. |
Call graph
anderson_mixing%converged
||f|| <= atol + rtol ||G(x)||, from the caller's reduced sums; an error stop past max_iterations, or when a sum is not finite (the iteration diverged: Anderson converges for a contractive map, and beyond only with depth enough for the spectrum).
Returns: logical
function converged(self, sums) result(yes)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(anderson_mixing) | in | Mixing. | |
sums | real(kind=R_P) | in | Reduced sums. |
anderson_mixing%mix
x_{k+1} = G(x_k) - sum_i c_i dG_i into the stage state, c from the reduced sums (the plain iteration G(x_k) at the first call of a solve).
subroutine mix(self, bx, x, sums)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(anderson_mixing) | inout | Mixing. | |
bx | type(box) | in | Box. | |
x | real(kind=R_P) | inout | The stage state, x_{k+1} out. | |
sums | real(kind=R_P) | in | Reduced sums. |
Call graph