Number of processors
-
Hi,
Is there a way to get number of processors with Ruby in Sketchup.
I've found on internet solutions like thisrequire 'win32ole' wmi = WIN32OLE.connect("winmgmts;//") num = wmi.ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors
problem is when I run this in Sketchup I get error
- unknown property or method `NumberOfProcessors' HRESULT error code;0x80020006 Unknown name. Error; #<WIN32OLERuntimeError; unknown property or method `NumberOfProcessors' HRESULT error code;0x80020006 Unknown name.>
I'm using win32ole posted here: [Plugin Library] Win32API and Win32OLE so files
-
Is this any help?
# Returns the number of processor for Linux, OS X or Windows. def number_of_processors 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
-
On Windows, an environment var is set for the number of processors:
num = ENV['NUMBER_OF_PROCESSORS'].to_i
-
num = ENV['NUMBER_OF_PROCESSORS'].to_i
is much easier than the other way and should be fine unless you want to have a cross-platform solution... We don't know if MAC has the same ENV variable 0 - some references are similar to PC, while others can be the same ??
Advertisement