Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Muhannad
Muhannad el 15 de Dic. de 2015
Editada: Kirby Fears el 17 de Dic. de 2015
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 comentario
Kirby Fears
Kirby Fears el 17 de Dic. de 2015
Editada: Kirby Fears el 17 de Dic. de 2015
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.

Iniciar sesión para comentar.

Respuestas (1)

Krishnan Ramkumar
Krishnan Ramkumar el 17 de Dic. de 2015
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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by