# Documentation for parallel computing - clarification

**URL:** https://discourse.julialang.org/t/documentation-for-parallel-computing-clarification/30057
**Category:** Performance
**Tags:** documentation
**Created:** [October 18, 2019, 4:15pm UTC](https://discourse.julialang.org/t/documentation-for-parallel-computing-clarification/30057 "2019-10-18T16:15:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [October 18, 2019, 4:15pm UTC](https://discourse.julialang.org/t/documentation-for-parallel-computing-clarification/30057/1 "2019-10-18T16:15:48Z")

</div>

Two bits of clarification. Are these two statements correct?

1. All parallel functions require that the user has started worker processes separately with addprocs().

2. You need to add at least 2 worker processes to see benefits of parallelization because the main process does not act as a worker itself.

If so, I intend to edit the docs to better convey these views.

---

<div class="post-metadata">

### Author: ![swishmas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swishmas/32/8803_2.png) [@swishmas](https://discourse.julialang.org/u/swishmas)
#### Post date: [October 18, 2019, 11:14pm UTC](https://discourse.julialang.org/t/documentation-for-parallel-computing-clarification/30057/2 "2019-10-18T23:14:36Z")

</div>

Hi TurboNick,

I think I can help. Can you tell me what type of parallelization you’re looking to use? There are several right now in the language (@threads, @spawn, etc.).

In general, there are two ways to start more than one parallel thread that come to mind immediately (please, someone add to this list if I miss something). One can start the julia REPL with `julia -p 4` for four processes (or however many you want). Alternatively, you can set an environment variable in your terminal prompt, .bash\_profile, .zshrc, etc. if you want to always invoke this as `export JULIA_NUM_THREADS=4` or whatever number of threads you want.

If you then set the number of processes, you should see parallelization if everything goes well. If you can be more specific about what you’re seeing and what you’re looking to parallelize, then more can be said.

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [October 18, 2019, 11:41pm UTC](https://discourse.julialang.org/t/documentation-for-parallel-computing-clarification/30057/3 "2019-10-18T23:41:21Z")

</div>

Thanks @swishmas. I’m exploring several variants for their impact and basing it on an already-running julia process because I think that’d be easier for anyone using my code.

So at the moment I’m looking at `pmap` and `@distributed for`. Multithreading instead of multiple processors might be more natural, but I gather that’s still being tested?

Do you know whether the two statements in my first post are true?

That is, distributed/pmap with 2 processes (1 worker) would of course allow you to do other things on the main process while your code is running on the single worker, but would not itself be in parallel. So you need 3 processes (2 workers) to execute in parallel?

---

<div class="post-metadata">

### Author: ![swishmas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swishmas/32/8803_2.png) [@swishmas](https://discourse.julialang.org/u/swishmas)
#### Post date: [October 22, 2019, 4:43pm UTC](https://discourse.julialang.org/t/documentation-for-parallel-computing-clarification/30057/4 "2019-10-22T16:43:07Z")

</div>

Sorry for the slow reply. Hopefully this is still useful.

As I understand it, if you designate 4 threads, then the “master thread” is included in that total. When I parallelize over 4 threads, 4 threads are used on my machine.

I’m less familiar with `@distributed`, but I can comment on `pmap` and `@threads`. For `pmap`, the only trick is to initialize julia with `julia -p 4` and this gives parallelization over 4 threads. For `Threads.@threads`, I start with the environment variable I listed above. Again, `=4` means I get 4 threads that are parallelized over.

As I understand the current status, the parallelization is still in testing. There’s a new `@sync` system in v1.3 (and an earlier version or two), but the problem is that the new parallelization system can be slower since it is not optimized in terms of allocations. So, a code written in v1.1.1 will be faster than v1.2/1.3 (I found a x2 slow-down between those versions). This is supposed to be fixed, but it’s not known when that will be completed.

As for your last paragraph, I suppose the way I would think about it is whatever happened on that third process should be counted as a third process to be initialized in parallel with whatever is running on the other two threads. So, I would write the function with something like `for i = 1:3` and then have an `if` statement saying that the `i=3` case gets the sequential, independent commands of the other two threads. That would be where I start, but you might find something more efficient as you get more feedback and develop more code.

Good luck!
