c - EXC_BAD_ACCESS, Could not access memory -


i have code doing numerical optimization (large program). in gdb exits with

program received signal exc_bad_access, not access memory. reason: 13 @ address: 0x0000000000000000 [switching process 8673 thread 0x1203] 0x00007fff95d2a9fb in small_malloc_from_free_list () 

during backtrace told following line contains error, can't figure out what's wrong.

177     u  = calloc(cols*cols,sizeof(double)); 

the code containing line is

int fcn_invxx(double *x, int rows, int cols, double *invxx) {     //---------------------------------------------------------------     // declarations     //---------------------------------------------------------------      // counters , info     int i, j, info;      // upper triangular placeholder, u, , x'x     double *u, *xx;      // indicator upper triangular     char s;      // alpha , beta matrix multiplication - see dgemm documentation     double alpha, beta;       //---------------------------------------------------------------     // memory allocation     //---------------------------------------------------------------     u  = calloc(cols*cols,sizeof(double));     xx = calloc(cols*cols,sizeof(double));       //---------------------------------------------------------------     // compute inverse of x'x     //---------------------------------------------------------------     alpha = 1.0;     beta  = 0.0;      // x'x     cblas_dgemm(cblascolmajor, cblastrans, cblasnotrans, cols, cols, rows, alpha, x, rows, x, rows, beta, xx, cols);     // cblascolmajor means data ordered in columns first, if x 4x4, x[0] , x[1] first column     // cblastrans means matrix should transposed before multiplication. here first matrix transposed     // cblasnotrans means matrix should not transposed. here second matrix not transposed     // x first matrix, , here, second     // xx stores product      (i = 0; < cols*cols; i++)     {         u[i] = xx[i];     }      // upper cholesky factorization     s = 'u'; // upper     dpotrf_(&s, &cols, u, &cols, &info);     // info = lapacke_dpotrf(lapack_col_major, s, cols, u, cols);      (i = 0; < cols*cols; i++)     {         invxx[i] = u[i];     }       // inverse     dpotri_(&s, &cols, invxx, &cols, &info);     // info = lapacke_dpotri(lapack_col_major, s, cols, invxx, cols);      (i = 0; < cols; i++)     {         (j = 0; j < cols; j++)         {             if (i > j)             {                 invxx[i + j * cols] = invxx[j + * cols];             }         }     }       //---------------------------------------------------------------     // free memory     //---------------------------------------------------------------     free(u);     free(xx);      return info;  } 

hope can help.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -