2017-11-06 14:24:50 +01:00
|
|
|
function cpuinfo_physicalcores()
|
|
|
|
maxcore = -1
|
|
|
|
for line in eachline("/proc/cpuinfo")
|
|
|
|
if startswith(line, "core id")
|
|
|
|
maxcore = max(maxcore, parse(Int, split(line, ':')[2]))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
maxcore < 0 && error("failure to read core ids from /proc/cpuinfo")
|
|
|
|
return maxcore + 1
|
|
|
|
end
|
|
|
|
|
2018-08-08 00:16:05 +02:00
|
|
|
function set_parallel_mthread(N::Int, workers::Bool)
|
|
|
|
if N > cpuinfo_physicalcores()
|
|
|
|
warn("Number of specified cores exceeds the physical core count. Performance may suffer.")
|
2017-11-06 14:24:50 +01:00
|
|
|
end
|
|
|
|
|
2017-12-21 13:01:38 +01:00
|
|
|
if workers
|
|
|
|
addprocs(N)
|
|
|
|
info("Using $N cpus in @parallel code.")
|
|
|
|
end
|
2017-11-06 14:49:59 +01:00
|
|
|
info("Using $(Threads.nthreads()) threads in @threads code.")
|
2017-11-06 14:24:50 +01:00
|
|
|
BLAS.set_num_threads(N)
|
2017-12-21 13:01:38 +01:00
|
|
|
info("Using $N threads in BLAS.")
|
2017-11-06 14:24:50 +01:00
|
|
|
|
2018-08-08 00:16:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function set_parallel_mthread(parsed_args::Dict; workers=false)
|
|
|
|
if parsed_args["cpus"] == nothing
|
|
|
|
N = cpuinfo_physicalcores()
|
|
|
|
else
|
|
|
|
N = parsed_args["cpus"]
|
|
|
|
end
|
|
|
|
|
|
|
|
set_parallel_mthread(N, workers)
|
2017-11-06 14:24:50 +01:00
|
|
|
end
|