# Overhead of \`Threads.@threads\`

**URL:** <https://discourse.julialang.org/t/overhead-of-threads-threads/53964>\
**Category:** Performance\
**Tags:** question, multithreading\
**Created:** [January 26, 2021, 10:04am UTC](https://discourse.julialang.org/t/overhead-of-threads-threads/53964 "2021-01-26T10:04:27Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [January 26, 2021, 11:01am UTC](https://discourse.julialang.org/t/overhead-of-threads-threads/53964/3 "2021-01-26T11:01:52Z")

</div>

Yes, we do see an overhead. If I remove all `Threads.@threads`, we get the following timings for different numbers of DG elements for one right-hand side evaluation.

```julia
  #Elements | Runtime in seconds
          1 | 1.39e-06
          4 | 1.66e-06
         16 | 2.86e-06
         64 | 7.70e-06
        256 | 2.69e-05
       1024 | 1.04e-04
       4096 | 4.27e-04
      16384 | 1.87e-03
      65536 | 9.75e-03

```

If we use `Threads.@threads` with a single thread as we do now, I get

```julia
#Elements | Runtime in seconds
          1 | 1.86e-05
          4 | 1.87e-05
         16 | 2.03e-05
         64 | 2.68e-05
        256 | 4.62e-05
       1024 | 1.25e-04
       4096 | 4.44e-04
      16384 | 1.93e-03
      65536 | 9.67e-03

```

> [@mauro3](#):
>
> I once did this PR [Make the at-threads a no-op if nthreads()==0 by mauro3 · Pull Request #33964 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/33964), which made `@threads` a no-op if `nthreads()==1` . But apparently that was not save but no work-around was suggested. The road-map PR is linked in that PR of mine.

Thanks for this link!

---

_[View the full topic](https://discourse.julialang.org/t/overhead-of-threads-threads/53964)._
