Effacer les filtres
Effacer les filtres

5D array and Out of memory error

2 vues (au cours des 30 derniers jours)
Burak
Burak le 21 Fév 2017
Commenté : Burak le 21 Fév 2017
clc
clear all
theta0=pi/2;
a_0=6e-2;
r0=a_0;
r_d=a_0;
N_R=20;
drho=(r_d)/N_R;
Mphi=30;
dphi2=2*pi/Mphi;
Mtheta=30;
dtheta=pi/Mtheta;
M_phi=120;
dphi0=2*pi/M_phi;
r2=0:drho:r_d;
phi2=0:dphi2:2*pi;
theta2=0:dtheta:pi;
phi0=0:dphi0:2*pi;
xd=zeros(length(r2),length(theta2),length(phi2));
yd=zeros(length(r2),length(theta2),length(phi2));
zd=zeros(length(r2),length(theta2));
x0=r0*sin(theta0)*cos(phi0);
y0=r0*sin(theta0)*sin(phi0);
z0=r0*cos(theta0);
dx=zeros(length(r2),length(theta2),length(phi2),length(phi0));
dy=zeros(length(r2),length(theta2),length(phi2),length(phi0));
dis=zeros(length(r2),length(theta2),length(phi2),length(phi0));
for nr=1:length(r2)
for nt=1:length(theta2)
for mp=1:length(phi2)
xd(nr,nt,mp)=r2(nr)*sin(theta2(nt))*cos(phi2(mp));
yd(nr,nt,mp)=r2(nr)*sin(theta2(nt))*sin(phi2(mp));
zd(nr,nt)=r2(nr)*cos(theta2(nt));
end
end
end
dz=z0-zd;
for mg=1:length(phi0)
dx(:,:,:,mg)=x0(mg)-xd(:,:,:);
dy(:,:,:,mg)=y0(mg)-yd(:,:,:);
end
for nr=1:length(r2)
for nt=1:length(theta2)
for mp=1:length(phi2)
for mg=1:length(phi2)
dis(nr,nt,mp,mg)=sqrt(dx(nr,nt,mp,mg)^2+dy(nr,nt,mp,mg)^2+dz(nr,nt)^2);
end
end
end
nr
end
eps0=(10^-9)/(36*pi);
mu0=4*pi*10^-7;
epsr1=1.;
epsr2=3.45;
mur1=1.;
mur2=1.;
eps1=epsr1*eps0;
sigma=3e-7;
mu1=mur1*mu0;
mu2=mur2*mu0;
freq=8e9:10e6:10e9;
omeg=zeros(1,length(freq));
eps2=zeros(1,length(freq));
kd=zeros(1,length(freq));
for nf=1:length(freq)
omeg(nf)=2*pi*freq(nf);
eps2(nf)=epsr2*eps0-1j*(sigma/omeg(nf));
kd(nf)=omeg(nf)*sqrt(eps2(nf)*mu2);
end
Gxx=zeros(length(r2),length(theta2),length(phi2),length(phi0),length(freq));
for nf=1:length(freq)
Gxx(:,:,:,:,nf)=((3*(((kd(nf)^2).*dis(:,:,:,:).^4).^(-1)))-(3.*1j.*(kd(nf).*(dis(:,:,:,:).^3)).^(-1))-...
(dis(:,:,:,:).^-2)).*(exp(1j*kd(nf).*dis(:,:,:,:)).*(4*pi*dis(:,:,:,:)).^(-1)).*...
(dx(:,:,:,:).^2)+(1.+((kd(nf).*dis(:,:,:,:)).^(-1))-(((kd(nf)^2).*(dis(:,:,:,:)).^2).^(-1))).*...
(exp(1j*kd(nf).*dis(:,:,:,:)).*(4*pi*dis(:,:,:,:)).^(-1));
nf
end
Hi, I need to calculate the Gxx (Dyadic Green's Function) but I got memory error. I don't know how to calculate it easier and I can't decrease the dimensions. I need help, if anyone can help me , I'll appreciate.
Here is my memory.
Maximum possible array: 1763 MB (1.849e+09 bytes) *
Memory available for all arrays: 1763 MB (1.849e+09 bytes) *
Memory used by MATLAB: 4660 MB (4.887e+09 bytes)
Physical Memory (RAM): 4094 MB (4.293e+09 bytes)
* Limited by System Memory (physical + swap file) available.

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Fév 2017
You
Gxx=zeros(length(r2),length(theta2),length(phi2),length(phi0),length(freq));
is requesting 21 by 31 by 31 by 121 by 201 which is 3926576808 bytes of double normally. However, the output is complex, so you need to double that to 7853153616 bytes. You do not have the available memory for that; it is over four times as large as your free memory.
If you have a 32 bit version of MATLAB, then because you "can't decrease the dimensions", you will need to build the array in pieces and write out the pieces to somewhere as you build them.
If you have a 64 bit version of MATLAB, then your best bet is to increase your memory to at least 7912106024 bytes (8 gigabytes); you might need a little more to handle the intermediate results during computation.
On a 64 bit version of MATLAB, you could calculate the array by increasing your operating system swap size, and changing the preference to turn off restricting array sizes: Preferences -> MATLAB -> Workspace -> Limit the array size to a percentage of the ram. Then you would run the code, and wait a day or so for it to finish computing. (If you have the available memory, it would complete in less than a minute.)
What are you going to do with the 7.3 gigabyte array of results on your 4 gigabyte system?
  1 commentaire
Burak
Burak le 21 Fév 2017
I need this for my thesis , and I need to calculate it, thanks for your help and time , I guess I need to increase my memory.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by