Questions on QR methods in PETSc
Dear Users Support Team, I have a couple of questions regarding QR decompositions in PETSc. 1) I would like to find the least-squares solution of a rectangular system of the form Ax = b, where A is a dense and tall-skinny matrix (size around 1000000 x 10). Since A has very bad conditioning, I want to avoid iterative methods (such as KSPLSQR), since the number of iterations can get very large, and would like to use a direct QR solving method. Currently, I am running my code on only 1 core, and A is of type seqaij. With this setup, the following code works fine: call KSPSetType(ksp, KSPPREONLY, ierr) call KSPGetPC(ksp, pc, ierr) call PCSetType(pc, PCQR, ierr) call KSPSetOperators(ksp, A, A, ierr) t1 = MPI_Wtime() call KSPSolve(ksp, b, x, ierr) t2 = MPI_Wtime() I eventually want to run this in parallel on multiple cores. Will PCQR work for an mpiaij / mpidense matrix? If not, what would you suggest as a direct solving approach for this system? 2) I would also like to compute an explicit QR decomposition of A, and want to do so in parallel. Is there any way to do so in PETSc? If not, as a possible alternative, would you recommend using SLEPc BVOrthogonalize function? Kind regards, Leonardo
El 27 mar 2026, a las 15:10, Leonardo De Novellis via petsc-users <[email protected]> escribió:
Dear Users Support Team, I have a couple of questions regarding QR decompositions in PETSc.
1) I would like to find the least-squares solution of a rectangular system of the form Ax = b, where A is a dense and tall-skinny matrix (size around 1000000 x 10). Since A has very bad conditioning, I want to avoid iterative methods (such as KSPLSQR), since the number of iterations can get very large, and would like to use a direct QR solving method. Currently, I am running my code on only 1 core, and A is of type seqaij. With this setup, the following code works fine:
call KSPSetType(ksp, KSPPREONLY, ierr) call KSPGetPC(ksp, pc, ierr) call PCSetType(pc, PCQR, ierr) call KSPSetOperators(ksp, A, A, ierr) t1 = MPI_Wtime() call KSPSolve(ksp, b, x, ierr) t2 = MPI_Wtime()
I eventually want to run this in parallel on multiple cores. Will PCQR work for an mpiaij / mpidense matrix? If not, what would you suggest as a direct solving approach for this system?
As an alternative, you can try PCSVD. If your matrix is ill-conditioned, I would trust SVD more than QR. Both PCQR and PCSVD are sequential, but PCSVD will work in parallel by creating a redundant dense matrix replicated in all processes, so that computation is still sequential. You can obtain a similar behaviour with PCREDUNDANT + PCQR.
2) I would also like to compute an explicit QR decomposition of A, and want to do so in parallel. Is there any way to do so in PETSc? If not, as a possible alternative, would you recommend using SLEPc BVOrthogonalize function?
PETSc does not have parallel QR. In SLEPc BVOrthogonalize() will do the job. I would try the TSQR and SVQB methods, they should work for ill-conditioned matrices. With 1 MPI process TSQR should be equivalent to PCQR. You can also use the result of BVOrthogonalize() to compute the least-squares solution as x=R^{-1}*Q^T*b. Jose
Kind regards, Leonardo
Hi Leonardo, On Fri, Mar 27, 2026 at 11:35 AM Leonardo De Novellis via petsc-users < [email protected]> wrote:
Dear Users Support Team, I have a couple of questions regarding QR decompositions in PETSc.
1) I would like to find the least-squares solution of a rectangular system of the form Ax = b, where A is a dense and tall-skinny matrix (size around 1000000 x 10). Since A has very bad conditioning, I want to avoid iterative methods (such as KSPLSQR), since the number of iterations can get very large, and would like to use a direct QR solving method. Currently, I am running my code on only 1 core, and A is of type seqaij. With this setup, the following code works fine:
call KSPSetType(ksp, KSPPREONLY, ierr) call KSPGetPC(ksp, pc, ierr) call PCSetType(pc, PCQR, ierr) call KSPSetOperators(ksp, A, A, ierr) t1 = MPI_Wtime() call KSPSolve(ksp, b, x, ierr) t2 = MPI_Wtime()
I eventually want to run this in parallel on multiple cores. Will PCQR work for an mpiaij / mpidense matrix?
No it is only serial. We could call the ScLAPACK or Elemental version of QR, but we don't right now.
If not, what would you suggest as a direct solving approach for this system?
It would be easy to make the normal equations (dot products would make the matrix on all procs) and factor.
2) I would also like to compute an explicit QR decomposition of A, and want to do so in parallel. Is there any way to do so in PETSc? If not, as a possible alternative, would you recommend using SLEPc BVOrthogonalize function?
I would definitely recommend using BV. I have been meaning to pull that into PETSc because it is so great, but have not done it yet. You can just reconfigure with --download-slepc and run with it. Thanks, Matt
Kind regards, Leonardo
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCf... <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfs... >
participants (3)
-
Jose E. Roman -
Leonardo De Novellis -
Matthew Knepley