Matrix multiplication result - where does it go?
이전 댓글 표시
I've been curious, after various recent observations, about whether matrix multiplication always allocates fresh memory for its output. For example, suppose I do something like
A(:,1)=B*x;
Is this equivalent to
z=B*x; %memory allocated here
A(:,1)=z;
Or, does the output of B*x get directly generated in the memory locations occupied by A(:,1)? Obviously, the latter would be more efficient, but I wasn't sure how it worked. I know for example that this
A(1,:)=B(1,:)*x;
is equivalent to
z=B(1,:); %memory allocated here
A(1,:)=z*x;
so obviously not everything is as well optimized as it could be.
댓글 수: 1
I used Process Lasso to set a watchdog on MATLAB memory usage at 2GB.
In the following, n=1.36e4 is the size needed for building a matrix that will put MATLAB virt. mem usage right below 2GB on my system.
This is OK (usage ~1.8GB):
>> clear all ; n = 1.36e4 ; v = ones(n,1) ; A = zeros(n) ;
This is also OK (usage ~1.8GB):
>> clear all ; n = 1.36e4 ; v = ones(n,1) ; A = v * v.' ;
This is killed:
>> clear all ; n = 1.36e4 ; v = ones(n,1) ; A = zeros(n) ; A = v * v.' ;
I could perform more tests that fit better your initial question, but I wanted to start with something that would generate a brutal increase in memory usage if temp. memory was allocated.. which seems to be the case!
(PS: but not before tomorrow, because tonight I have to perform computations using a.. an Excel spreadsheet! ;-/)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!