# Using PETSc to solve Ax=rhs

**URL:** https://discourse.julialang.org/t/using-petsc-to-solve-ax-rhs/117140
**Category:** General Usage
**Created:** [July 17, 2024, 1:11pm UTC](https://discourse.julialang.org/t/using-petsc-to-solve-ax-rhs/117140 "2024-07-17T13:11:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Van\_Sy\_Tnut](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/van_sy_tnut/32/217602_2.png) [@Van\_Sy\_Tnut](https://discourse.julialang.org/u/Van_Sy_Tnut)
#### Post date: [July 17, 2024, 1:11pm UTC](https://discourse.julialang.org/t/using-petsc-to-solve-ax-rhs/117140/1 "2024-07-17T13:11:54Z")

</div>

Hello everyone,  
I am trying to reduce the time for solving the system of linear equations: **Ax=rhs**.  
My method is to use **factorization** provided by “pkg:LinearAlgebra”.  
However, I know that if we can use **PETSc** it will be much faster for the large matrix.  
Herein, I give a simple code for illustration by using factorization provided by “pkg:LinearAlgebra”.  
Then, if you know how to use “PETSc” in Julia to modify these codes, could you please help me? I appreciate your help.  
Thanks a lot.

```julia
using LinearAlgebra
n = 10000; # size of matrix
A = 100*rand(n,n); # matrix A
rhs = 5*rand(n); # Right hand side rhs
A_factorized = factorize(Symmetric(A)) # factorize
x = A_factorized\rhs; # Solve

```

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [July 17, 2024, 1:26pm UTC](https://discourse.julialang.org/t/using-petsc-to-solve-ax-rhs/117140/2 "2024-07-17T13:26:41Z")

</div>

for dense matrices like the one you posted, LinearAlgebra is likely to be optimal as long as you aren’t on a cluster. For large sparse matrices, you likely want to use LinearSolve.jl which, like PETSc, provides krylov methods as well as factorization based methods.

---

<div class="post-metadata">

### Author: ![Van\_Sy\_Tnut](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/van_sy_tnut/32/217602_2.png) [@Van\_Sy\_Tnut](https://discourse.julialang.org/u/Van_Sy_Tnut)
#### Post date: [July 21, 2024, 9:32pm UTC](https://discourse.julialang.org/t/using-petsc-to-solve-ax-rhs/117140/3 "2024-07-21T21:32:44Z")

</div>

Dear Smith,  
Thank you for your recommendation about using LinearSolve.jl.  
Best regards,
