フィルターのクリア

how can I write a parallel code in Matlab?

1 回表示 (過去 30 日間)
sasa
sasa 2014 年 8 月 1 日
回答済み: Edric Ellis 2014 年 8 月 4 日
hi every one, can you help me to write a program with parfor and compare the time consumed in comparing with for? The code is: matlabpool open local 7 tic parfor i = 1:100000 k=i end toc matlabpool close Elapsed time is 1.846197 seconds.
tic,for i = 1:100000 k=i end toc Elapsed time is 0.000640 seconds.

採用された回答

Dima Lisin
Dima Lisin 2014 年 8 月 1 日
The reason you are seeing this result is because your loop does not do anything. If you make each iteration of your loop do substantial work, you will see a speedup.
  1 件のコメント
sasa
sasa 2014 年 8 月 2 日
yes,That's right.Thanks for your help. I have tested with this code and the result is ok.
matlabpool open local 7 tic parfor i = 1:10000 k=i; I = imread('cameraman.tif'); h = fspecial('motion',20,45); blur = imfilter(I,h,'replicate'); end toc matlabpool close
tic for i = 1:10000 k=i; I = imread('cameraman.tif'); h = fspecial('motion',20,45); blur = imfilter(I,h,'replicate'); end toc
Starting matlabpool using the 'local' profile ... connected to 7 workers. Elapsed time is 23.898915 seconds. Sending a stop signal to all the workers ... stopped.
Elapsed time is 49.894086 seconds.

サインインしてコメントする。

その他の回答 (1 件)

Edric Ellis
Edric Ellis 2014 年 8 月 4 日
Ideally, you should not open and close the pool for timing purposes - it's intended that you keep the pool open.

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by