GroupsWithPropertyT/CPUselect.jl

36 lines
974 B
Julia
Raw Normal View History

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
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.")
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.")
BLAS.set_num_threads(N)
2017-12-21 13:01:38 +01:00
info("Using $N threads in BLAS.")
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)
end