parfor loop variable cannot be classified

Hi all, I'm trying to use parfor instead of for to deal with 3 minimizations (for now, it should increase a lot) that are independent of each other in everything but the initial values. I have the data corresponding to each minimization in a different structure and the parameters over which I want to minimize, defined as scalars out of the structure. In particular, the code looks as follows (matlabpool is open before what follows).
p0=rand(3,1); % Initial guess for parameters, common to all %minimizations
for i=1:3,
mk(i).param=zeros(3,1);
mk(i).obj=zeros(1,1);
end
mk(1).mc=[2;3;4];
mk(2).mc=[1;3;2];
mk(3).mc=[2;4;1];
mk(1).n=6;
mk(2).n=8;
mk(3).n=15;
mk(1).id=1;
mk(2).id=2;
mk(3).id=3;
parfor i=1:3,
[mk(i).param mk(i).obj]=fminsearch(@(p) prFOCv1(p,a;mk(i).mc,mk(i).n,mk(i).id),P0,Options);
end
So, every struct has components labeled mc, n and id and the values of each of these correspond to the values specified above and are independent of each other. If I use for instead of parfor, it works ok, but executes one minimization after the other, while I would like to do all simultaneusly. When I use parfor I get the message ???Error: The variable mk in a parfor cannot be classified. See Parallel for Loops in MATLAB, "Overview". I have read the "Overview" section, but I just don't understand what's the mistake that I'm making.
Any help would be appreciated. Thanks,
Fernando

 Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Mayo de 2012

0 votos

Why is there a semi-colon in the call to prFOCv1 ?

Más respuestas (1)

Fernando
Fernando el 5 de Mayo de 2012
by mistake...but without the semi-colon I get the same error message.
I did a couple of changes to see what is causing the error. In particular, I decided to just evaluate the function prFOCv1 at the initial values, using parfor. This works OK.
parfor i=1:3,
mk(i).obj=prFOCv1(p0,a,mk(i).mc,mk(i).n,mk(i).id);
end
So I guess that the problem is related to the way the output of the minimization is defined ( [mk(i).param mk(i).obj]=...).

4 comentarios

Walter Roberson
Walter Roberson el 5 de Mayo de 2012
You still have a semi-colon right after the "a" and before the "mk(i)" ??
Fernando
Fernando el 5 de Mayo de 2012
Sorry, that was a typo when writing the code (I didn't copy and paste). It is a , not a ;
Walter Roberson
Walter Roberson el 5 de Mayo de 2012
You could try outputting to cell arrays indexed at "i", and put the structure back together afterwards.
Fernando
Fernando el 5 de Mayo de 2012
Great, that worked. Thanks.

Iniciar sesión para comentar.

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by