parfor sliced variable unable to classify the variable

1 view (last 30 days)
Hello,
I'm trying to run a parfor loop to speed up everything. I've not completely understood the use of sliced variables.
What I want to do is to generate within the parfor a struct M storing all the figures with a getframe(fig) inside the function ThicknessVideoCreatorV2 needed to create a video. Within the loop the Mtemp struct with 'cdata' and 'colormap' variables is created and then assigned to the kk position of M.
M=[];
parfor i=iStart:iStart+100%iStop
kk=i-iStart+1;
zz=iV(kk);
% iV=i+Divid-iStart;
% if iV+iStart>nImag-iStart
%
% break
%
% else
Mtemp=ThicknessVideoCreatorV2(LFradial(:,i), TfilmRadial(:,i),...
txt1{i}, txt2{i}, txt3{i},newIred{zz},fig, i, p1,p2,pl2,...
imgGraph, t1, t2,t3, pipeLength,limY_TBS);
M(kk)=Mtemp;
end
I get this error:
"Error: Unable to classify the variable 'M' in the body of the parfor-loop. For more information, see Parallel for Loops in MATLAB, "Solve Variable Classification Issues in parfor-Loops"."
How can I fix this and use parfor properly?
Thank you in advance
Riccardo

Answers (1)

Prateekshya
Prateekshya on 6 Sep 2023
Hi Riccardo,
I understand that you are trying to store "Mtemp" in a specific index of "M" in each iteration of the "parfor" loop and you are getting an error. The given error typically occurs when we attempt to use a variable inside a "parfor" loop that cannot be automatically classified by MATLAB's Parallel Computing Toolbox. I assume that there are no other dependencies on the variable "M".
Instead of "i", you can use "kk" as the loop variable which will solve the issue. The code will be modified as follows:
M=[];
parfor kk = 1 : 101 % Modification done
i = kk+iStart-1; % Modification done
zz=iV(kk);
% iV=i+Divid-iStart;
%
% if iV+iStart>nImag-iStart
%
% break
%
% else
Mtemp=ThicknessVideoCreatorV2(LFradial(:,i), TfilmRadial(:,i),...
txt1{i}, txt2{i}, txt3{i},newIred{zz},fig, i, p1,p2,pl2,...
imgGraph, t1, t2,t3, pipeLength,limY_TBS);
M(kk)=Mtemp;
end
For more information on sliced variables you can refer the examples given here: https://in.mathworks.com/help/coder/ug/classification-of-variables-in-parfor-loops.html
I hope this helps!

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!