parallel processing time problem

3 views (last 30 days)
Anas A.Salam
Anas A.Salam on 11 May 2013
hello i have a question about the time when i use single core and when i use 4 cores at the first time i had time equal 15 second also this is the code
-----------------------
a=imread('something.jpg');
b(1:size(a,1),1:size(a,2))=0;
c(1:size(a,1),1:size(a,2))=0;
for i=1:size(a,1)
for j=1:size(a,2)
for k=1:size(a,3)
b(i,j)=b(i,j)+a(i,j,k);
c(i,j)=b(i,j)/3;
end
end
end
---------------------
when i try to use matlabpool i had time larger than i had it with single core so what is the problem ?? by the way i used this code with multi core
----------------------
a=imread('something.jpg');
b(1:size(a,1),1:size(a,2))=0;
c(1:size(a,1),1:size(a,2))=0;
parfor i=1:size(a,1)
parfor j=1:size(a,2)
for k=1:size(a,3)
b(i,j)=b(i,j)+a(i,j,k);
c(i,j)=b(i,j)/3;
end
end
end
-------------------------- thank you

Answers (1)

Edric Ellis
Edric Ellis on 13 May 2013
Firstly, you should note that only the outermost PARFOR has any effect. All the available parallelism is used there, so the inner PARFOR makes no difference.
In this case, the amount of computation you're doing inside the loop compared to the amount of data you're accessing is much too low. In this case, I think vectorization should give you much better results. I think in this case can't you simply do:
a = imread('something.jpg');
b = sum(a, 3);
c = b ./ 3;

Categories

Find more on Parallel for-Loops (parfor) 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!