Need help on memory allocation problem

Need help on memory allocation problem

Dear Sir/Madam,

I am a student from University of Connecticut. I am now using "SGI Altix 3700 BX2 system". The system contains 64 Intel Itanium 2 processors and 64 GB memory. I do C program on it. Now I met some problem on my project(The program can run in personal computer correctly). The problem is memory allocation and it seems caused by memory alignment.

Now I copy part of my program to you (the error part). I do not know I can explain what happened, let me try.

I use this subroutine to allocate a 3D matrix space for my algorithm. While it runs to the line marked by /*error*/, it can run through until i=0, j=20. Then the error information shows up:
"Program received signal SIGSEGV, Segmentation fault.
0x20000000001d00c1 in _int_malloc () from /lib/tls/libc.so.6.1"

The program is:

/**********************************************************************************************/
double ***AllocMatrix1(short nxl,short nxh, short nyl,short nyh, short nzl,short nzh)
{
short i,j,k;
double *** m;

m=(double ***) malloc((unsigned) ((nxh-nxl)+1)*sizeof(double**));
if (!m) nrerror("allocation failure 1 in matrix()");
m -= nxl;

for(i=nxl;i<=nxh;i++) {
m[i]=(double **) malloc((unsigned) ((nyh-nyl)+1)*sizeof(double*));
if (!m[i]) nrerror("allocation failure 2 in matrix()");
m[i] -= nyl;

for(j=nyl;j<=nyh;j++) {

/**The problem happened in this loop while j=20, (now i=0),

in this program the maxmum number is nzh=700***/

/*error*/ m[i][j]=(double *) malloc((unsigned) (nzh-nzl+1)*sizeof(double));
if (!m[i][j]) nrerror("allocation failure 3 in matrix()");
m[i][j] -= nzl;
}
}

for(i=nxl;i<=nxh;i++)
for(j=nyl;j<=nyh;j++)
for(k=nzl;k<=nzh;k++) m[i][j][k] = 0.0;
return m;
}

Thank you very much for your help!

Best regards,
Rae

1 contribution / 0 nouveau(x)
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.