Error using UseParallel and fmincon
Show older comments
Hello, I am having a problem with the parallel toolbox using MATLAB 2008b. Let me show the error, then I will explain the functions involved. The error message reads:
??? Error using ==> parallel_function at 587 Error in ==> priceindexSS at 23 At least one operand must be scalar.
Error in ==> parfinitedifferences at 103 parfor(gcnt=1:numberOfVariables)
Error in ==> nlconst at 321 [gf,gnc] = parfinitedifferences(XOUT,x,funfcn,confcn,lb,ub,f,nc, ...
Error in ==> fmincon at 728 [X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
Error in ==> clbrtSS at 68 pp_t = fmincon(@(pp) ggSS(pp,data)'*WGT*ggSS(pp,data),...
The object I am minimizing is the inner product of ggSS(). I have passed ...'UseParallel','always'... into the options structure. This is being read as Matlab is using the parfinitedifferences to compute the gradient. The confusing part is the error in parallel_function. It says that there is an error in the function priceindex. The function price index is another function that is being called through ggSS.
I know there is no coding error since the problem runs with UseParallel set to 'never'. But for some reason I get this error when I turn it on. To give a better idea about the function priceindex, it includes a list of global variables, and a performs iterations in a while loop. I have tested much simpler problems with a similar type of structure (nested functions being called with while loops and global variables, and so on) using the parallel toolbox and it has worked. Any experience with this type of error?
Please let me know if you need more info, I am trying to avoid including too much code here unless necessary.
Thanks - Mike
Answers (1)
Edric Ellis
on 19 Aug 2011
0 votes
GLOBAL (and PERSISTENT) variables are not shared between your MATLAB client session and the workers executing the body of your PARFOR loop (which is hidden inside your fmincon call). Unfortunately, I think you need to re-work your code so that it doesn't rely on GLOBAL data.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!