Multithreading in Julia
In this recipe, we use Julia's multithreading mechanism to speed up computations of statistics over a largeDataFrame
.
Getting ready
For this recipe, you need to use theDataFrames.jl
andBenchmarkTools.jl
packages, which can be installed with the Julia package manager. If you need to add them then in the Julia command line, press the] key and run these commands:
(v1.0) pkg> add DataFrames (v1.0) pkg> add BenchmarkTools
This will install theDataFrames.jl
andBenchmarkTools.jl
packages and all their dependencies.
In this recipe, we use Julia's threading mechanism. The number of threads is controlled via theJULIA_NUM_THREADS
system variable, which needs to be assigned before starting thejulia
process. In order to set the variable, start a new command-line console and execute this command (Windows version):
C:\ set JULIA_NUM_THREADS=4
In a Linux console, run this:
$ export JULIA_NUM_THREADS=4
Now, start Julia:
$julia
You can check whether the number of threads has been properly allocated...