# How can I arrange to only use @threads if the number of iteration is higher than minimum?

**URL:** <https://discourse.julialang.org/t/how-can-i-arrange-to-only-use-threads-if-the-number-of-iteration-is-higher-than-minimum/68177>\
**Category:** Performance\
**Tags:** multithreading\
**Created:** [September 14, 2021, 10:34pm UTC](https://discourse.julialang.org/t/how-can-i-arrange-to-only-use-threads-if-the-number-of-iteration-is-higher-than-minimum/68177 "2021-09-14T22:34:59Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [September 16, 2021, 3:04pm UTC](https://discourse.julialang.org/t/how-can-i-arrange-to-only-use-threads-if-the-number-of-iteration-is-higher-than-minimum/68177/3 "2021-09-16T15:04:04Z")

</div>

It’s a bit old, but perhaps still useful:

> [@Conditional Multithreading](https://discourse.julialang.org/t/conditional-multithreading/32421):
>
> Is there a way to enable/disable calls to Threads.@threads? I’m developing an optimization solver, and when the problem is sufficiently small, using multi-threading hurts performance, and incurs allocations (my code doesn’t make any allocations until I wrap it in @threads). However, when the problem size grows and the individual operations being threaded become more computationally intensive (booting the arithmetic intensity) I get some good performance increases. I’d like to be able to enable…

---

_[View the full topic](https://discourse.julialang.org/t/how-can-i-arrange-to-only-use-threads-if-the-number-of-iteration-is-higher-than-minimum/68177)._
