The variable 'counter' is perhaps intended as a reduction variable, but is actually an uninitialized temporary.

5 visualizaciones (últimos 30 días)
I have tried to use parfor to decrease the required time needed for the for loop. The normal for loop was working properly before using parfor but it takes too long to finish the for loop. Then, I have modified the for to parfor to enable using parallel computing. The following error was generated (Error: The variable 'counter' is perhaps intended as a reduction variable, but is actually an uninitialized temporary).
start=8;%%%% elemnent that are not numbers in the file read
var=['_var_',num2str(no_variables),'_'];
a=first;
b=last;
tic
name=first;
counter=0;
for i=a:step:b
filename=[surfacename,num2str(sub),var,num2str(i),'.raw'];
fullname=fullfile(Dir,filename);
fid = fopen(fullname,'rb'); % rb = read binary
NN=N*10;
data2 = fread(fid,NN,'single');
fclose(fid);
start=8;
data2=data2(start:length(data2));
len=length(data2)/no_variables;
counter=counter+1;
if opt==1 ||opt==6;
data(:,counter)=data2(1:len);
elseif opt==2;
data(:,counter)=data2(len+1:2*len);
elseif opt==3;
data(:,counter)=data2(2*len+1:3*len);
elseif opt==4;
data(:,counter)=data2(3*len+1:4*len);
elseif opt==5;
data(:,counter)=data2(4*len+1:5*len);
elseif opt==7;
F = scatteredInterpolant(x,y,z,data2(1:len),'linear','linear');
data_int=F(xq,yq,zq);
data_int_2= reshape(data_int,[],1);
data(:,counter)=data_int_2;
end
if mod(i,500) == 0
fprintf('flie read %d...\n',i);
tt=toc/60
end
name=[name,i];
end
tt=toc/60

Respuesta aceptada

Rik
Rik el 8 de Abr. de 2022
Your loop depends on the previous iterations. You should calculate the value of the counter variable inside the loop. Otherwise you cannot make this parallel.

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by