I have my model in C which runs an evolutionary process, but once I input too large a population or too long an evolutionary period, it fails. For example, I can evolve a (constant) population of 20 individuals over 50 years in 14 seconds, but 30 individuals won't run. The error message is cygwin_exceptionpen_stackdumpfile: Dumping stack ... , which I believe is to do with memory allocation, but I tried using pflags to assign up to 4GB and it still doesn't run.
The code is fairly long, but a simplified version is below (i know the functions all run as intended)
Code:
int main(){
//structs initialised, controls like population size loaded
//output file opened
// initialise with artificial 'chromosome' using random number generation for each of N 'genes'
Initialise(N, ctrl.Population, &chrom);
for (int Generation = 1; Generation <= ctrl.Generations; Generation++){
for (int Individual = 1; Individual <= ctrl.Population; Individual++){
//calls function to assess fitness
} //END OF INDIVIDUAL LOOP
if(Generation < ctrl.Generations){
Selection(Generation, ctrl.Population, ctrl.MutationRate, N, &chrom);
}
} // END OF GENERATION LOOP
printf("Finished sim!");
} /// END OF MAIN FUNCTION
void Initialise(int N, int Population, chrom_struct *chrom)
{
double rand_double(); /* 0.0 to 1.0, unif. dist. */
chrom->Genes = (double **)malloc(Population * sizeof(double *));
for(int i = 0; i < N; i++){
chrom->Genes[i] = (double *)malloc(N * sizeof(double));
}
chrom->Fitness = (double *)malloc(Population * sizeof(double));
struct timeval tm;
gettimeofday(&tm, NULL);
srandom(tm.tv_sec + tm.tv_usec * 1000000ul);
for(int Individual = 1; Individual <= Population; Individual++){
chrom->Genes[Individual][0] = 0;
for(int i = 1; i<= N; i++){
chrom->Genes[Individual][i] = rand_double();
}
}
} // END OF INITIALISE
double rand_double(){
struct timeval tm;
gettimeofday(&tm, NULL);
srandom(tm.tv_sec + tm.tv_usec * 1000000ul);
return random()/(double)RAND_MAX;
}
void Selection(int Generation, int Population, double MutationRate, int N, chrom_struct *chrom)
{
// copies current generation into parental array
double **Parents;
Parents = (double **)malloc(Population * sizeof(double *));
for(int i = 0; i < soil->N; i++){
Parents[i] = (double *)malloc(N * sizeof(double));
}
for(int Individual = 1; Individual <= Population; Individual++){
for(int i = 1; i<= N; i++){
Parents[Individual][i] = chrom->Genes[Individual][i];
}
}
// ranks individuals in current genes array depending on fitness
// copies fittest individual over to parental array directly
// for rest of pop, fills parental array from top half of individuals
// overwrites genes array using randomly selected parents, recombines, mutates
} // END OF SELECTION FUNCTION
I'm trying to write a makefile etc to run it on the university's supercomputing cluster, but it's slow progress since I've never done it before. I was wondering if there's a way to get it to run on my laptop? Even 100 individuals x 100 generations would be fine.
Thanks for your help!