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.
MATLAB is using: 3 logical cores. MATLAB is not using all logical cores because hyper-threading is enabled. why matlab detect just juste 3 physical cores ! and how can i use all logical and physical cores for parallel computing. thanks.
The number of logical processors you will have will be 8. This value is a product of the number of physical cores (8), and the number of threads they can handle (1). But what if your CPU is capable of hyperthreading? Well then each core can handle two threads, so an 8 core CPU will have 8 * 2 = 16 logical processors.
MATLAB® provides two main ways to take advantage of multicore and multiprocessor computers. By using the full computational power of your machine, you can run your MATLAB applications faster and more efficiently.
Only certain functions are optimized to take advantage of multiple core processor. More generally matlab remains a single threaded application and you have to use parallel computing toolbox to take full advantage of multi core processors.
You need to use the undocumented command
feature('numcores')
as explained here: http://undocumentedmatlab.com/blog/undocumented-feature-function/
This will work
getenv('NUMBER_OF_PROCESSORS')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With