Search code examples
multithreadingmatlabmatlabpool

can't use all 8 cores in core i7 for matlab


When I execute

matlabpool open 4;

everything works correctly, but when I try execute

matlabpool open 8;

error occurs immediately. I read about Hyper Threading and I know that 4 of 8 cores are virtual. Does than mean that I cannot use all 8 cores in an efficient way for

parfor loop 

in Matlab?

For example, I have 8 similar independent tasks.

Can I use all 8 cores in python or C#/C++ with acceleration 8 times faster?


Solution

  • By default, MATLAB uses the number of physical cores rather than the number of hyperthreaded cores on your machine since the hyperthreads still ultimately share the same physical CPUs resources. There is more info about specific cases where there may/may not be a benefit to using hyperthreads in this post on MATLAB Answers

    If you want to use 8 workers, you'll want to modify the NumWorkers property of your 'local' configuration

    cluster = parcluster('local');
    cluster.NumWorkers = 8;
    saveProfile(cluster);
    

    Alternately, you can set the maximum number of compute threads to use with maxNumCompThreads

    maxNumCompThreads(8)