# PackageCompiler: Setting the number of threads

**URL:** <https://discourse.julialang.org/t/packagecompiler-setting-the-number-of-threads/31611>\
**Category:** New to Julia\
**Created:** [November 28, 2019, 8:33am UTC](https://discourse.julialang.org/t/packagecompiler-setting-the-number-of-threads/31611 "2019-11-28T08:33:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![scj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scj/32/20488_2.png) [@scj](https://discourse.julialang.org/u/scj)\
**Post date:** [November 28, 2019, 8:33am UTC](https://discourse.julialang.org/t/packagecompiler-setting-the-number-of-threads/31611/1 "2019-11-28T08:33:35Z")

</div>

Is it possible to set the number of Julia threads when building an executable using PackageCompiler?

```julia
module Hello
Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
    println(Threads.nthreads())
    return 0
end
end

```

If I compile the above code using PackageCompiler,

```julia
using PackageCompiler
build_executable("hello.jl")

```

then I get

```julia
hello.exe
1

```

Does this mean, as is suggested, that only a single thread is available to the program? I’ve tried using the `cc_flags` option, but I’ve had no luck.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 28, 2019, 8:40am UTC](https://discourse.julialang.org/t/packagecompiler-setting-the-number-of-threads/31611/2 "2019-11-28T08:40:07Z")

</div>

How about setting the environment variable `JULIA_NUM_THREADS=4` before starting the executable?

---

<div class="post-metadata">

**Author:** ![scj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scj/32/20488_2.png) [@scj](https://discourse.julialang.org/u/scj)\
**Post date:** [November 28, 2019, 9:06am UTC](https://discourse.julialang.org/t/packagecompiler-setting-the-number-of-threads/31611/3 "2019-11-28T09:06:54Z")

</div>

Wow, yeah, that works. Thank you, can’t believe I didn’t think of it.

---

<div class="post-metadata">

**Author:** ![adriangb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adriangb/32/20438_2.png) [@adriangb](https://discourse.julialang.org/u/adriangb)\
**Post date:** [December 21, 2020, 6:11pm UTC](https://discourse.julialang.org/t/packagecompiler-setting-the-number-of-threads/31611/4 "2020-12-21T18:11:11Z")

</div>

I’m using PacakgeCompiler to make a relocatable app that I can share to users who don’t know what an environment variable is. I can’t ask them to do `export JULIA_NUM_THREADS=...` before running the executable. I realize I can probably make an executable that calls the executable but… is there a better way?

---

<div class="post-metadata">

**Author:** ![djholiver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djholiver/32/50470_2.png) [@djholiver](https://discourse.julialang.org/u/djholiver)\
**Post date:** [April 22, 2021, 8:27pm UTC](https://discourse.julialang.org/t/packagecompiler-setting-the-number-of-threads/31611/5 "2021-04-22T20:27:28Z")

</div>

Hi @kristoffer.carlsson ,

I had the same question as Adrian - is this possible to set the number of threads in the code that is then packaged(compiled) into a relocatable app?

Regards

---

<div class="post-metadata">

**Author:** ![Alessio\_Bellisomi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alessio_bellisomi/32/12525_2.png) [@Alessio\_Bellisomi](https://discourse.julialang.org/u/Alessio_Bellisomi)\
**Post date:** [November 23, 2021, 3:14pm UTC](https://discourse.julialang.org/t/packagecompiler-setting-the-number-of-threads/31611/6 "2021-11-23T15:14:29Z")

</div>

now it is possible to define the number of threads needed by the compiled app with the argument  
`--julia-args`  
e.g.

`app.exe --julia-args --threads=4`
