Hello, why does my parallel source code turns out to be slow compared to sequential source code?
Show older comments
this is my sequential source code:
for n = 1:lh hj(2^j*(n-1)+1)=h(n); end
for n = 1:lg
gj(2^j*(n-1)+1)=g(n);
end
a(:,:,1,j+1) = conv2(hj,hj,a(:,:,1,j),'same');
dx(:,:,1,j+1) = conv2(delta,gj,a(:,:,1,j),'same');
dy(:,:,1,j+1) = conv2(gj,delta,a(:,:,1,j),'same');
x = dx(:,:,1,j+1);
y = dy(:,:,1,j+1);
dj(:,:,1,j+1) = sqrt(x.^2+y.^2);
I1 = imadjust(dj(:,:,1,j+1),stretchlim(dj(:,:,1,j+1)),[0 1]);
figure;imshow(I1);
end
and this is my parallel source code:
for j = 1:J+1
lhj = 2^j*(lh-1)+1;
hj=zeros(1, lhj);
hj(1:2^j:end)=h;
a(:,:,1,j+1) = conv2(hj,hj,a(:,:,1,j),'same');
end
parfor j = 1:J+1
lgj = 2^j*(lg-1)+1;
gj=zeros(1, lgj);
gj(1:2^j:end)=g;
atmp=a(:,:,1,j); %excessive optimization perhaps, eliminate one subsref() call
dx(:,:,1,j+1) = conv2(delta,gj,atmp,'same');
dy(:,:,1,j+1) = conv2(gj,delta,atmp,'same');
end
dj = sqrt(dx.^2+dy.^2);
for j = 1:J+1
I1 = imadjust(dj(:,:,1,j+1),stretchlim(dj(:,:,1,j+1)),[0 1]);
figure;imshow(I1);
end
Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!