# Where can I find matrices and it's preconditioner for testing?

I want to find some kinds of matrices for testing my code such as GMRES , MINRES and so on. But I can't find some testing matrices and corresponding preconditioner to verify my program.

I know some website like MatrixMarket (see this question) ,but I couldn't find corresponding preconditioner of a matrix. Can anyone help me?

• Welcome to Computational Science SE. Can you clarify what a corresponding preconditioner would mean? There are a lot of different ways one can precondition the same system of linear equations. Dec 27, 2021 at 13:58
• You can try PETSc, e.g., see petsc.org/main/docs/manualpages/PC/PCType.html Dec 27, 2021 at 15:51

## 2 Answers

I think there’s some confusion here. There’s no matrix and corresponding preconditioner. The latter are usually derived mechanically on the fly as the iterative scheme evolves unless you already have the matrix inverse, which would be the perfect preconditioner as you’d just apply the inverse and the iterative method would converge on its first step. The matrix may also be created from, say, timestep to timestep, and change as the code evolves. So, it may never be stored in a complete form either, just computed as needed.

In lots of methods where we have a step showing that we need the inverse of a matrix applied to an object, we often do not have the matrix fully formed, and so will never fully form it nor its inverse. We simply need to perform their actions on arbitrary vectors. As a result, the preconditioner will probably never be fully constructed in most production programs since, for big problems, the pieces of your matrix are scattered all over the memory of a large parallel computer.

But don’t despair, there are libraries, as mentioned in other answers and comments that handle these issues, so you “just” have to adapt your code to their manner of representing matrices and vectors.

• Also, you can make you own test suites by randomly selecting a matrix and an answer vector and multiplying to get the target RHS. This is the so called Method of Manufactured Solutions and should work as well for testing linear algebra solvers as it does for PDE problems. Dec 29, 2021 at 14:58

Generally, preconditioners are considered to be part of the solver, so they are not included in test matrix collections. In fact, preconditioners are rarely constructed as an explicit matrix, making it hard to include them in a programming-language-agnostic manner.

If you're using an existing sparse linear algebra framework or a language like MATLAB or Julia, there should be plenty of preconditioners already implemented. Otherwise, there are a number that are easy to implement.

• The identity matrix - doesn't help convergence, but trivial to implement and helpful for checking correctness
• A scaler Jacobi preconditioner - just the matrix diagonal
• A block Jacobi preconditioner - diagonal blocks of the matrix (requires solving small linear systems at each step)
• Incomplete LU/Cholesky - A bit more involved, but still relatively straightforward to implement in it's most basic form.

As a final side note, I think the SuiteSparse collection has all of the matrices from MatrixMarket plus many more.

• Thank you for your kind answer, which helps me understand how to use the preconditioner in the solver .I still have a lot to learn... Dec 28, 2021 at 5:15