MATLAB Answers

handling the parfor loop

2 views (last 30 days)
in fact, i want to parallelize this function in matlab.
here is the piece of code:
function calcul(h,e,ch3,ch2,ch1)
menu = get(ch2,'Value');
texte=get(ch2,'String');
fich=get(ch1,'string');
fct = texte{menu};
disp(fct);
val= get(ch3,'string');
switch fct
case 'ellipsoide'
disp('ellipsoide');
trouve=0;
[n,m] = size(val);
parfor i=1:m
if val(i)=='1'|| val(i)=='2'||val(i)=='3'||val(i)=='4'||val(i)=='5'||val(i)=='6'||val(i)=='7'||val(i)=='8'||val(i)=='9'||val(i)=='0'
trouve=trouve+1;
end
end
here is the error that shows me : The temporary variable val in a parfor is uninitialized.
  3 Comments
PIERRE OLIVIER SCHOUEL ATANGANA
Hello,
I just encountered another problem in parallelization. I identified the outermost for loop. Here's what I didHello,
I just encountered another problem in parallelization. I identified the outermost for loop. Here's what I did:
t_debut3=tic;
%l = parallel.pool.Constant(mex);
% i=1;
%while i <k
parfor (i=1:k,8)
members = (i == idx);
disp(strcat('Cluster numero <',num2str(i),'>'));
sousEns=Pts(members,:);
if(isempty(sousEns)==1)
continue
end
sousRay=Ray(members);
disp('De Centroid');
disp(C(i,:));
Echan=[];
l=size(sousEns,1);
for j = 1:l
% for j=1:size(sousEns,1)
xx=[];
yy=[];
zz=[];
xx=sousRay(j)*sin(phi).*cos(theta)+sousEns(j,1);
yy=sousRay(j)*sin(phi).*sin(theta)+sousEns(j,2);
zz=sousRay(j)*cos(phi)+sousEns(j,3);
% disp('OOOKKKKK')
n=size(xx(:),1);
Echan2=[];
Echan2(1:n,1)=xx(:);
Echan2(1:n,2)=yy(:);
Echan2(1:n,3)=zz(:);
Echan=[Echan2;Echan];
[xu,yu,zu] = sphere;
x = xu*sousRay(j) + sousEns(j,1);
y = yu*sousRay(j) + sousEns(j,2);
z = zu*sousRay(j) + sousEns(j,3);
c = ones(size(z))*1;
hold on;
surf(x,y,z,c);
end
% envConvex=[]
% Echan
hold on
% disp('Echantillons');
% disp(Echan);
% Calcul de l'enveloppe convexe du sous ensemble de boule
[envConvex,vol]=convhull(Echan,'simplify',true);
% Ajout de l'enveloppe convexe du sous ensemble sur le dessin
% trisurf(envConvex,Echan(:,1),Echan(:,2),Echan(:,3), 'Facecolor','cyan'); axis equal;
col1=Echan(:,1);
col2=Echan(:,2);
col3=Echan(:,3);
% trisurf(envConvex,col1,col2,col3, 'Facecolor','cyan');
% Ajout des points echantionné d'un sous ensemble sur la figure de
% visualisation.% hold on
plot3(Echan(:,1),Echan(:,2),Echan(:,3),'.');
% Trace de l'ellipsoide qui approxime l'envesloppe convexe.
plot3(col1(envConvex(:,1)),col2(envConvex(:,2)),col3(envConvex(:,3)),'.');
Ptsapp=[];
Ptsapp=[col1 col2 col3];
hold on;
nbptsvisual=15;
[A1 centro] = approximation(Ptsapp',0.01)
[~,D1,V1] = svd(A1);
rx = 1/sqrt(D1(1,1));
ry = 1/sqrt(D1(2,2));
rz = 1/sqrt(D1(3,3));
me = [centro(1) centro(2) centro(3) rx ry rz];
mex=[me;mex];
[u v] = meshgrid(linspace(0,2*pi,nbptsvisual),linspace(-pi/2,pi/2,nbptsvisual))
x1 = rx*cos(u').*cos(v');
y1 = ry*sin(u').*cos(v');
z1 = rz*sin(v');
for indx = 1:nbptsvisual
for indy = 1:nbptsvisual
poin = [x1(indx,indy) y1(indx,indy) z1(indx,indy)]';
Pt = V1 * poin;
x1(indx,indy) = Pt(1)+centro(1);
y1(indx,indy) = Pt(2)+centro(2);
z1(indx,indy) = Pt(3)+centro(3);
end
end
uicontrol(fig, 'style','pushbutton', 'string','sauvergader', 'units','normalized', 'fontsize',11, 'position',[.05 .05 .15 .07], 'FontWeight','bold', 'FontName','Times New Roman', 'callback',{@sauvegarder,mex});
mesh(x1,y1,z1,'facecolor','none');
% set(me,'facecolor','none');
% surf(x1,y1,z1);
% i=i+1;
end
t_for=toc(t_debut3);

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!