73. Address and Size Functions

Up: Derived Datatypes Next: Lower-Bound and Upper-Bound Markers Previous: Distributed Array Datatype Constructor

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(location, address)
IN locationlocation in caller memory (choice)
OUT addressaddress of location (integer)

int MPI_Get_address(void *location, MPI_Aint *address)

<type> LOCATION(*)

{ MPI::Aint MPI::Get_address(void* location) (binding deprecated, see Section Deprecated since MPI-2.2 ) }
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) 
   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 datatypedatatype (handle)
OUT sizedatatype size (integer)

int MPI_Type_size(MPI_Datatype datatype, int *size)

{ int MPI::Datatype::Get_size() const (binding deprecated, see Section Deprecated since MPI-2.2 ) }
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.

Up: Derived Datatypes Next: Lower-Bound and Upper-Bound Markers Previous: Distributed Array Datatype Constructor

Return to MPI-2.2 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-2.2 of September 4, 2009
HTML Generated on September 10, 2009