# Limit number of threads in julia -t auto

**URL:** <https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099>\
**Category:** General Usage\
**Tags:** question, multithreading\
**Created:** [September 4, 2025, 1:36pm UTC](https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099 "2025-09-04T13:36:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 4, 2025, 1:36pm UTC](https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099/1 "2025-09-04T13:36:08Z")

</div>

Is there a way to start a (non-interactive) Julia process that automatically determines the sensible automatic number for theads _but_ if that is higher than some threshold, limits it to the latter?

Eg on a laptop with 8 cores I would want to use 8 (which I get with `julia -t auto`), but on a server with 100+ cores I am sharing with others I would want to max out at, say, 24 to be a good citizen, and I want to use the same scripts on both without too much hassle.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 4, 2025, 2:07pm UTC](https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099/2 "2025-09-04T14:07:31Z")

</div>

if you use `-t auto` and OhMyThreads.jl, you can use `@set ntasks = min(nthreads(), 24)` or something

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [September 4, 2025, 2:16pm UTC](https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099/3 "2025-09-04T14:16:20Z")

</div>

I would probably do a shell alias here rather than language-level solution

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [September 4, 2025, 2:21pm UTC](https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099/4 "2025-09-04T14:21:27Z")

</div>

Or alternatively,

```bash
echo "export JULIA_NUM_THREADS=24" >> ~/.bashrc

```

on the server.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 4, 2025, 3:45pm UTC](https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099/5 "2025-09-04T15:45:11Z")

</div>

Yes, that makes sense. I went with

```sh
julia -t `julia -t auto --startup-file=no -e 'print(min(Threads.nthreads(),24))'`

```

which _does_ involve the shell (for the ``) but it is portable and requires no Bash magic.¹

¹Anything beyond `VAR=stuff ... $VAR` is magic.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [September 4, 2025, 3:49pm UTC](https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099/6 "2025-09-04T15:49:08Z")

</div>

> [@Tamas\_Papp](#):
>
> ```julia-auto
> julia -t `julia --startup-file=no -e 'print(min(Threads.nthreads(),24))'`
> 
> ```

Shouldn’t that be:

```julia-auto
julia -t `julia -t auto --startup-file=no -e 'print(min(Threads.nthreads(),24))'`

```

?

Otherwise the “inner” julia will always have only one thread, no?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 4, 2025, 3:51pm UTC](https://discourse.julialang.org/t/limit-number-of-threads-in-julia-t-auto/132099/7 "2025-09-04T15:51:23Z")

</div>

thanks, I edited it
