# How to query the current maximum number of threads?

**URL:** <https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342>\
**Category:** Julia at Scale\
**Tags:** question, performance\
**Created:** [August 11, 2017, 11:18pm UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342 "2017-08-11T23:18:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 11, 2017, 11:18pm UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/1 "2017-08-11T23:18:26Z")

</div>

I have just found [JULIA\_NUM\_THREADS](https://docs.julialang.org/en/stable/manual/environment-variables/#JULIA_NUM_THREADS-1) in the documentation, and I wonder if Julia is already doing a good job on picking up the number of CPU cores on my laptop. Is there a command to find the number of threads available?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 12, 2017, 1:27am UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/2 "2017-08-12T01:27:31Z")

</div>

`Threads.nthreads()`. It doesn’t add threads by default, but Juno does.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 12, 2017, 1:56am UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/3 "2017-08-12T01:56:53Z")

</div>

I tried setting the variable `JULIA_NUM_THREADS` on my `.juliarc.jl` file but it doesn’t affect `Threads.nthreads()`. Is it already implemented?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 12, 2017, 2:03am UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/4 "2017-08-12T02:03:05Z")

</div>

> [@juliohm](#):
>
> I tried setting the variable JULIA\_NUM\_THREADS on my .juliarc.jl file

That won’t work.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 12, 2017, 2:03am UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/5 "2017-08-12T02:03:22Z")

</div>

`JULIA_NUM_THREADS` is supposed to be an environment variable set before Julia is opened.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 12, 2017, 2:06am UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/6 "2017-08-12T02:06:47Z")

</div>

Thank you all, I have the variable set on my `.bashrc`, and it works now. Though I think this should be widely spread to other Julians, I’d have set this variable a long time ago.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 12, 2017, 2:13am UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/7 "2017-08-12T02:13:44Z")

</div>

> [@juliohm](#):
>
> Though I think this should be widely spread to other Julians

No please don’t. It is highly experimental.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 12, 2017, 2:20am UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/8 "2017-08-12T02:20:07Z")

</div>

> [@yuyichao](#):
>
> No please don’t. It is highly experimental.

What is not highly experimental in Julia? 🙂

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 12, 2017, 2:31am UTC](https://discourse.julialang.org/t/how-to-query-the-current-maximum-number-of-threads/5342/9 "2017-08-12T02:31:48Z")

</div>

Well, there are the kind of code that is expected to work and there are features that aren’t.
