Pregunta

I have to transfer a number of elements of type: typedef struct { float w; int a, b; } edge; to different processes, hence I am creating an MPI derived type like this:

unsigned int typecount;
MPI_Datatype PEDGE, types[2] = { MPI_FLOAT, MPI_INT };
MPI_Aint offsets[2], extent;
int blocklen[2] = { 1, 2 };

typecount     = 2;
offsets[0]    = 0;
MPI_Type_extent(MPI_FLOAT, &extent);
offsets[1]    = (1*extent);
MPI_Type_struct (typecount, blocklen, offsets, types, &PEDGE);
MPI_Type_commit(&PEDGE);

When I do a sizeof(edge) I get 12 bytes, but I am getting only 8 bytes when I do sizeof(PEDGE)...why is that? Apart from this, my code for sending some elements of PEDGE type to arrays of edge type are failing, probably because of this mismatch.

¿Fue útil?

Solución

The problem here is that an MPI_Datatype object such as PEDGE is not itself the new datatype, merely an opaque handle to some implementation-specific entity that MPI can interpret as a datatype. As such, sizeof() will not be able to return its accurate size. Use MPI_Type_size() instead.

As for the sends failing, I can't say much without seeing your code, but your datatype definition does look correct.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top