1

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.

0

1 Answer 1

2

You can't send pointers to other processes with MPI. Well, technically you can, but because each process has its own memory space and addressing, a pointer that was valid on one process will most likely point to invalid memory on another. Anyway, you want to send the data that the pointer is pointing to, not the pointer itself.

See this question: Creating an MPI_Datatype for a structure containing pointers

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for your answer. In the link that you sent me, I actually want to send an array of that kind of structure, not only one element...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.