unable to classify the variable 'F' in the body of the parfor-loop
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
zein
el 13 de Abr. de 2022
Comentada: zein
el 14 de Abr. de 2022
I was trying to reduce the time taken by parfor and I have tried to calculate F (scatteredInterpolant() ) before the parfor loop
F = scatteredInterpolant(x,y,z,data2(1:len),'linear','linear');
Then, I tried to use interpolant object F inside the parfor loop
parfor i=1:size(data,2)
F.Values=data2(1:len)
end
but the following error was generated
unable to classify the variable 'F' in the body of the parfor-loop. For more information ,see parallel for loops in MATLAB "SOLVE VARIABLE Classification issues in parfor-loops
0 comentarios
Respuesta aceptada
Edric Ellis
el 13 de Abr. de 2022
This use of F creates an order depdency between loop iterations. (You're modifying F on each loop iteration). I'm not entirely sure what you're trying to do here, but perhaps you want to do something more like this?
rng('default')
x = -2.5 + 5*rand([50 1]);
y = -2.5 + 5*rand([50 1]);
v = x.*exp(-x.^2-y.^2);
F = scatteredInterpolant(x,y,v);
parfor i = 1:10
% Make a copy of F
Ftmp = F;
% Modify the copy - this is fine
vnew = x.^2 + y.^2 + i;
Ftmp.Values = vnew;
out(i) = F(i, i);
end
disp(out)
0 comentarios
Más respuestas (1)
zein
el 13 de Abr. de 2022
Editada: zein
el 13 de Abr. de 2022
2 comentarios
Edric Ellis
el 14 de Abr. de 2022
In the attached code, you still have lines inside the parfor loop that assign to F.Values - lines 95; 100; 105; 109; 114. Even if these lines don't execute at runtime, the parfor analysis must be satisfied that nothing order-dependent could ever happen using static analysis and ignoring the value of opt. It might help to assign Ftmp = F at the start of the loop, and then use that everywhere inside the loop.
Ver también
Categorías
Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!