# Checking for error in conjugate gradient algorithm

What is a good way to check if the any numerical error is occured in conjugate gradient algorithm. Additionally why is it not suggested to check error by checking A-orthogonality of search direction or checking orthogonality of residuals?

Note: here by error I mean error from floating point unit of CPU because of incorrect computation (which can be due to corrupt data in cache etc.) not due to rounding error. In some cases the errors can be due incorrect computation of matrix vector product (in cases where matrix A is not explicitly available).

• Your definition of "error" seems unrelated to the conjugate gradient algorithm per se ("due to corrupt data in cache etc."). I see no reason to think there should be a CG specific way to "check" for errors of that kind. You may also be conflating hardware and software errors when you reference "incorrect computation of matrix vector product". Certainly a component module performing that task should be debugged with respect to its own specifications, as incorrect matrix-vector products cannot be useful for reliable implementation of a conjugate gradient solver. Nov 28 '12 at 16:01
• Think about this as follows: I give you a piece of "probabilistic" processor which gives you correct output for each operation for 95 times out of 100. But if error occurs at any iteration for CG, it will not converge. In that case I would redo the iteration if I detect the error has occured. But question is how do I know that error has occured? Nov 28 '12 at 16:22

If you try to use the CG to seek the least square solution of $Ax=b$, where $A$ is not symmetric or even square, you will solve the normal equation $A^TAx=A^Tb$.
In this case, from my experience, it's very important to check if $A^T$ is indeed the adjoint of $A$ by using the definition of adjoint (inner product), especially when you implicitly compute $A$ and $A^T$. Every time I found my CG didn't converge, it's due to the error from $A^T$, i.e. it's not the strictly adjoint of $A$.
• Let's just assume that input matrix $A$ is SPD. Most of the iteration go right until one of the operation in an iteration gives incorrect value due to probabilistic nature of processor Nov 28 '12 at 16:30