I am trying to set the number of threads (such as 4) in Julia by using the command:
JULIA_NUM_THREADS=4
in CMD in window before launching Julia, which works.
However, I need to set this issue inside “.jl” file by typing the command:
$ JULIA_NUM_THREADS=4 ./julia
at the beginning but it seems not working when I check the threads number by “Threads.threadid()” in the opened REPL.
By the way, I am using VS code to run the “.jl” file.
no, because it’s defined when the Julia process starts, which is before anything inside a .jl file is read. Same reason you can’t change number of threads on the fly
you open up a Julia REPL, Threads.nthreads() shows a number, there’s no way to change this value within the same session (“on the fly”, as this Julia process is running).
yeah just use a bash or powershell steering script, or even a julia script
Create a file that (1- defines the number of threads; 2- and executes some calculations in julia script).
I need to open this file by VScode and run it