誰でも助けることができますか?私はかなり経験豊富な Matlab ユーザーですが、以下のコードの高速化に問題があります。
12 個のコアを使用して、3 つのループすべてを 1 回実行して達成できた最速の時間は、約 200 秒です。実際の関数は最大 720 回呼び出され、このレートでは実行に 40 時間以上かかります。Matlab プロファイラーによると、CPU 時間の大部分は指数関数呼び出しに費やされます。gpuArray を使用してこれを大幅に高速化し、Quadro 4000 グラフィック カードで exp 呼び出しを実行しましたが、ワークステーションにはグラフィック カードが 1 つしかないため、parfor ループが使用されなくなります。誰か助けてもらえますか、またはこのコードは Matlab を使用して達成できる最適に近いですか? 私は openMP を使用して非常に粗雑な C++ 実装を作成しましたが、ほとんど効果がありませんでした。
よろしくお願いします
function SPEEDtest_CPU
% Variable setup:
% - For testing I'll use random variables. These will actually be fed into
% the function for the real version of this code.
sy = 320;
sx = 100;
sz = 32;
A = complex(rand(sy,sx,sz),rand(sy,sx,sz));
B = complex(rand(sy,sx,sz),rand(sy,sx,sz));
C = rand(sy,sx);
D = rand(sy*sx,1);
F = zeros(sy,sx,sz);
x = rand(sy*sx,1);
y = rand(sy*sx,1);
x_ind = (1:sx) - (sx / 2) - 1;
y_ind = (1:sy) - (sy / 2) - 1;
% MAIN LOOPS
% - In the real code this set of three loops will be called ~720 times!
% - Using 12 cores, the fastest I have managed is ~200 seconds for one
% call of this function.
tic
for z = 1 : sz
A_slice = A(:,:,z);
A_slice = A_slice(:);
parfor cx = 1 : sx
for cy = 1 : sy
E = ( x .* x_ind(cx) ) + ( y .* y_ind(cy) ) + ( C(cy,cx) .* D );
F(cy,cx,z) = (B(cy,cx,z) .* exp(-1i .* E))' * A_slice;
end
end
end
toc
end