0
只是爲了檢查matlab中的並行處理是如何工作的,我嘗試了下面的一段代碼並測量了執行時間。但是我發現並行處理代碼比意想不到的普通代碼花費更多時間。我在某處做錯了嗎?如何檢查matlab中的並行處理性能?
代碼與並行處理
function t = parl()
matlabpool('open',2);
tic;
A = 5:10000000;
parfor i = 1:length(A)
A(i) = 3*A(i) + (A(i)/5);
A(i) = 0.456*A(i) + (A(i)/45);
end
tic;
matlabpool('close');
t = toc;
end
有導致用於並行處理
>> parl Starting matlabpool using the 'local' profile ... connected to 2 workers. Sending a stop signal to all the workers ... stopped.
ans =
3.3332
function t = parl()
tic;
A = 5:10000000;
for i = 1:length(A)
A(i) = 3*A(i) + (A(i)/5);
A(i) = 0.456*A(i) + (A(i)/45);
end
tic;
t = toc;
end
結果爲沒有並行處理代碼
>> parl
ans =
2.8737e-05