# Multithreading for nested loops

**URL:** <https://discourse.julialang.org/t/multithreading-for-nested-loops/36002>\
**Category:** Performance\
**Tags:** multithreading\
**Created:** [March 15, 2020, 5:31am UTC](https://discourse.julialang.org/t/multithreading-for-nested-loops/36002 "2020-03-15T05:31:15Z")\
**Posts on this page:** 1\
**Showing post:** 38

<div class="post-metadata">

**Author:** ![henry2004y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henry2004y/32/9284_2.png) [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Post date:** [June 27, 2021, 12:25pm UTC](https://discourse.julialang.org/t/multithreading-for-nested-loops/36002/38 "2021-06-27T12:25:11Z")

</div>

Thanks! In my first attempt with Tullio, I did not import LoopVectorization. In fact, if we use `avx` macro for this micro example, without any threading we can immediately get 4x speedup. However, that is not what I want to test initially (and probably not a fair comparison?). `avx` looks like the `simd` clause in OpenMP, if I interpret it correctly.

Now with 2 threads and no `avx`, using Tullio gives me 1.5x speed up compared with base case, but `@threads on the outer loop` is slightly faster than that:

```julia
Number of threads = 2
base line:
  158.373 ms (2 allocations: 61.04 MiB)
@threads on the outer loop:
  99.353 ms (14 allocations: 61.04 MiB)
@tullio on the nested loops:
  109.440 ms (18 allocations: 61.04 MiB)
@tullio avx on the nested loops:
  34.556 ms (17 allocations: 61.04 MiB)

```

---

_[View the full topic](https://discourse.julialang.org/t/multithreading-for-nested-loops/36002)._
