GroupsWithPropertyT/CPUselect.jl

31 lines
815 B
Julia

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(parsed_args)
if parsed_args["cpus"] == nothing
N = cpuinfo_physicalcores()
else
N = parsed_args["cpus"]
if N > cpuinfo_physicalcores()
warn("Number of specified cores exceeds the physical core count. Performance may suffer.")
end
end
info("Using $N cpus in @parallel code.")
info("Using $(Threads.nthreads()) threads in @threads code.")
addprocs(N)
BLAS.set_num_threads(N)
return N
end