フィルターのクリア

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

2 ビュー (過去 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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by