我需要並行執行兩個Matlab函數。問題是從他們那裏獲得結果比執行慢得多。Matlab從並行函數中獲得結果很慢
第一種方法:
spmd;
if labindex==1,
K=MatricaK(NP, NE, r, Kxx, N, h, 1); %K is 1000x1000 matrix
end;
if labindex==2,
F=Apkrovos(NP, NE, N, r, Ta, h, 1); %F is 1000x1 vector
end;
end;
%This part is quite fast, around 0.17s.
K=K{1};
F=F{2};
%This part is very slow, around 1.15s.
方法二:
parfor i=1:2
if i==1
K=MatricaK(NP, NE, r, Kxx, N, h, 1); %this way doesn't return K outside the loop, but very fast, around 0.15 for all loop
..
K{i}=MatricaK(NP, NE, r, Kxx, N, h, 1); %this works, but slow, around 1.5s
..
K = [K MatricaK(NP, NE, r, Kxx, N, h, 1)]; %also works, but slow, around 1.5s
...
end;
我如何才能讓結果反饋快?我發現Parallel Programming on MATLAB to execute 3 different functions at the same time,但沒有速度。
對不起,如果這是一個愚蠢的問題,但爲什麼要這麼快就開始平行呢? – wakjah 2013-03-27 15:34:39
首先,我必須讓我的程序平行進行研究。其次,我只是希望它比順序版本更快。實際上,如果我不考慮獲得結果,它會比序貫(0.24 vs 0.17s)快40%。所以,我想知道,如果有可能快速獲得結果:) – 2013-03-27 15:46:55
令人驚訝的結果!第二次運行時速度是否有所不同(以及是否已經完成任何預先初始化)?另外,'K {:}'也許超出了你能夠有效存儲的內容(在Ram中)?可以通過使用300而不是1000來檢查一次。 – 2013-03-27 15:52:35