move cpu/multithreading selection to CPUselect.jl
This commit is contained in:
parent
d7c8b45090
commit
2dd747a748
@ -41,29 +41,11 @@ end
|
||||
|
||||
parsed_args = parse_commandline()
|
||||
|
||||
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
|
||||
include("CPUselect.jl")
|
||||
|
||||
if parsed_args["cpus"] == nothing
|
||||
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"])
|
||||
set_parallel_mthread(parsed_args)
|
||||
|
||||
include("SAutFNs.jl")
|
||||
|
||||
include("Orbit.jl")
|
||||
|
||||
main(SAutFNs, parsed_args)
|
||||
|
30
CPUselect.jl
Normal file
30
CPUselect.jl
Normal 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
|
25
SL_orbit.jl
25
SL_orbit.jl
@ -48,30 +48,11 @@ end
|
||||
|
||||
parsed_args = parse_commandline()
|
||||
|
||||
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
|
||||
include("CPUselect.jl")
|
||||
|
||||
if parsed_args["cpus"] == nothing
|
||||
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"])
|
||||
set_parallel_mthread(parsed_args)
|
||||
|
||||
include("SLNs.jl")
|
||||
|
||||
include("Orbit.jl")
|
||||
|
||||
main(SLNs, parsed_args)
|
||||
|
Loading…
Reference in New Issue
Block a user