June 2019
Intermediate to advanced
218 pages
5h 19m
English
The number of real threads that Julia can run is fixed at startup. It depends on the JULIA_NUM_THREADS environmental variable and is checked when the Julia runtime starts up. If the variable is not set, the default number of threads is 1:
$ export JULIA_NUM_THREADS = 4
Once Julia is started, you can check the number of threads using the nthreads function. This and other threading functionalities are located in the Base.Threads module, which we need to import into the following listing:
julia> using Base.Threadsjulia> nthreads()4
The threadid function returns the current thread ID as follows:
julia> threadid()1
So, by default, all Julia code is running on the first thread. We can see this in the following code, where the first ...
Read now
Unlock full access