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. Note that in Fortran MPI_BOTTOM is not usable for initialization or assignment, see Section Named Constants.
The address of a location in memory can be found by invoking the procedure MPI_GET_ADDRESS. The relative displacement between two absolute addresses can be calculated with the procedure MPI_AINT_DIFF. A new absolute address as sum of an absolute base address and a relative displacement can be calculated with the procedure MPI_AINT_ADD. To ensure portability, arithmetic on absolute addresses should not be performed with the intrinsic operators ``-'' and ``+''. See also Sections Absolute Addresses and Relative Address Displacements and Correct Use of Addresses on pages Absolute Addresses and Relative Address Displacements and Correct Use of Addresses.
Rationale.
Address sized integer values, i.e., MPI_Aint or
INTEGER(KIND=MPI_ADDRESS_KIND) values, are signed integers, while
absolute addresses are unsigned quantities. Direct arithmetic on addresses
stored in address sized signed variables can cause overflows, resulting in
undefined behavior.
( End of rationale.)
MPI_GET_ADDRESS(location, address) | |
IN location | location in caller memory (choice) |
OUT address | address of location (integer) |
Returns the (byte) address of location.
Rationale.
In the mpi_f08 module, the location argument is not defined
with INTENT(IN) because existing applications may use
MPI_GET_ADDRESS as a
substitute for MPI_F_SYNC_REG, which was not defined before MPI-3.0.
( End of rationale.)
Example
Using MPI_GET_ADDRESS for an array.
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
Sections Problems With Fortran Bindings for MPI--Comparison with C.
( End of advice to users.)
To ensure portability, arithmetic on MPI addresses must be
performed using the MPI_AINT_ADD
and MPI_AINT_DIFF procedures.
MPI_AINT_ADD(base, disp) | |
IN base | base address (integer) |
IN disp | displacement (integer) |
MPI_AINT_ADD produces a new MPI_Aint value that is equivalent to the sum of the base and disp arguments, where base represents a base address returned by a call to MPI_GET_ADDRESS and disp represents a signed integer displacement. The resulting address is valid only at the process that generated base, and it must correspond to a location in the same object referenced by base, as described in Section Correct Use of Addresses. The addition is performed in a manner that results in the correct MPI_Aint representation of the output address, as if the process that originally produced base had called:
MPI_AINT_DIFF(addr1, addr2) | |
IN addr1 | minuend address (integer) |
IN addr2 | subtrahend address (integer) |
MPI_AINT_DIFF produces a new MPI_Aint value that is equivalent to the difference between addr1 and addr2 arguments, where addr1 and addr2 represent addresses returned by calls to MPI_GET_ADDRESS. The resulting address is valid only at the process that generated addr1 and addr2, and addr1 and addr2 must correspond to locations in the same object in the same process, as described in Section Correct Use of Addresses. The difference is calculated in a manner that results in the signed difference from addr1 to addr2, as if the process that originally produced the addresses had called (char *) addr1 - (char *) addr2 on the addresses initially passed to MPI_GET_ADDRESS.
The following auxiliary procedures provide useful information on derived datatypes.
MPI_TYPE_SIZE(datatype, size) | |
IN datatype | datatype to get information on (handle) |
OUT size | datatype size (integer) |
MPI_TYPE_SIZE set the value of size to 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. For both procedures, if the OUT parameter cannot express the value to be returned (e.g., if the parameter is too small to hold the output value), it is set to MPI_UNDEFINED.