Does anyone know of a way to query the number of physical cores from MATLAB? I would specifically like to get the number of physical rather than logical cores (which can differ when hyperthreading is enabled).
I need the method to be cross-platform (Windows and Linux, don't care about Mac), but I'd be happy to use two separate methods with a switch
statement based on the output of computer
.
So far I've tried:
java.lang.Runtime.getRuntime().availableProcessors
System.Environment.ProcessorCount
!wmic cpu get NumberOfCores
and!wmic cpu get NumberOfLogicalProcessors
.
1 is cross-platform, but returns the number of logical rather than physical processors.
2 is Windows only, and also returns logical rather than physical processors.
3 gives both physical and logical processors, but is also Windows only, and although I can use it successfully from the DOS command window, for some reason it seems to hang for an eternity when run from MATLAB.
wmic
might have been hanging? There are lots of other things that could be useful for if it worked. – Pasia