So I have this loop here:
/* loop */
omp_set_dynamic(0);
#pragma omp parallel num_threads(1)
#pragma omp for ordered private(iterationPoints, normalizedPoints, grid)
for(iterations = maxIter; iterations >= minIter; iterations -= stepSizeIter){
/* calculate iterationPoints */
iterationPoints = (double **) malloc(iterations *sizeof(double *));
int i;
for(i = 0; i < iterations; i++){
iterationPoints[i] = (double *) malloc(DIMS *sizeof(double));
}
calcuTraj(iterationPoints,a,b,c,x,y,z,h,iterations, bounds, (iterations == maxIter));
/* normalize Data */
normalizedPoints = (double **) malloc(iterations *sizeof(double *));
for(i = 0; i < iterations; i++){
normalizedPoints[i] = (double *) malloc(DIMS * sizeof(double));
}
#pragma omp ordered
printf("%d %f %f %f %f %f %f\n",iterations,bounds[0][0] ,bounds[0][1], bounds[1][0], bounds[1][1], bounds[2][0], bounds[2][1]);
normalize(iterationPoints, normalizedPoints, bounds, iterations);
/* creating 3D Array for the grid of boxes in space*/
/* setting minimum for sidelength of the grid */
double minGridSideLength = 1;
/* calculating array size */
int boxesPerDim = ceil(minGridSideLength/epsion) +1;
//printf("boxesPerDim: %d \n", boxesPerDim);
/* create grid array */
grid = (bool ***) malloc(boxesPerDim *sizeof(bool **));
int j_X, j_Y;
for(j_X = 0; j_X < boxesPerDim; j_X++){
grid[j_X] = (bool **) malloc(boxesPerDim *sizeof(bool *));
for(j_Y = 0; j_Y < boxesPerDim; j_Y++){
grid[j_X][j_Y] = (bool *) calloc(boxesPerDim,sizeof(bool *));
}
}
/* count hitted boxes */
int boxesHit = boxCount(normalizedPoints, grid, iterations, epsion, boxesPerDim);
#pragma omp ordered
fprintf(file,"%d %d\n", iterations, boxesHit);
//printf("%d \n",boxesHit);
/* free storage */
free(iterationPoints);
free(grid);
free(normalizedPoints);
}
I set the number of threads to 1, so there is no multithreading which would lead to an exploding ram for high iterations. So in this configuration the loop would run step after step. the function 'calculatedTraj(..)' calculates the 'iterationpoints'. If I run it from minIter = 20*10^6 to maxIter = 50*10^6 iterations with the stepsize = 10*10^6 my ram is exploding and the process is getting killed. But if I run the program for minIter = maxIter = 50*10^6 it is working and the ram is fine. So why it is not possible to do it with a for loop, because at the end of every loop part I am freeing the allocated memory, so why is the ram exploding then ?