# Parallel programming capabilities in Julia

**URL:** https://discourse.julialang.org/t/parallel-programming-capabilities-in-julia/44394
**Category:** New to Julia
**Created:** [August 6, 2020, 7:34am UTC](https://discourse.julialang.org/t/parallel-programming-capabilities-in-julia/44394 "2020-08-06T07:34:35Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)
#### Post date: [August 6, 2020, 7:38pm UTC](https://discourse.julialang.org/t/parallel-programming-capabilities-in-julia/44394/5 "2020-08-06T19:38:37Z")

</div>

I havn’t really looked into multithreading yet, but I do make use of `Distributed` quite a bit. My workflow usually goes like the following. Suppose you have the following computationally expensive function:

```julia
function work()
    # a function that does a lot of work (i.e. is computationally expensive)
end

```

I next `addprocs(n) # add n workers`, this launches n workers, i.e. julia processes with the `--worker` flag. Then I mainly use the `pmap` function to run parallel computations, so something like

```julia
results = pmap(1:10) do i 
    w = work(i)
    p = process(w) # will run on the worker process!
end

```

You have to be careful here. If you have `n` workers all running `work()`, you have to make sure there is sufficient memory on your system (and remember all the results from `work()` are returned to the variable `results` so you must ensure there is memory left for this collection also.

Another caveat is that `pmap` is only really useful when `work()` is computationally expensive to offset the overhead. If the work function is simple and fast, it’s better to use multithreading.

---

_[View the full topic](https://discourse.julialang.org/t/parallel-programming-capabilities-in-julia/44394)._
