Hola,
Estoy trabajando con arreglos de 4 dimensiones y estoy definiendo los arreglos con la funcion malloc. Sin embargo, cuando incremento el tamano de alguno de los elementos, obtengo un segmentation fault pero no logro conseguir el por que. A continuacion pondre como defini mi funcion a ver si alguien puede ayudarme:
De esta manera defino lasa matrices:
double ****Fd, ****Fdnew;
double ****gxFd, ****gxFdnew;
double ****gyFd, ****gyFdnew;
double ****gvxFd, ****gvxFdnew;
double ****gvyFd, ****gvyFdnew;
double ****FIn;
double ****gxFIn;
double ****gyFIn;
double ****gvxFIn;
double ****gvyFIn;
double ****Fo;
double ****Fa, ****gxFa, ****gvxFa;
double ****Fo1;
double ff, ff2, gg, gg2, vv, vv2;
Fd = (double****)malloc(sizeof(double***)*ymax+2);
Fdnew = (double****)malloc(sizeof(double***)*ymax+2);
FIn = (double****)malloc(sizeof(double***)*ymax+2);
Fa = (double****)malloc(sizeof(double***)*ymax+2);
Fo = (double****)malloc(sizeof(double***)*ymax+2);
Fo1 = (double****)malloc(sizeof(double***)*ymax+2);
gxFd = (double****)malloc(sizeof(double***)*ymax+2);
gxFIn = (double****)malloc(sizeof(double***)*ymax+2);
gxFa = (double****)malloc(sizeof(double***)*ymax+2);
gxFdnew = (double****)malloc(sizeof(double***)*ymax+2);
gyFd = (double****)malloc(sizeof(double***)*ymax+2);
gyFIn = (double****)malloc(sizeof(double***)*ymax+2);
gyFdnew = (double****)malloc(sizeof(double***)*ymax+2);
gvxFd = (double****)malloc(sizeof(double***)*ymax+2);
gvxFIn = (double****)malloc(sizeof(double***)*ymax+2);
gvxFdnew = (double****)malloc(sizeof(double***)*ymax+2);
gvyFd = (double****)malloc(sizeof(double***)*ymax+2);
gvyFIn = (double****)malloc(sizeof(double***)*ymax+2);
gvyFdnew = (double****)malloc(sizeof(double***)*ymax+2);
for(i=0;i<ymax+2;i++){
Fd
= (double***)malloc(sizeof(double**)*xmax+2);
Fdnew = (double***)malloc(sizeof(double**)*xmax+2);
Fo = (double***)malloc(sizeof(double**)*xmax+2);
Fo1 = (double***)malloc(sizeof(double**)*xmax+2);
FIn = (double***)malloc(sizeof(double**)*xmax+2);
Fa = (double***)malloc(sizeof(double**)*xmax+2);
gxFd = (double***)malloc(sizeof(double**)*xmax+2);
gxFIn = (double***)malloc(sizeof(double**)*xmax+2);
gxFa = (double***)malloc(sizeof(double**)*xmax+2);
gxFdnew = (double***)malloc(sizeof(double**)*xmax+2);
gyFd = (double***)malloc(sizeof(double**)*xmax+2);
gyFIn = (double***)malloc(sizeof(double**)*xmax+2);
gyFdnew = (double***)malloc(sizeof(double**)*xmax+2);
gvxFd = (double***)malloc(sizeof(double**)*xmax+2);
gvxFIn = (double***)malloc(sizeof(double**)*xmax+2);
gvxFdnew = (double***)malloc(sizeof(double**)*xmax+2);
gvyFd = (double***)malloc(sizeof(double**)*xmax+2);
gvyFIn = (double***)malloc(sizeof(double**)*xmax+2);
gvyFdnew = (double***)malloc(sizeof(double**)*xmax+2);
for(j=0;j<xmax+2;j++){
Fd[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
Fdnew[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
Fo[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
Fo1[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
FIn[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
Fa[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gxFd[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gxFdnew[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gxFIn[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gxFa[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gyFd[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gyFdnew[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gyFIn[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gvxFd[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gvxFdnew[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gvxFIn[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gvyFd[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gvyFdnew[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
gvyFIn[j] = (double**)malloc(sizeof(double*)*(2*Nmax+2));
for(p=0;p<2*Nmax+2;p++){
Fd[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
Fdnew[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
Fo[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
Fo1[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
FIn[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
Fa[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gxFd[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gxFdnew[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gxFIn[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gxFa[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gyFd[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gyFdnew[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gyFIn[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gvxFd[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gvxFdnew[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gvxFIn[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gvyFd[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gvyFdnew[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
gvyFIn[j][p] = (double*)malloc(sizeof(double)*(2*Mmax+2));
for(q=0;q<2*Mmax+2;q++){
Fd[j][p][q] = 0.0;
Fdnew[j][p][q] = 0.0;
Fo[j][p][q] = 0.0;
Fo1[j][p][q] = 0.0;
FIn[j][p][q] = 0.0;
Fa[j][p][q] = 0.0;
gxFd[j][p][q] = 0.0;
gxFdnew[j][p][q] = 0.0;
gxFIn[j][p][q] = 0.0;
gxFa[j][p][q] = 0.0;
gyFd[j][p][q] = 0.0;
gyFdnew[j][p][q] = 0.0;
gyFIn[j][p][q] = 0.0;
gvxFd[j][p][q] = 0.0;
gvxFdnew[j][p][q] = 0.0;
gvxFIn[j][p][q] = 0.0;
gvyFd[j][p][q] = 0.0;
gvyFdnew[j][p][q] = 0.0;
gvyFIn[j][p][q] = 0.0;
}
}
}
}
Y esto las uso en una funcion como la siguiente:
void Init(double**** Fd, double**** gxFd, double****gyFd, double**** gvxFd, double**** gvyFd, double**** FIn,
double**** gxFIn, double**** gyFIn, double**** gvxFIn, double**** gvyFIn, double**** Fo, double****Fo1,
double* Vx, double* Vy, double nx)
{
int i, j, p, q;
for(i=0; i<=xmax+1; i++){ //Inicialmente lleno TODO x
for(j=0; j<=ymax+1; j++){
for(p=0; p<=2*Nmax+1; p++){
for(q=0; q<=2*Mmax+1; q++){
Fo[j][p][q]= nx*(me/(2.0*Pi*k*Tg))*exp(-(me*((Vx[p]*Vx[p])+(Vy[q]*Vy[q]))/(2.0*k*Tg)));
Fo1[j][p][q]= nx*(me/(2.0*Pi*k*Tg))*exp(-(me*(((Vx[p])*(Vx[p]))+(Vy[q]*Vy[q]))/(2.0*k*Tg))); //Fo desplazado pero tg
Fd[j][p][q]= nx*(me/(2.0*Pi*k*Tei))*exp(-(me*(((Vx[p]-Vx[33])*(Vx[p]-Vx[33]))+(Vy[q]*Vy[q]))/(2.0*k*Tei)));
gxFd[j][p][q]= 0.0;
gyFd[j][p][q]= 0.0;
gvxFd[j][p][q]= -((2.0*me*((Vx[p]-Vx[33])))/(k*Tei))*nx*sqrt(me/(2.0*Pi*k*Tei))*exp(-(me*(((Vx[p]-Vx[33])*(Vx[p]-Vx[33]))+(Vy[q]*Vy[q]))/(2.0*k*Tei)));
gvyFd[j][p][q]= -((2.0*me*(Vy[q]))/(k*Tei))*nx*sqrt(me/(2.0*Pi*k*Tei))*exp(-(me*(((Vx[p]-Vx[33])*(Vx[p]-Vx[33]))+(Vy[q]*Vy[q]))/(2.0*k*Tei)));
//Injection Function at the Inlet of the channel
FIn[j][p][q]= nx*(me/(2.0*Pi*k*Tei))*exp(-(me*(((Vx[p]-Vx[33])*(Vx[p]-Vx[33]))+(Vy[q]*Vy[q]))/(2.0*k*Tei)));
gxFIn[j][p][q]= 0.0;
gyFIn[j][p][q]= 0.0;
gvxFIn[j][p][q]= -((2.0*me*((Vx[p]-Vx[33])))/(k*Tei))*nx*sqrt(me/(2.0*Pi*k*Tei))*exp(-(me*(((Vx[p]-Vx[33])*(Vx[p]-Vx[33]))+(Vy[q]*Vy[q]))/(2.0*k*Tei)));
gvyFIn[j][p][q]= -((2.0*me*(Vy[q]))/(k*Tei))*nx*sqrt(me/(2.0*Pi*k*Tei))*exp(-(me*(((Vx[p]-Vx[33])*(Vx[p]-Vx[33]))+(Vy[q]*Vy[q]))/(2.0*k*Tei)));//*/
}
}
}
}
}
Donde:
#define xmax 70
#define ymax 50
#define Nmax 30
#define Mmax 30
Se que es un poco tedioso. El programa funciona bien si xmax vale 50 o incluso con 60 funciona. El error se mantiene aun usando una computadora de mayor capacidad asi que no creo que ese sea el problema.