0

I've created a structure like this:

typedef struct point_struct { int x, y; }point;

And in main i defined it like this:

int num_item =2;
int blocklengths[2] = {1,1};
MPI_Datatype types[2] = {MPI_INT, MPI_INT};
MPI_Datatype mpi_point_type;
MPI_Aint offsets[2];
offsets[0] = offsetof(point, x);
offsets[1] = offsetof(point, y);
MPI_Type_create_struct(num_item, blocklengths, offsets, types, &mpi_point_type );
MPI_Type_commit(&mpi_point_type);

I've scattered it between processes and call a recursive function to do something.
Mpirun throws back this error:

Process received signal. Signal: Segmentation fault (11) Signal code: Address not mapped (1) Failing at address: 0x7fffb9be57dc mpirun noticed that process rank 3 with PID 2924 on node MY_COMPUTER exited on signal 11 (Segmentation fault).

I also malloc my array of structure this way:

 point *p_x = (struct point_struct*)malloc(n*sizeof(struct point_struct));

Do i malloced it wrong? or whats the problem?
Thanks for your time.

Shahriar.M
  • 818
  • 1
  • 11
  • 24
  • Have you read [about cast of `malloc`](http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc/605858#605858)? – Ilya Sep 04 '15 at 14:38
  • what should i know? whats wring with my code? – Shahriar.M Sep 04 '15 at 15:03
  • You don't want to cast malloc since it is a void * and can easily be assigned to any pointer. Read the link above more information about that. But that shouldn't be the error in your code, it's just good practice. – Yashwanth Sep 04 '15 at 15:15
  • Thanks for practice suggestion but i should submit my project before tomorrow night. I'll do that another time @yashwanth – Shahriar.M Sep 04 '15 at 15:46
  • @francis really i used this question for my structure definition : http://stackoverflow.com/questions/9864510/struct-serialization-in-c-and-transfer-over-mpi i dont know what is this function implementation – Shahriar.M Sep 04 '15 at 19:07
  • Sorry : `offsetof()` is part of stddef and I cannot see any problem in the code you posted. Could you post the code related to the `mpi_scatter()` ? Did you allocate memory for the receive buffer on all processes ? The error can also be created by a wrong `sendcount` or a wrong `recvcount`... More code is needed to answer your question ! – francis Sep 05 '15 at 09:01
  • @francis: actually i've found what was my problem. but im blocked and i cant post answer to it. what should i do? i changed my `malloc` code and it worked. here is my new `malloc` : `struct point_struct *p_x = (struct point_struct*)malloc(n*sizeof(struct point_struct));` you may post it as an answer, i'll accept it. thank you for your time. – Shahriar.M Sep 05 '15 at 22:24

0 Answers0