We consider the behavior of the GMRES method for solving a linear syst
em Ax = b when A is singular or nearly so, i.e., ill conditioned. The
(near) singularity of A may or may not affect the performance of GMRES
, depending on the nature of the system and the initial approximate so
lution. For singular A, we give conditions under which the GMRES itera
tes converge safely to a least-squares solution or to the pseudoinvers
e solution. These results also apply to any residual minimizing Krylov
subspace method that is mathematically equivalent to GMRES. A practic
al procedure is outlined for efficiently and reliably detecting singul
arity or ill conditioning when it becomes a threat to the performance
of GMRES.