Obtain the number of CPU cores in Julia
In recent versions of Julia, you can use Sys.CPU_CORES
(and not Base.CPU_CORES
as some answers mentioned). Tested on 0.6.
Sys.CPU_CORES
is not defined in Julia v1.1.0. However, the following does the job.
length(Sys.cpu_info())
I'm not 100% certain about this, but CPU_CORES
returns the number of (hyper-threading) cores on my machine (OSX 10.9.5 and Julia 0.3.5), even when I start Julia in serial mode. I've been checking the number of available cores using nworkers()
and nprocs()
. Starting up Julia without the -p
flag this returns 1 for both.
When I start julia as julia -p 4
julia> nprocs()
5
julia> nworkers()
4
In both cases CPU_CORES
returns 8.