How many cores does MATLAB use in a given program?

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?

 Akzeptierte Antwort

John D'Errico
John D'Errico am 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 Kommentare

BM
BM am 7 Nov. 2017
I use Linux, do you have any suggestions of the best program to accomplish this task in Linux? Thanks for your suggestion, by the way!
Sorry, but I am clueless about any other OS than a Mac. Ok, some will suggest I am just clueless in general. :)
"... best program to accomplish this task ..."
The best program to accomplish what task ?
To show the number of cores currently active (in MATLAB) on a Linux system.
BM
BM am 8 Nov. 2017
Exactly. I already knew of some monitoring programs on Linux, but the ones I know about are a little less clear, at least to me, then what I have seen on other operating systems.
The one on the Mac is pretty nice. Run the utility. A graphic window pops up. You tell it to watch the CPU utilization with a menu. Then go off and use MATLAB, with one eye on the monitor.
Or, I just listen for the fan to kick in. If it starts kicking in, then I know all CPUS are busy. :)
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?
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by