The displacements in a general datatype are relative to some initial buffer address. Absolute addresses can be substituted for these displacements: we treat them as displacements relative to ``address zero,'' the start of the address space. This initial address zero is indicated by the constant MPI_BOTTOM. Thus, a datatype can specify the absolute address of the entries in the communication buffer, in which case the buf argument is passed the value MPI_BOTTOM.
The address of a location in memory can be found by invoking the
function
MPI_GET_ADDRESS.
MPI_GET_ADDRESS(location, address) | |
IN location | location in caller memory (choice) |
OUT address | address of location (integer) |
int MPI_Get_address(void *location, MPI_Aint *address)
MPI_GET_ADDRESS(LOCATION, ADDRESS, IERROR)
<type> LOCATION(*)
INTEGER IERROR
INTEGER(KIND=MPI_ADDRESS_KIND) ADDRESS
MPI::Aint MPI::Get_address(void* location)
This function replaces MPI_ADDRESS, whose use is deprecated. See also Chapter Deprecated Functions
.
Returns the (byte) address of location.
Advice to users.
Current Fortran MPI codes will run unmodified, and will port to any
system. However, they may fail if addresses larger than 232 -1
are used in the program. New codes should be written so that they use
the new functions. This provides compatibility
with C/C++ and avoids errors on 64 bit architectures. However, such
newly written codes may need to be (slightly) rewritten to port to old
Fortran 77 environments that do not support KIND
declarations.
( End of advice to users.)
Example
Using MPI_GET_ADDRESS for an array.
REAL A(100,100) INTEGER(KIND=MPI_ADDRESS_KIND) I1, I2, DIFF CALL MPI_GET_ADDRESS(A(1,1), I1, IERROR) CALL MPI_GET_ADDRESS(A(10,10), I2, IERROR) DIFF = I2 - I1 ! The value of DIFF is 909*sizeofreal; the values of I1 and I2 are ! implementation dependent.
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.)
Advice to users.
To prevent problems with the argument copying and register optimization done
by Fortran compilers, please note the hints in subsections ``Problems Due to
Data Copying and Sequence Association,'' and ``A Problem with
Register Optimization''
in Section Problems With Fortran Bindings for MPI
on
pages Problems Due to Data Copying and Sequence Association
and A Problem with Register Optimization
.
( End of advice to users.)
The following auxiliary function provides useful information on
derived datatypes.
MPI_TYPE_SIZE(datatype, size) | |
IN datatype | datatype (handle) |
OUT size | datatype size (integer) |
int MPI_Type_size(MPI_Datatype datatype, int *size)
MPI_TYPE_SIZE(DATATYPE, SIZE, IERROR)
INTEGER DATATYPE, SIZE, IERROR
int MPI::Datatype::Get_size() const
MPI_TYPE_SIZE returns the total size, in bytes, of the entries in
the type signature
associated with datatype; i.e., the total size of
the data in a message that would be created with this datatype. Entries that
occur multiple times in the datatype are counted with their multiplicity.