# Would recalculating the residual in the conjugate gradient method help?

The conjugate gradient method suffers from an accumulation of errors as it continues. For this reason it is unwise to use it as a direct solver. My question is, would it help to recalculate the residual every 5 or so steps in an attempt to mitigate these sorts of errors even when used as an iterative solver? I've not heard of people doing this but it seems kind of obvious. If it wouldn't help, can you explain why?

• Hi Cramer and welcome to scicomp! Could you give a little more detail on the problem you're solving and how you implemented the CG method? This will help us address your question more precisely. – Paul Nov 15 '13 at 13:50
• I'm working on structural optimisation and I've implemented it in a matrix free fashion using CUDA. But the question is more general, the residual is key to the method working, and it can be calculated at any time for a reasonable cost (although I can understand not calculating it every time if you don't have to). – Cramer Nov 15 '13 at 14:00

• If you run CG for a long time (e.g. $n$ iterations), then the vectors in the CG algorithm can lose their orthogonality due to round-off errors. Sometimes the method is "restarted" after a large number of iterations to deal with this. For example,you might restart every $n$ iterations. As you've said, the CG method is most commonly used on very large scale problems and not run for even a significant fraction of $n$ iterations, and under those circumstances restarting isn't really necessary. – Brian Borchers Nov 15 '13 at 16:20