MATLAB: Internal threads in FMINCON

fmincon parallelMATLABOptimization Toolbox

Dear users,
I am using Matlab 2012A in Linux (Ubuntu 12.04) and I have a MEX function that I want to use as the objective function in FMINCON. I have developed this function in C with OpenMP. My function computes both the gradient and the value of the objective for a given candidate solution. However, it relies on global static arrays to save constant information along the search. Therefore, the MEX function is far from being thread safe for external calls. Then, I would like to know if FMINCON will try to run my objective function in parallel at any point of its searching procedure. If it does so, I would need to block it.
I have explicitly defined an struct for the parameters of FMINCON with the "UseParallel" directly configured as "never" (what I have read in the documentation that is the default value). However, when I start the search of FMINCON with my objective function (in a pure sequential version WITHOUT OpenMP) and I launch the HTOP utility in the system, I see several cores of the processor (which has 4, 2 real cores with hyper-threading) as if they were heavily working: One of the cores is at 100% while another one is up to 70% and sometimes the third one seems to get something to do (up to 40%… more or less).
Consequently, I am afraid of getting wrong results in case that FMINCON tries to launch my MEX function with global static variables from several internal threads. Would it be possible?
Thank you very much in advance for your time and answers,
Best regards.

Best Answer

MATLAB automatically uses multiple cores for larger computations that fit one of the patterns available through BLAS or LINPAC . It will examine multiple statements and will do several operations at the same time if it figures that will be productive. Even something as simple as mean() can sometimes be done faster on multiple cores.
This is not done at the call level: this is done at the mathematics level. It also does not use the Parallel Computing Toolbox.
Related Question