# Nested parallelization in Julia?

**URL:** https://discourse.julialang.org/t/nested-parallelization-in-julia/30568
**Category:** General Usage
**Created:** [November 1, 2019, 12:13am UTC](https://discourse.julialang.org/t/nested-parallelization-in-julia/30568 "2019-11-01T00:13:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)
#### Post date: [November 1, 2019, 12:13am UTC](https://discourse.julialang.org/t/nested-parallelization-in-julia/30568/1 "2019-11-01T00:13:17Z")

</div>

Hello,

I was curious to know if there has been some thought regarding nested parallelization in julia. For example, a typical parallelizable routine with a for loop inside may look like

```julia
function my_parallel_function()
 @distributed () for i in 1:I
  #do something 
   for j in 1:J 
    #do something else
   end
 end
end

```

In cases where both | I | and |J| are large it may be useful to parallelize the inner loop within the already parallelized outer-loop. I have written parallelized code over a collection of iterators but I am wondering if this was somewhere in the works too.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [November 1, 2019, 6:22am UTC](https://discourse.julialang.org/t/nested-parallelization-in-julia/30568/2 "2019-11-01T06:22:52Z")

</div>

in `1.3`, you can nest `Threads.@threads` which can help here.

---

<div class="post-metadata">

### Author: ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)
#### Post date: [November 1, 2019, 6:25am UTC](https://discourse.julialang.org/t/nested-parallelization-in-julia/30568/3 "2019-11-01T06:25:21Z")

</div>

nice, that’s pretty cool. We only have 1.3.0-rc4 now though, but not the stable version yet – is that right?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [November 1, 2019, 6:28am UTC](https://discourse.julialang.org/t/nested-parallelization-in-julia/30568/4 "2019-11-01T06:28:19Z")

</div>

that’s correct, you can try it now (I think rc4 is really close to release, which should happen within the year), if you don’t have mission-critical stability requirement.

---

<div class="post-metadata">

### Author: ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)
#### Post date: [November 1, 2019, 6:30am UTC](https://discourse.julialang.org/t/nested-parallelization-in-julia/30568/5 "2019-11-01T06:30:21Z")

</div>

Yes, will do and I also just dug up this link ([Announcing composable multi-threaded parallelism in Julia](https://julialang.org/blog/2019/07/multithreading)) which is useful and gives examples for what you mentioned in your first comment. Posting the link here in case some may have missed this blog post.
