  We present a new algorithm that computes eigenvalues and eigenvectors of a
Hermitian positive definite matrix while solving a linear system of equations
with Conjugate Gradient (CG). Traditionally, all the CG iteration vectors could
be saved and recombined through the eigenvectors of the tridiagonal projection
matrix, which is equivalent theoretically to unrestarted Lanczos. Our algorithm
capitalizes on the iteration vectors produced by CG to update only a small
window of vectors that approximate the eigenvectors. While this window is
restarted in a locally optimal way, the CG algorithm for the linear system is
unaffected. Yet, in all our experiments, this small window converges to the
required eigenvectors at a rate identical to unrestarted Lanczos. After the
solution of the linear system, eigenvectors that have not accurately converged
can be improved in an incremental fashion by solving additional linear systems.
In this case, eigenvectors identified in earlier systems can be used to
deflate, and thus accelerate, the convergence of subsequent systems. We have
used this algorithm with excellent results in lattice QCD applications, where
hundreds of right hand sides may be needed. Specifically, about 70 eigenvectors
are obtained to full accuracy after solving 24 right hand sides. Deflating
these from the large number of subsequent right hand sides removes the dreaded
critical slowdown, where the conditioning of the matrix increases as the quark
mass reaches a critical value. Our experiments show almost a constant number of
iterations for our method, regardless of quark mass, and speedups of 8 over
original CG for light quark masses.
