# Solving A\\b in parallel

**URL:** https://discourse.julialang.org/t/solving-a-b-in-parallel/10011
**Category:** Julia at Scale
**Tags:** parallel, linearalgebra
**Created:** [March 27, 2018, 5:14pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011 "2018-03-27T17:14:49Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [March 27, 2018, 5:14pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/1 "2018-03-27T17:14:49Z")

</div>

I have an access to a large _shared_-memory machine. It has memory in the order of TB, and has 64 CPU cores.

If I want to perform `A\b` for a square matrix `A` and column vector `b` on this shared-memory machine using multiple CPU cores, what is the workflow? `A` is stored in Julia’s sparse matrix format.

---

<div class="post-metadata">

### Author: ![stabbles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stabbles/32/946_2.png) [@stabbles](https://discourse.julialang.org/u/stabbles)
#### Post date: [March 27, 2018, 5:30pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/2 "2018-03-27T17:30:19Z")

</div>

Did `A\b` not work? What kind of matrix is A? How sparse is it? Is it symmetric positive definite? Non-symmetric?

---

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [March 27, 2018, 5:37pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/3 "2018-03-27T17:37:29Z")

</div>

`A\b` works, but how do we make sure it runs on `N` CPU cores?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [March 27, 2018, 5:51pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/4 "2018-03-27T17:51:06Z")

</div>

> [@wsshin](#):
>
> A\b works, but how do we make sure it runs on N CPU cores?

Check `htop`. You’ll see that it’s already multithreaded.

---

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [March 27, 2018, 6:07pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/5 "2018-03-27T18:07:08Z")

</div>

So you mean I don’t need to do something like `julia -np N scriptname.jl` to make `A\b` in `scriptname.jl` use `N` CPU cores?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [March 27, 2018, 6:08pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/6 "2018-03-27T18:08:04Z")

</div>

> [@wsshin](#):
>
> So you mean I don’t need to do something like julia -np N scriptname.jl to make A\b in scriptname.jl use N CPU cores?

In fact, don’t do that. Adding processes sets the number of BLAS threads to 1, which is what you don’t want.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 27, 2018, 6:46pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/7 "2018-03-27T18:46:47Z")

</div>

You can also try out [https://github.com/JuliaSparse/Pardiso.jl/](https://github.com/JuliaSparse/Pardiso.jl/). I’ve gotten significantly higher performance with it than with the solvers coming with julia on high core machines.

---

<div class="post-metadata">

### Author: ![pasha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pasha/32/3319_2.png) [@pasha](https://discourse.julialang.org/u/pasha)
#### Post date: [March 27, 2018, 8:01pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/8 "2018-03-27T20:01:15Z")

</div>

To clarify what is only really implied here, and please correct me if I’m wrong: linear algebra ops are automatically parallel if you have BLAS set up right (run `versioninfo()` and look for `libopenblas`). BLAS operations use a different kind of parallel computing than Julia native parallel as described in [the parallel doc](https://docs.julialang.org/en/stable/manual/parallel-computing)

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 27, 2018, 8:17pm UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/9 "2018-03-27T20:17:59Z")

</div>

Solving a sparse linear system will not use BLAS directly, although it is likely used by the sparse solver.

---

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [March 28, 2018, 1:50am UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/10 "2018-03-28T01:50:31Z")

</div>

@kristoffer.carlsson, I am testing Pardiso.jl, but the performance enhancement with the number of CPU cores is a bit disappointing. The same problem is solved in about 40 seconds with 2 cores, and about 30 seconds with 16 cores. Is this typical, or you think something is wrong?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [March 28, 2018, 2:19am UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/11 "2018-03-28T02:19:16Z")

</div>

> [@wsshin](#):
>
> I am testing Pardiso.jl, but the performance enhancement with the number of CPU cores is a bit disappointing. The same problem is solved in about 40 seconds with 2 cores, and about 30 seconds with 16 cores. Is this typical, or you think something is wrong?

How big is the matrix?

---

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [March 28, 2018, 2:32am UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/12 "2018-03-28T02:32:08Z")

</div>

It is million by million.

Also, do you have an example with `set_solver!(ps, ITERATIVE_SOLVER)`? I am solving a system with slowly evolving matrix, so I would like to perform factorization only once by using `ITERATIVE_SOLVER`, but not sure where to call this. Don’t see a good example in the PARDISO documentation, either.

---

<div class="post-metadata">

### Author: ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)
#### Post date: [July 22, 2021, 1:01am UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/13 "2021-07-22T01:01:48Z")

</div>

So, let’s suppose I am using multiprocessing and solving sparse matrix systems. Do I have to set manually the number of BLAS threads for each process?

---

<div class="post-metadata">

### Author: ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)
#### Post date: [August 21, 2021, 10:25am UTC](https://discourse.julialang.org/t/solving-a-b-in-parallel/10011/14 "2021-08-21T10:25:09Z")

</div>

Did you find a way?  
I also want to use `Pardiso.jl` in the same manner. Factorize once, use many times (For different RHS).

I thought iterative mode means the way the system is solved not use it many times.
