You can use MatCreateMFFD https://petsc.org/main/docs/manualpages/Mat/MatCreateMFFD/ <https://petsc.org/main/docs/manualpages/Mat/MatCreateMFFD/> MatMFFDSetFunction MatSetFromOptions MatMFFDSetBase and provide the matrix to KSP. Note you will need to use -pc_type none or provide your own custom preconditioner with https://petsc.org/main/docs/manualpages/PC/PCSHELL/ <https://petsc.org/main/docs/manualpages/PC/PCSHELL/>
> On May 24, 2022, at 1:21 PM, Tu, Jiannan <jiannan...@uml.edu> wrote: > > I want to use a matrix-free matrix to solve a large linear equation system > because the matrix is too large to be stored. Petsc user manual describes > matrix-free method for SNES with examples. The matrix-free matrices section > explains how to set up such a matrix, but I can't find any example of > matrix-free method with KSP. I am wondering how to apply the method to KSP > iterative solver in parallel. > > I greatly appreciate your help for me to understand this topic. > > Jiannan Tu