How to run MATLAB (or execute some algorithm) on specific number of cores on a computer?

1 view (last 30 days)
Hello,
I am trying to study the performance (in terms of execution time) of my some algorithm by varying the number of cores to be used on my machine. Any pointers, how to do it?
Thanks in advance.
PS: (I have a 16 core machine in the dept (OS:Red Hat, MATLAB 2011 a))

Answers (2)

Walter Roberson
Walter Roberson on 24 Jan 2013
Make sure that hardware hyperthreading is off. Then use matlabpool() with the number of cores you want.
Watch out for a core being used by the operating system for whatever (e.g., virus checking).
  1 Comment
Matt J
Matt J on 24 Jan 2013
matlabpool sets the number of workers. I'm not sure that guarantees that each worker will be assigned a single core. On a 16-core machine, I suspect that a pool of 4 workers would get 4 cores each, for example.

Sign in to comment.


Jason Ross
Jason Ross on 24 Jan 2013
Edited: Jason Ross on 24 Jan 2013
A matlabpool will give you a number of worker processes, with a single computational thread each. The actual placement of workers is left up to the operating system, so there's not a guarantee which core will recieve which process.
It would be much easier to vary the number of MATLAB workers in your matlabpool and chart execution time as the number changes if you are using an algorithm that can be parallelized. For an example, see Benchmarking A\b
If you aren't using something that can be parallelized, you might want to try varying the maxNumCompThreads setting.
As with any benchmarking or performance analysis, take care to minimize variables that can cause variation. In general, I find it most useful to have all of the resources local to the machine under test as possible. This eliminates networking latency, which depending on the speed of your network and storage infrastucture, can introduce enormous variations into your results. It's also worth taking the time to repeat runs, as well -- and have run times that are long enough to be meaningful.
In addition to CPU performance, you also likely want to keep an eye on memory utilization, network utilization, and disk performance to fully understand why your algorithm may perform differently under different circumstances.
There is also an interesting paper on the File Exchange on this topic: http://www.mathworks.com/matlabcentral/fileexchange/18510-matlab-performance-measurement

Community Treasure Hunt

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

Start Hunting!