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 Kommentare

Walter Roberson
Walter Roberson am 29 Jul. 2021
Bearbeitet: Walter Roberson am 29 Jul. 2021
Note:
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;
could be written without a loop as
trouble = nnz(val >= '0' & val <= '9')
... unless 'val' has multiple rows, in which case your existing code is likely wrong.
thanks for this solution.
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);

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by