RAM crash because of multiple looping, how to solve the problem?

조회 수: 1 (최근 30일)
Muhannad
Muhannad 2015년 12월 15일
편집: Kirby Fears 2015년 12월 17일
l = find(lamda >= fmin & lamda <= fmax);
lam = lamda(l);
n = length(lam);
C = zeros(n,n,n,n,n);
C = zeros(n,n,n,n,n) + inf;
for i = 1:n
for ii = 1:i-1
for iii = 1:ii-1
for iv = 1:iii-1
for v = 1:iv-1
A = data(l([i ii iii iv iv]), 1:3);
C(i,ii,iii, iv, v) = cond(A);
vif(i,ii,iii,iv,v) = max(diag(inv(A'*A)));
end
end
end
end
end
  댓글 수: 1
Kirby Fears
Kirby Fears 2015년 12월 17일
편집: Kirby Fears 2015년 12월 17일
Muhannad,
It looks like you are initializing C twice but not initializing vif at all.
C = zeros(n,n,n,n,n);
C = zeros(n,n,n,n,n) + inf;
You should initialize vif also:
C = zeros(n,n,n,n,n); % add Inf here if you want
vif = zeros(n,n,n,n,n);
This will pre-allocate memory for vif as well, which will help the speed of your run.
These initialization steps are going to cause a RAM crash if n is too large. For example, if n is 100, C and vif will each have 100^5 = 10 billion elements.
The loops themselves are not crashing your RAM. The size of C and vif (based on n) are the problem.

댓글을 달려면 로그인하십시오.

답변 (1개)

Krishnan Ramkumar
Krishnan Ramkumar 2015년 12월 17일
Hi Muhannad,
Can you please tell me the problem that you would like to solve so that we can see if there is any optimized way to resolve the issue . For large values of n, it is expected to use high memory usage and also depends on the number of applications that are used at that point of time. Also can you tell me the system configuration that you are using?
Regards,
Krishnan

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by