I have got the following C structure:
typedef struct chromosome{
int *genes;
float cout;
}chromosome;
I would like to send an array of chromosomes using MPI_Send. I've defined an MPI_CHROMOSOME data type like this:
MPI_Datatype MPI_CHROMOSOME;
MPI_Datatype TYPES_ELEMENTAIRES[2] = {MPI_INT, MPI_FLOAT};
int blocklengths[2] = {NB_SOMMETS,1}; //NB_SOMMET is a known integer value at this point (number of elements of the "genes" array)
MPI_Aint offsets[2];
offsets[0] = offsetof(chromosome, genes);
offsets[1] = offsetof(chromosome, cout);
MPI_Type_create_struct(2, blocklengths, offsets, TYPES_ELEMENTAIRES, &MPI_CHROMOSOME);
MPI_Type_commit(&MPI_CHROMOSOME);
Then I tried to send an array of chromosomes:
chromosome *sub_pop = malloc(taille_sub_pop*sizeof(chromosome));//taille_sub_pop is a known integer value
/* ... Fills sub_pop with chromosomes ...*/
MPI_Send(sub_pop,taille_sub_pop,MPI_CHROMOSOME, 1, 3, MPI_COMM_WORLD);
... But I got an error (BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES... Exit Code 139... YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)).
How can I send this array properly ? I would appreciate your help. Thanks a lot.