# High-dimensional A\\b when running julia -p N

**URL:** https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669
**Category:** Performance
**Created:** [October 20, 2020, 3:23am UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669 "2020-10-20T03:23:34Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)
#### Post date: [October 20, 2020, 3:23am UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669/1 "2020-10-20T03:23:35Z")

</div>

Hi,

I am trying to optimise a function that solves a series of high-dimensional systems (using A\b) in parallel (one per iteration of a for-loop). I am not sure whether it would be a good idea to have more cores than what I need as a buffer for these linear algebra operations (ergo, if they are automatically running in parallel and thus if I need to account for that). Would you please help me out understanding this point? I am open to alternative solutions, but it is crucial for me to solve the systems at the same time.

I am currently using Julia LTS, 16 CPU cores, and 16 GB RAM per core. The A matrix is 1,000 x 1,000 dimensional, while b is 1,000 x K where K \<\< 1000. I was wondering whether it would be a good idea to increase the number of CPU cores and keep the total RAM as it is.

Thank you.

---

<div class="post-metadata">

### Author: ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)
#### Post date: [October 20, 2020, 6:57am UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669/2 "2020-10-20T06:57:31Z")

</div>

There are 2 parallel capabilities: threads and processes and you chose multiprocessing. For this, if you use `SharedArray`s you should get parallel computations if implemented internally. For threads, regular `Array`s are enough and the undelying library (openblas+lapack?) should already use multi threads. For large systems with sparse `A`, `b`, you could use `SparseArrays`.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [October 20, 2020, 7:35am UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669/3 "2020-10-20T07:35:05Z")

</div>

I guess on LTS threads aren’t really an option? Any reason why you’re using LTS, @fipelle? It’s quite out of date now and you’re missing out on loads of great improvements to the language!

---

<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: [October 20, 2020, 12:25pm UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669/4 "2020-10-20T12:25:28Z")

</div>

Note that Julia 1.6 will probably be the next LTS, and it will be out within a few months. One solution would be to just wait until the LTS version does this automatically.

---

<div class="post-metadata">

### Author: ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)
#### Post date: [October 20, 2020, 3:55pm UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669/5 "2020-10-20T15:55:07Z")

</div>

Thank you all!

@tomaklutfu: `A` has quite a lot of zeros, so I suppose that I could consider it a `SparseArrays`. Do I need to have a sparse `b` as well to see the benefits?

@nilshg: Frankly, I had to dedicate less time to Julia in the last semester due to Covid-19 related issues. In fact, [TSAnalysis.jl](https://github.com/fipelle/TSAnalysis.jl) is still waiting for an major update (I am writing a theoretical paper that could have an impact on it and I am finishing that first). The only software I managed to release is a [replication code](https://github.com/fipelle/replication-hasenzagl-et-al-2020) for a paper I co-authored that has just been accepted for publication at the Review of Economics and Statistics (not a proper package, but an interesting empirical application / technique).

@Oscar_Smith: I am not sure I understand. Is Julia 1.6 going to have automated multithreading for linear algebra operations?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [October 21, 2020, 6:19am UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669/6 "2020-10-21T06:19:45Z")

</div>

Congrats on the ReStat!

On the multithreading: in many cases, linear algebra is already multithreaded, as it calls out to underlying BLAS (or MKL when using MKL.jl) routines. Julia 1.3 introduced composable multithreaded parallelism (announcement [here](https://julialang.org/blog/2019/07/multithreading/), docs [here](https://docs.julialang.org/en/v1/manual/multi-threading/)), introducing the `@threads` macro that can be prefixed to for loops.

While multithreading has continued to improve since 1.3 and is likely going to continue improving, it is unlikely that there will be “automated” parallelism (other than what underlying libraries like BLAS do)

---

<div class="post-metadata">

### Author: ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)
#### Post date: [October 21, 2020, 12:38pm UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669/7 "2020-10-21T12:38:51Z")

</div>

Thank you! Do you also know if there exists a good performance comparison between classical Julia multitasking, multithreading and a combination of the two?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [October 21, 2020, 1:10pm UTC](https://discourse.julialang.org/t/high-dimensional-a-b-when-running-julia-p-n/48669/8 "2020-10-21T13:10:03Z")

</div>

Not aware of a definite comparison unfortunately, there’s a thread here: [The ultimate guide to distributed computing](https://discourse.julialang.org/t/the-ultimate-guide-to-distributed-computing/41867) which discusses options in some detail, and there are some good answers from Bogumil and Przemyslaw on StackOverflow that might be helpful.
