This is the outline of my code.
int main()
{
int i,j,k,igen;
int size =4;
int chrom[11][4];
nchrom=10;
k=1;
int nprocs,pid,namelen;
int rbuf[4];
int fitness_arr[11];
int fitness[1]={0};
char processor_name[80];
MPI::Init();
nprocs=MPI::COMM_WORLD.Get_size();
pid=MPI::COMM_WORLD.Get_rank();
if(pid==0)
master(chrs,chrom);
for(igen=0;igen<10;igen++)
{
MPI_Get_processor_name(processor_name,&namelen);
MPI_Scatter(chrom,4,MPI_INT,&rbuf,4,MPI_INT,0,MPI_COMM_WORLD);
if(pid!=0)
fitness= servant(rbuf,size);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Gather(&fitness,1, MPI_INT, &fitness_arr,1, MPI_INT,
0,MPI_COMM_WORLD);
if(pid==0)
{
for(i=1;i<11;i++)
{
cout<<"Fitness: "<<fitness_arr[i]<<endl;
chrs[k].get_fit(fitness_arr[i]);
k++;
}
order_chrom(chrs,nchrom);
copy_arr_chrom(chrs,chrom);
}
}
MPI::Finalize();
delete []chrs;
cout<<"Complete"<<endl;
return 0;
}
When the loop is entered for the first time everything works fine.
But for the next run the process dies.I could not figure out the
problem.
Thanks
|