Module: Kernel
- Defined in:
- lib/parallelpipes.rb
Instance Method Summary collapse
-
#number_of_processors_for_parallel_map ⇒ Object
Returns the number of processor for Linux, OS X or Windows.
Instance Method Details
#number_of_processors_for_parallel_map ⇒ Object
Returns the number of processor for Linux, OS X or Windows.
2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 |
# File 'lib/parallelpipes.rb', line 2337 def number_of_processors_for_parallel_map if RUBY_PLATFORM =~ /linux/ return `cat /proc/cpuinfo | grep processor | wc -l`.to_i elsif RUBY_PLATFORM =~ /darwin/ return `sysctl -n hw.logicalcpu`.to_i elsif RUBY_PLATFORM =~ /win32/ # this works for windows 2000 or greater require 'win32ole' wmi = WIN32OLE.connect("winmgmts://") wmi.ExecQuery("select * from Win32_ComputerSystem").each do |system| begin processors = system.NumberOfLogicalProcessors rescue processors = 0 end return [system.NumberOfProcessors, processors].max end end raise "can't determine 'number_of_processors' for '#{RUBY_PLATFORM}'" end |