parallel processing time problem
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
Edric Ellis
2013 年 5 月 13 日
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;
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!