Efficient way to perform loops of matrix multiplications

1 次查看(过去 30 天)
Hello,
I have an implementation that involves multiplying matrices, summing them up, and storing them. It goes like this,
A = 0;
for i=1:1225
% Load operator A_i of size NxN
A_i = load('A_i.mat');
% z_i is some variable of size Nx1 that I compute in this loop
% x is some variable of size Nx1 calculated above this loop
% I have to perform some operations like these two
y_i = A_i*(z_i + x);
A = A + A_i*A_i'
end
My problem is the large amount of simulation time being consumed by the above code. Even when the operations inside the loop are efficient (let's say ~0.01mins), the entire looped implementation still consumes about ~12-13mins. Can somebody please help me out and suggest an efficient way to do this? Thanks so much!
  7 个评论
AA
AA 2018-1-27
Hello,
Thanks for your response. Yes, in my case, parfor is not able to help. As you rightly pointed out, the time taken to start the pool overwhelms any time savings thereafter. Unfortunately, I faced the same problem while working on gpuArrays. The time taken for transferring the data is large, and shows no overall improvement. I am currently stuck and have no good way to get it done within some practical time.
Thanks for your help again!
David Goodmanson
David Goodmanson 2018-1-27
Hi AA,
If N stays constant, when you compute them offline could you stack them into sets of 3d arrays, no one of which is large enough to overrun RAM? That way you would have to load stuff a lot less often.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by