Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB and using multiple cores to run calculations

Hey all. Im trying to sort out how to get MATLAB running as best as possible. I have a pretty decent new machine.

12GB RAM Core i7 3.2Ghz Cpu and lots of free space. and a strong graphics card.

However when I run the benchmark test of MATLAB (command bench) it lists the computer as being near the worst, around a Windows XP single core 1.7Ghz machine.

Any ideas why and how I can improve this??

Thanks very much

like image 874
Guy Z Avatar asked Jul 21 '10 03:07

Guy Z


People also ask

Can I make MATLAB use more CPU?

Accepted AnswerFor some code MATLAB can only utilize a single core of a single processor, for other code, MATLAB will automatically utilize all available cores (and maybe processors). It really depends on the underlying functions. Some things cannot be easily parallelized.

How many cores do I need for MATLAB?

MATLAB is using: 2 logical cores.

Why MATLAB does not use all CPU?

In general, MATLAB is single threaded except for some lower level BLAS routines that are multithreaded. Therefore, CPU utilization may vary depending on what function you are running.

Can MATLAB use hyperthreading?

Direct link to this question cores issue in Matlab: Matlab has inherent multithreading capabilities, and will utilize extra cores on a multicore machine. Matlab runs its threads in such a way that putting multiple Matlab threads on the same core (i.e. hyperthreading) isn't useful.


2 Answers

Firstly, I would recommend re-running the bench command a few times to make sure MATLAB has fully loaded all the libraries etc. it needs. Much of MATLAB is loaded on demand, so it's always best to time the second or third run.

MATLAB automatically takes advantage of multiple cores when executing certain operations which are multithreaded. For example lots of elementwise operations such as +, .* and so on as well as BLAS-backed operations (and probably others). This page lists those things which are multithreaded.

Parallel Computing Toolbox is useful when MATLAB's intrinsic multithreading can't help (if it can, then it's usually the fastest way to do things). This gives you explicit parallelism via PARFOR, SPMD and distributed arrays.

like image 97
Edric Avatar answered Sep 29 '22 05:09

Edric


You need the Parallel Processing Toolbox. A lot of MATLAB functions are multithreaded but to parallelize your own code, you'll need it. A dumb hack is to open several instances of command-line MATLAB. You could also write multithreaded MEX files but the right way to go about it would be the purchase and use the aforementioned toolbox.

like image 38
Jacob Avatar answered Sep 29 '22 07:09

Jacob