How many cores does MATLAB use in a given program?
27 views (last 30 days)
Show older comments
This might be an odd question, but my code has to be run on a more powerful machine. What would be helpful is to know how many cores my program uses. I don't know how to obtain this information. Would anyone be able to provide some suggestions?
0 Comments
Accepted Answer
John D'Errico
on 7 Nov 2017
On my computer...
maxNumCompThreads
ans =
4
How many cores your code actually uses on any given code is far more difficult. MATLAB can sometimes launch extra threads for large problems, but ONLY if it decides there will be a gain in so doing. So any given code may vary in the number of cores it will end up using. With some effort, I can force all of my cores to run flat out, but most simple computations never launch any additional cores.
I would suggest that you test run your code, watching a system monitor that will tell how many cores are active for MATLAB. How you do that will depend on what computer you are using. On my Mac, it is the activity monitor utility that I would use.
8 Comments
Shaily_T
on 6 Jun 2022
Hi, I have a related question and I appreciate your comment. I tried your nice suggestion, and when I run my code in Matlab, the activity monitor says 100% CPU is being used. And sometimes it shows even more than 100%. Does that mean all of the cores are used for running the code?
I have a Matlab code for fitting a custom model to a series of data. The actual number of data I have is about 600000. I can run the code for a selection of the data (6000 points), and it works fine. But I need to know the answer for the actual data size, and when I run the fit code, it takes a long time on my laptop to run, and it doesn't get to work. My laptop has four physical cores, and when I run Matlab code, the Activity Monitor on my MAC says 100% for CPU usage.
I am thinking of running my code on a cluster, but if the current laptop is not using all the available cores, I don't believe running it on a cluster would be helpful. The algorithm of my fit code is not something that I can write as a suitable format for parallel computing.
Do you have any thoughts?
Walter Roberson
on 6 Jun 2022
MacOS Activity monitor shows work relative to one core. A "single core" process can exceed 100% due to hyperthreading. If your Mac were running flat out on four physical cores it would approach 400%
MATLAB automatically uses parallel libraries for some of the operations, provided that the arrays are "large enough" (size is dependent on the operation). Not routinely seeing hundreds implies that your code either is not making much use of those mathematical operations, or else that your arrays are too small for it to help.
More Answers (0)
See Also
Categories
Find more on Platform and License in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!