# How do I make sparse solvers to accept custom matvec function insted of matrix?

I have tried it with Lis, Intel mkl and PETSc. Everywhere you need to pass an actual matrix to GMRES or other similar iterative solver, while I want to pass just function which multiplies my matrix on vector (my matrix is having special structure and forming it completely is inefficient).

There is no problem for me writing simple solver which would accept my custom matrix-vector product myself, but I think this kind of problem should be probably already figured out and implemented in many libraries.

PETSc does this. See the documentation for MatShell and Section 3.3 in the manual.