3

I'm running an algorithm that's taking a lot of resources, and maxes out the CPU.

The problem is that it's only using one CPU.

How can i make MATLAB multithread the computations and use more than 1 CPU ?

Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185

2 Answers2

2

Unless you specifically use parallel constructs -- that is, using explicit parallelism -- or use built-in functions that have already been parallelized for you -- Matlab will not run faster on a multicore machine. This post has a list of built-in functions that have been parallelized and so will take advantage of multiple cores:

http://www.walkingrandomly.com/?p=1894

Here's an example of using a parallel construct to roll your own parallelism:

http://www.mathworks.com/matlabcentral/fileexchange/13775

EmeryBerger
  • 3,897
  • 18
  • 29
  • That's just no true. It will run faster on parallel machines. – Yochai Timmer Jan 15 '11 at 17:33
  • @Yochai - edited to clarify (it runs faster if you use already-parallelized functions, otherwise, not). – EmeryBerger Jan 15 '11 at 17:37
  • 2
    +1 Right, but MATLAB itself parallelisese even basic matrix operations (multiplication, MIN,MAX,INV,SQRT,POW). For matrices that are larger than 40K elements. BUT you did give a nice example on how to parallelize your own functions. – Yochai Timmer Jan 15 '11 at 17:46
2

The settings are at:

File>Preferences>General>Multithreading in R2007a or newer

Affected functions are described at:

Which MATLAB functions benefit from multithreading

Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185