Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: [OMPI users] Difficulty with MPI_Unpack
From: Prentice Bisbal (prentice_at_[hidden])
Date: 2010-02-07 22:40:55


Hello, everyone. I'm having trouble packing/unpacking this structure:

typedef struct{
  int index;
  int* coords;
}point;

The size of the coords array is not known a priori, so it needs to be a
dynamic array. I'm trying to send it from one node to another using
MPI_Pack/MPI_Unpack as shown below. When I unpack it, I get this error
when unpacking the coords array:

[fatboy:07360] *** Process received signal ***
[fatboy:07360] Signal: Segmentation fault (11)
[fatboy:07360] Signal code: Address not mapped (1)
[fatboy:07360] Failing at address: (nil)

Any idea what I'm doing wrong here? Any help/advice will be greatly
appreciated. I've compared my code to Pacheco's book and a few other
examples online, and everything looks okay. I'm sure I'm overlooking
something minor and trivial.

--
Prentice
if (rank == 0) {
    /* assign values to a_point */
    position = 0;
    buffer = malloc(4 * sizeof(int));
    buff_size = (4 * sizeof(int));
    MPI_Pack(&a_point.index, 1, MPI_INT, buffer, buff_size, &position,
MPI_COMM_WORLD);
    MPI_Pack(a_point.coords, 3, MPI_INT, buffer, buff_size, &position,
MPI_COMM_WORLD);
    MPI_Send(buffer, buff_size, MPI_PACKED, 1, 0, MPI_COMM_WORLD);
    }
}
if (rank == 1) {
    buffer = malloc(4 * sizeof(int));
    buff_size = (4 * sizeof(int));
    MPI_Recv(buffer, buff_size, MPI_PACKED, 0, 0, MPI_COMM_WORLD, &status);
    position = 0;
    MPI_Unpack(buffer, buff_size, &position, &b_point.index, 1, MPI_INT,
MPI_COMM_WORLD);
    printf("b_point.index = %i\n", b_point.index);
    /*everything works up to this point! */
    MPI_Unpack(buffer, buff_size, &position, b_point.coords, 3, MPI_INT,
MPI_COMM_WORLD);    /*
    printf("b_point.coords = (%i, %i, %i)\n", b_point.coords[0],
b_point.coords[1], b_point.coords[2]);
  }