Error using UseParallel and fmincon

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

回答(1 个)

Edric Ellis
Edric Ellis 2011-8-19
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.

1 个评论

This is true. However, the functions which are part of the matlab toolboxes do not need to know the values of by global vars, and vice-versa. The strange thing is, if I do not invoke the parallel toolbox I do not receive this error, in which case fimincon and the related functions in the optimization toolbox are fine. This makes me believe that the use of my globals is not an issue.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

提问:

2011-8-19

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by