# Does Julia detect the maximum number of threads availible and if so how?

**URL:** <https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683>\
**Category:** Performance\
**Tags:** threads\
**Created:** [November 17, 2021, 8:33pm UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683 "2021-11-17T20:33:01Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [November 18, 2021, 7:54pm UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/21 "2021-11-18T19:54:51Z")

</div>

> [@carstenbauer](#):
>
> `Threads.nthreads()`

I don’t know how to check if hyperthreading is disabled but here’s the results

```julia
dave@deepthought:~$ julia -t auto
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.6.3 (2021-09-23)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using Hwloc

julia> num_physical_cores()
36

julia> num_virtual_cores()
36

julia> Threads.nthreads()
36

julia> 

```

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [November 18, 2021, 7:57pm UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/22 "2021-11-18T19:57:39Z")

</div>

hyperthreading IS disabled GREAT SPOT!!! I’ll get that sorted out next reboot!

```julia
dave@deepthought:~$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 36
On-line CPU(s) list: 0-35
Thread(s) per core: 1
Core(s) per socket: 18
Socket(s): 2
NUMA node(s): 2

```

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [November 18, 2021, 7:59pm UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/23 "2021-11-18T19:59:02Z")

</div>

Well, as you can see, the system reports only 36 available threads. Hence, the reason why you get 36 for `julia -t auto` isn’t related to Julia at all but lies deeper. Again, my simple guess would be that hyperthreading is disabled (which would give you precisely the output that you see). Don’t know how to check that from the top of my head but should be easy to find out. You should be able to activate this in the BIOS I guess.

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [November 18, 2021, 8:01pm UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/24 "2021-11-18T20:01:06Z")

</div>

OUTSTANDING WORK!  
thanks so much for clearing this up.

Here’s how I found out how to check hyperthreading

[how to check intel hyperthreading](https://www.xmodulo.com/check-hyper-threading-enabled-linux.html)

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [November 18, 2021, 8:02pm UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/25 "2021-11-18T20:02:39Z")

</div>

Maybe as a final comment, I’m not a fan of hyperthreading so I wouldn’t mind if it was turned off 🙂

(In fact, on some of our clusters it is indeed turned off as more often than not it is not what users want, whether they know it or not 🙂 )

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [November 18, 2021, 8:07pm UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/26 "2021-11-18T20:07:25Z")

</div>

thanks for your help @carstenbauer My use case would benefit from threads as I intend to implement a group of finite state machines. I’m HOPING that Julia is thread safe, I’ll soon find out 🙂

---

<div class="post-metadata">

**Author:** ![anon28281882](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon28281882](https://discourse.julialang.org/u/anon28281882)\
**Post date:** [November 19, 2021, 12:53am UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/27 "2021-11-19T00:53:45Z")

</div>

> [@DNF](#):
>
> My understanding is that `julia -t auto` will always give you one thread per physical core, so this behavior is expected, and not a failure of the detection scheme.

Hi @DNF, my understanding was that it is one thread per logical core. Just checked and it looks so. Pls see below. Also it seems that the same situation is in case of @anon69491625 setup.

```julia
~$ julia -t auto
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.7.0-rc2 (2021-10-20)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> Threads.nthreads()
128

shell> lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 52 bits physical, 57 bits virtual
CPU(s): 128
On-line CPU(s) list: 0-127
Thread(s) per core: 2
Core(s) per socket: 32
Socket(s): 2 
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 106
Model name: Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz

```

---

<div class="post-metadata">

**Author:** ![anon28281882](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon28281882](https://discourse.julialang.org/u/anon28281882)\
**Post date:** [November 19, 2021, 12:56am UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/28 "2021-11-19T00:56:15Z")

</div>

> [@carstenbauer](#):
>
> Maybe as a final comment, I’m not a fan of hyperthreading so I wouldn’t mind if it was turned off 🙂

Is there maybe any general rule of thumb? My current assumption is that if there is more intense computation (like computations with higher memory consumption) it is better to use HT and it should bring better results even then `JULIA_EXCLUSIVE=1 julia -t (n of physical cores)`. However, I have not done any extensive testing on this topic.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [November 19, 2021, 11:49am UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/29 "2021-11-19T11:49:09Z")

</div>

> [@anon28281882](#):
>
> my understanding was that it is one thread per logical core.

Yes, I see that too, now. I was so certain, I even remember reading why this was so. And my memory completely played a trick on me…

---

<div class="post-metadata">

**Author:** ![anon28281882](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon28281882](https://discourse.julialang.org/u/anon28281882)\
**Post date:** [November 19, 2021, 6:27pm UTC](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683/30 "2021-11-19T18:27:50Z")

</div>

Yeah, thanks for pointing out to this. I have to admit that I always was starting Julia specifying desired number of threads. So it was a new experiment for me even though my understanding was that Julia auto policy is to set number of threads as equal to number of logical cores (if present), the same with OpenBlas for Julia v. 1.8.

[Previous page](https://discourse.julialang.org/t/does-julia-detect-the-maximum-number-of-threads-availible-and-if-so-how/71683.md?page=1)
