Possible Duplicate:
Max Array Size in C
My question is: Does Code::blocks have a max number of iterations for a loop?
I am running a monte carlo and I would like to run a million particles through a for loop. But the max it seems to go without crashing is 110000.
Thanks!
Some more info:
I am using a random number generator seeded by time:
srand(time(NULL));
I then want to create a million particles (random)
for(k=0; k<M; k++){
R[k] = rand()*(1)/(double)RAND_MAX;
z[k] = -log(1 - R[k])/(1000*U);
where M = Num/10 (I want to #define N 1000000)
This is the only thing I can think of that is creating the problem?
Here is an example code that will not work.
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
int main(){
srand(time(NULL));
int j=0;
int i;
double A[1000000];
for(i=0;i<1000000;i++){
A[i] = rand()*(1.0)/(double)RAND_MAX;
if (A[i] == 1.0){
printf("Wow!\n");
}
}
return 0;
}
Could this be due to my settings of Code::blocks by any chance?
Edit: this is because the default maximum stack size is 1MB on Windows (but 8MB on Linux).
I don’t have a final answer, but I do know:
a) It runs fine from a Linux command-line.
b) Valgrind gives tons of errors of this form:
c) The errors are clearly related to reading and writing from the array. This simpler version of the program does not cause any Valgrind errors: