Community
cancel
Showing results for 
Search instead for 
Did you mean: 
pinkiee
Beginner
24 Views

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=(double **) malloc((unsigned) ((nyh-nyl)+1)*sizeof(double*));
if (!m) nrerror("allocation failure 2 in matrix()");
m -= 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=(double *) malloc((unsigned) (nzh-nzl+1)*sizeof(double));
if (!m) nrerror("allocation failure 3 in matrix()");
m -= nzl;
}
}

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

Thank you very much for your help!

Best regards,
Rae
0 Kudos
0 Replies
Reply