Firstly, some quick tests confirming our understanding:
> matlab.exe -singleCompThread
>> warning('off', 'MATLAB:maxNumCompThreads:Deprecated') >> maxNumCompThreads ans = 1 >> maxNumCompThreads(2) Error using feature MATLAB has computational multithreading disabled. To enable multithreading please restart MATLAB without singleCompThread option. Error in maxNumCompThreadsHelper (line 37) Error in maxNumCompThreads (line 27) lastn = maxNumCompThreadsHelper(varargin{:});
As indicated, when MATLAB starts with the -singleCompThread option, we cannot override it with maxNumCompThreads .
> matlab.exe
>> parpool(2); % local pool >> spmd, n = maxNumCompThreads, end Lab 1: n = 1 Lab 2: n = 1
We see that each worker is by default limited to one stream of computation. This is good because we want to avoid the excessive subscription and unnecessary context switches that occur when the number of threads trying to execute exceeds the number of available physical / logical cores. Therefore, in theory, the best way to maximize processor load is to run as many single-threaded workers as we have cores.
No, looking at the local work processes running in the background, we see that each of them starts as:
matlab.exe -dmlworker -noFigureWindows [...]
I believe that the undocumented -dmlworker option does something similar to -singleCompThread , but is probably a little different. Firstly, I was able to override it with maxNumCompThreads(2) without throwing an error as before.
Remember that even if the MATLAB session operates in single-threaded calculation mode, this does not mean that the computational flow is limited to only one CPU core (the flow may jump between the kernels designated by the OS scheduler). You will need to establish the proximity of work processes if you want to control this.
So, I did some profiling using the Intel VTune Amplifier. Basically, I ran some linear algebra code and performed the analysis of the βhot spotsβ by joining the MATLAB process and filtering the mkl.dll module (this is Intel MKL library, which MATLAB uses as an optimized implementation of BLAS / LAPACK). Here are my results:
- Sequential mode
I used the following code: eig(rand(500));
- MATLAB usually starts, the calculation generates 4 threads (which is automatically selected by default if I have a quad-core Intel i7 Intel processor).
- running MATLAB is usually, but calling
maxNumCompThreads(1) before computing. As expected, only the calculation only calculates 1 thread. - starting MATLAB with the
-singleCompThread option, again only 1 thread is used.
- Parallel mode ( parpool )
I used the following code: parpool(2); spmd, eig(rand(500)); end parpool(2); spmd, eig(rand(500)); end parpool(2); spmd, eig(rand(500)); end . In both cases below, MATLAB runs normally
- when you run the code for workers with default settings, each worker is limited to one calculation flow
- when I redefine the settings for workers using
maxNumCompThreads(2) , then each worker will use 2 threads
Here is a screenshot of what VTune reports:

Hope that answers your questions :)