move cpu/multithreading selection to CPUselect.jl

This commit is contained in:
kalmarek 2017-11-06 14:24:50 +01:00
parent d7c8b45090
commit 2dd747a748
3 changed files with 36 additions and 43 deletions

View File

@ -41,29 +41,11 @@ end
parsed_args = parse_commandline() parsed_args = parse_commandline()
function cpuinfo_physicalcores() include("CPUselect.jl")
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
if parsed_args["cpus"] == nothing set_parallel_mthread(parsed_args)
N = cpuinfo_physicalcores()
parsed_args["cpus"] = N
info("Setting --cpus to $N")
elseif parsed_args["cpus"] > cpuinfo_physicalcores()
warn("Number of specified cores exceeds the physical core count. Performance may suffer.")
end
addprocs(parsed_args["cpus"])
BLAS.set_num_threads(parsed_args["cpus"])
include("SAutFNs.jl") include("SAutFNs.jl")
include("Orbit.jl") include("Orbit.jl")
main(SAutFNs, parsed_args) main(SAutFNs, parsed_args)

30
CPUselect.jl Normal file
View File

@ -0,0 +1,30 @@
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()) in @threads code.")
addprocs(N)
BLAS.set_num_threads(N)
return N
end

View File

@ -48,30 +48,11 @@ end
parsed_args = parse_commandline() parsed_args = parse_commandline()
function cpuinfo_physicalcores() include("CPUselect.jl")
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
if parsed_args["cpus"] == nothing set_parallel_mthread(parsed_args)
N = cpuinfo_physicalcores()
parsed_args["cpus"] = N
info("Setting --cpus to $N")
elseif parsed_args["cpus"] > cpuinfo_physicalcores()
warn("Number of specified cores exceeds the physical core count. Performance will suffer.")
end
end
addprocs(parsed_args["cpus"])
BLAS.set_num_threads(parsed_args["cpus"])
include("SLNs.jl") include("SLNs.jl")
include("Orbit.jl") include("Orbit.jl")
main(SLNs, parsed_args) main(SLNs, parsed_args)