out of memory error

6 ビュー (過去 30 日間)
Zahra Kamali
Zahra Kamali 2022 年 6 月 20 日
コメント済み: Sam Chak 2022 年 6 月 22 日
hello,
I wonder if you could help me with my codes please
I need to make a big matrix (e.g. T= zeros(1e8,27)) but get out of memory error and I cant go further 9.5e7.
however, I need to go even e20. what would be the best way to solve this issue.
thanks
  6 件のコメント
Zahra Kamali
Zahra Kamali 2022 年 6 月 21 日
I am sorry, I changed the distance to be more understandable but didnt change any other places.
here is the final one.
I wonder if you could take a look at it once more. thanks
clc
clear
close all
%% medium 2
node_num = 15;
h= 2.8; %convection coefficient, W/m2.K
ka = 1.7; %thermalconductivity of aggregate, W/mK
Ra=1.33e-3; %the whole distance from the surface to the center, m
dn=Ra/node_num; %
rhoa = 910; %kg/m^3
cpa = 900; % J/kg.K
aa=ka/cpa/rhoa; %thermal difussivity, m2/s
Bia=h*dn/ka;
Foa=1/(2*(1+Bia));
dpa=Foa*dn^2/aa;
Foa= aa*dpa/dn^2;
%% medium 1
kb =.165;
cpb = 2500;% J/kg.K
rhob = 910;%kg/m^3
ab=kb/cpb/rhob;
Bib=h*dn/kb;
Fob=1/(2*(1+Bib));
dpb=Fob*dn^2/ab;
Fob= ab*dpa/dn^2;
dp=min(dpa,dpb);%dt, s
%% calculation
T= zeros(9.5e7,node_num);
[p,n] = size(T);
G=p/100;
TT=zeros(G,n);
Tinf= -21;
T(1,:)=25; %°c
for P= 2:p
T(P,1)= (2*h*dp*(Tinf-T(P-1,1))/rhob*cpb*(dn))+(2*ab*dp*(T(P-1,2)-T(P-1,1))/((dn)^2))+T(P-1,1);
for N = 2:4
T(P,N)= Fob*(T(P-1,N+1)+T(P-1,N-1)-2*T(P-1,N))+T(P-1,N);
end
for N=5:n-1
T(P,N)= Foa*(T(P-1,N+1)+T(P-1,N-1)-2*T(P-1,N))+T(P-1,N);
end
T(P,end)=Foa*2*(T(P-1,n-1)-T(P-1,end))+(T(P-1,end));
end
for P=1:p
if mod(P,100) ==0
for N=1:15
TT(P/100,N)=T(P,N);
end
end
end
%% plot T vs. Distance
vec_pos = 0:dn:(node_num-1)*dn;
vec_pos = flip(vec_pos);
% plot (0:dn:24*dn,T(1,:));
% X = TEST{5000};
% T (6000,:) = X(end,:);
subplot(2,2,1)
plot (vec_pos*1e3,T(3e4,:));hold on
line([1 1],[24.5 24.6],'linestyle','--','color','k')
legend('57 s'); xlabel('Distance, mm')
ylabel('Temperature, °c')
subplot(2,2,2)
plot (vec_pos*1e3,T(17e4,:));hold on
line([1 1],[22.4 22.5],'linestyle','--','color','k')
legend('5 min'); xlabel('Distance, mm')
ylabel('Temperature, °c')
subplot(2,2,3)
plot (vec_pos*1e3,T(167e4,:));hold on
line([1 1],[5.3 5.4],'linestyle','--','color','k')
legend('52 min'); xlabel('Distance, mm')
ylabel('Temperature, °c')
subplot(2,2,4)
plot (vec_pos*1e3,T(end,:));hold on
line([1 1],[-20.9 -21.1],'linestyle','--','color','k')
legend('50 h'); xlabel('Distance, mm')
ylabel('Temperature, °c')
sgtitle ('Temperature profile for 2mm-diameter aggregate in various times')
Sam Chak
Sam Chak 2022 年 6 月 22 日
How long did your code take to run in R2022a?
Unsure if it works, but you can try something like this
T= sparse(9.5e4, node_num);
[p, n] = size(T);
G = p/100;
TT = sparse(G, n);

サインインしてコメントする。

回答 (3 件)

John D'Errico
John D'Errico 2022 年 6 月 20 日
編集済み: John D'Errico 2022 年 6 月 20 日
Um, 1e20 rows? Seriously? Do you have that much memory? Clearly not, since your computer is throwing up at an 1e8 by 27 array. Even that array requires a large chunk of RAM. Remember that every double precision element uses 8 bytes of memory.
1e8*27*8/1e9
ans = 21.6000
So the simple array you tried to allocate needs roughly 21.6 gigabytes of RAM. While I have twice that much on my computer, even mine would probably fail to work with such an array, because almost anything you do will often make copies for whatever purpose you need. A simple rule of thumb is to never make an array that is more than say 1/3 of the RAM you have.
But to make arrays that are significantly larger than that? BE SERIOUS. Do you have
1e20*27*8/1e9
ans = 2.1600e+13
So 21 trillion gigabytes of RAM? Again, to be careful, you probably at least want 3 times that to be conservative. Lets see...
1024 Gigabytes = 1 Terabyte
1024 Terabytes = 1 Petabyte
1024 Petabytes = 1 Exabyte
1024 Exabyte = 1 Yottabyte
So you need roughly 21 Yottabytes of RAM. There are few computers in the word with that much memory installed. I'd be willing to bet I can count the number of such machines on the fingers of one foot.
The problem with computers is people think they are infinitely large, infinitely fast. People get spoiled. They can solve a small problem, so what the heck, I'll just make a much larger problem. And then they get upset when they run out of memory. A simple truism about computing:
Computing problems always expand to be just a bit larger than any computer you can find.
I'm sorry, but you can't do what you want, at least as you want to solve it. At least not until you buy that quantum computing machine that Starfleet command sells. The problem there is the shipping. They need to send it from the future, so the shipping costs tend to be really high. Of course, you can contact the borg since they ship everything for free, but do you really want the borg to be visiting your home or place of work?
Far better is to re-think your problem. Good mathematics, good numerical methods is often the solution to solving a problem that is too difficult to handle by brute force.

Walter Roberson
Walter Roberson 2022 年 6 月 20 日
編集済み: Walter Roberson 2022 年 6 月 21 日
IBM has a 120 petabyte drive. That is about 1.2e17 bytes.
The desired array is 18 million times larger.
In some cases, you can use Tall Arrays, but you have to have backing drive space for that, and we can be very certain that you do not have access to that much disk space.

Steven Lord
Steven Lord 2022 年 6 月 21 日
The maximum number of rows you can have in a matrix in MATLAB is the second output of the computer function, and you're unlikely to have enough memory to get close to that unless you create your matrix as a sparse matrix (which is possible because you're trying to create a tall, thin matrix.)
[~, maxsize] = computer
maxsize = 2.8147e+14
A = sparse(maxsize, 27)
A =
All zero sparse: 281474976710655×27
B = sparse(maxsize + eps(maxsize), 27)
Error using sparse
Sparse matrix sizes must be nonnegative integer scalars less than MAXSIZE as defined by COMPUTER. Use HELP COMPUTER for more details.

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by