Sementation fault - memory problem?

Im with a problem to run a C program, maybe you help me to find the solution.
Its a simple code, but uses a lot of memory. One matrix for example have 10 million elements. The program runs normally when i reduce the size of some of that matrices, but in the wanted size doesnt work. As it run sometimes, i think the problem is memory.
I have used:

% ulimit -s unlimited

and it appears to help a little, but didnt solve the problem. Had also tried to use malloc and free to free some memory, but had no effect. I know that much bigger programs run in this computer, so i really need help because i dont know what to do.

below the variables declaration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#define T_MIN 5000
#define T_MAX 15000
#define E_MIN 0.0
#define E_MAX 0.1
#define E_NUM 100
#define N_MAPS 1000

int main(void){

int tempo, map, e, i, start, end;
int y_maxtab[N_MAPS][T_MAX/100], k[N_MAPS], n_ymax[N_MAPS];
double eps, coup, step = (double)(E_MAX-E_MIN)/(double)(E_NUM-1);
double mean, new_x;
double alfa[N_MAPS], x0[N_MAPS], y0[N_MAPS];
double x_dat[N_MAPS], y_dat[N_MAPS][T_MAX];
double rnmed_tab[2][E_NUM], rn_tab[T_MAX];
double mcos, msin, fi,deno;

the y_dat matrix is the biggest here.

p.s.: normally i use icc to compile my programs, but in gcc i get the same errors. i had also tried to use gdb, but didnt discover nothing.
When you say you tried to use malloc and free, how did you define your 2D arrays? You need to make them like the following:

1
2
3
4
double** y_dat = (double**) malloc( sizeof(double*) * N_MAPS );
for( i = 0; i < N_MAPS; i++ ) {
    y_dat[i] = (double*) malloc( sizeof(double) * T_MAX );
}


Using malloc will allocate memory on the heap. The way you are doing it now is allocating memory on the stack which is very limited.
Topic archived. No new replies allowed.