Cg! per-iteration trace differs between single call and multiple calls

Calling IterativeSolvers.cg! for N iterations in one call produces a different per-iteration residual sequence than performing the same total number of iterations via multiple cg! calls.
A single call with 6 iterations produces a different result from two calls of thee iterations, or six calls of one iteration. Continuing with the same statevars or reseting them, does not seem to have an effect.

Is this normal behavior in the cg! implementation?

See pcg_minrepro.jl (2.0 KB)

Output sample:
Example (n=50 run):

continued 1x6 = [34.64101615137756, 33.22649545167231, 31.811947441173714, 30.397368307141303, 28.982753492378862, 27.568097504180436]
continued 3+3 = [34.64101615137756, 33.22649545167231, 31.811947441173714, 22.449999274606412, 22.31701560306767, 15.91631301611577]
restarted 3+3 = [34.64101615137756, 33.22649545167231, 31.811947441173714, 22.449999274606412, 22.31701560306767, 15.91631301611577]
continued 6x1 = [34.64101615137756, 17.620484724263306, 13.3463058496797, 11.283385733387556, 10.331019501894122, 9.610386186347737]
restarted 6x1 = [34.64101615137756, 17.620484724263306, 13.3463058496797, 11.283385733387556, 10.331019501894122, 9.610386186347737]

Environment

  • Julia: 1.12.6
  • OS: macOS (arm64-apple-darwin24.0.0) on Apple M2 Max
  • IterativeSolvers package: v0.9.4
1 Like