PackageCompiler: Setting the number of threads

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

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,

using PackageCompiler
build_executable("hello.jl")

then I get

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.

1 Like

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

2 Likes

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

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?

2 Likes

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

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

2 Likes