# size() in gmres

+1 vote

Dear ITensor,

I'm using the gmres algorithm. I'm wondering how should the size() function be defined in the BigMatrix type.

I was assuming that, since it's a Krylov space method, size() should be n, if the BigMatrix is nxn when written as a matrix. gmres in Itensor works very well in most cases. However, I find that sometimes it does not give the correct answer. However, if I change n to n^2 in the size() function, gmres does give the correct answer. Is n^2 supposed to be the correction return for size()?

Thanks,
Yantao

commented by (9.8k points)
size() is meant to be the linear size (what you call n, for an n x n linear operator). It's been a while since I looked at that function, but it appears that the size() function is only used to set the maximum number of iterations, as you can see here: https://github.com/ITensor/ITensor/blob/v3/itensor/iterativesolvers.h#L537

It is possible that for some problems it is having trouble converging, and for some reason requires more than size() iterations. I would think at least theoretically that shouldn't be the case, since once you reach n Krylov vectors then the entire space is determined, but perhaps there are some orthogonality issues that are showing up that are degrading the accuracy when using such a large Krylov space.

Instead of changing the definition of size(), I would instead try playing around with the arguments "MaxIter", "ErrGoal", and "RestartIter". Generally for iterative solvers I would recommend setting "MaxIter" to something quite large, and then adjust "ErrGoal" based on the accuracy you need for your particular application. "RestartIter" sets the number of iterations before the Krylov space is restarted, which can help if your "ErrGoal" is not reached in a relatively small number of iterations and orthogonality issues show up. So an example might be, for a problem of size 100 x 100, to use something like:

gmres(A, b, x, {"MaxIter=", 200, "ErrGoal=", 1E-10, "RestartIter=", 30)

where of course you should adjust the specific numbers based on your application (perhaps try setting "MaxIter=", 2*n for a problem of size n, for example).
commented by (310 points)
Dear Matt,

Thanks very much. I will try these.

Yantao