Home > OS >  How to limit CPU usage of Matlab in Linux
How to limit CPU usage of Matlab in Linux

Time:06-19

When I run a Matlab simulation on my PC (20 cores), it uses all cores. Is there any way to limit CPU availability to Matlab, so that it uses only, say, 10 cores?

CodePudding user response:

The maxNumCompThreads function can be used to tell MATLAB how many threads to use in computation. In your case, write at the top of your script/function:

maxNumCompThreads(10)

Note that this will affect everything run on MATLAB during the remainder of the session, but will not affect future sessions. This is why you probably want to put this command at the top of your script, so that it applies every time you run that script.

Note also that this does not affect the Parallel Processing Toolbox, which is a different way of using multiple CPUs on your machine. It changes how many threads are used to do basic computations like matrix multiplications and convolutions and Fourier transforms and so on.

  • Related