tall array introduces significant overhead if I call gather() at every iteration in a loop
Show older comments
I want to figure out the spread of the invariants of a symmetric 3x3 matrix using the code below
%input
nPts = 2;
ub = 2.0;
%create combinations of the SIX independent components
comb = combinations(linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts)).Variables;
%results array
res = zeros(nPts^6, 2);
tic
for idx=1:nPts^6
C = [comb(idx,1), comb(idx,4), comb(idx,5);
comb(idx,4), comb(idx,2), comb(idx,6);
comb(idx,5), comb(idx,6), comb(idx,3)];
res(idx, :) = [trace(C), trace(inv(C))];
end
toc
%creater scatter plot
scatter(res(:,1), res(:,2));
This works, however, I want to set nPts=60 for instance. So I will definitely end up with array sizes that do not fit into memory of my local machine anymore.
As a workaround, I thought storing comb as tall array
comb = tall( combinations(linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts), ...
linspace(0.1, ub, nPts)).Variables );
and then
C = gather(C)
res(idx, :) = [trace(C), trace(inv(C))];
in the loop.
However, this code takes 170 seconds on my screen for just 2^6 = 64 combinations.
So is tall array not appropriate in my application or do I just use it not correctly?
Accepted Answer
More Answers (0)
Categories
Find more on Timetables 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!