33 lines
898 B
Julia
33 lines
898 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; workers=false)
|
|
|
|
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
|
|
|
|
if workers
|
|
addprocs(N)
|
|
info("Using $N cpus in @parallel code.")
|
|
end
|
|
info("Using $(Threads.nthreads()) threads in @threads code.")
|
|
BLAS.set_num_threads(N)
|
|
info("Using $N threads in BLAS.")
|
|
|
|
return N
|
|
end
|