Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPI Different methods to find displacements

Tags:

c++

mpi

Assume that i have a struct type as follows:

typedef struct {
 float x, y, z;
 float velocity;
 int  n, type;
} Particle;

I want to send it. I have to create an MPI_Type. I know 4 ways to do it. I listed them below. I want to know what are the differences, limits and benefits of them.

  1. Using MPI_Type_extent

  2. Using offsetof() in stddef.h, it was explained in this answer: MPI Derived Type Send answer

  3. Using MPI_Get_address, also an example in the same answer.

  4. Using reinterpret_cast<const unsigned char*>, i didn't try but there is an example here: MPI Create Custom Data

like image 922
yossarianlives Avatar asked Apr 01 '14 08:04

yossarianlives


1 Answers

Option 1 is wrong as per the answer you linked.

Option 2 is the most straightforward, and has the advantage of being a constant expression rather than a function call.

Options 3 and 4 are probably functionally identical, but 3 is safer. Consider:

Advice to users.

C users may be tempted to avoid the usage of MPI_GET_ADDRESS and rely on the availability of the address operator &. Note, however, that & cast-expression is a pointer, not an address. ISO C does not require that the value of a pointer (or the pointer cast to int) be the absolute address of the object pointed at --- although this is commonly the case. Furthermore, referencing may not have a unique definition on machines with a segmented address space. The use of MPI_GET_ADDRESS to "reference" C variables guarantees portability to such machines as well. ( End of advice to users.)

Source: http://www.mpi-forum.org/docs/mpi-2.2/mpi22-report/node74.htm

Personally, I'd go with option 3, just to make absolutely sure that the values obtained will be compatible with the other MPI calls. You may want to whip up a function or macro similar to offsetof() that uses MPI_Get_address() internally.

like image 53
suszterpatt Avatar answered Oct 12 '22 09:10

suszterpatt