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.