Efficient way to perform loops of matrix multiplications

1 view (last 30 days)
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 Comments
AA
AA on 27 Jan 2018
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 on 27 Jan 2018
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.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!