Section Transfer of Handles defines methods for converting handles to integers of the type MPI_Fint. In order to provide this functionality without depending on the behavior of the Fortran compiler, new functions that convert handles to and from int are necessary. Because these functions depend only on C language features, they are not referred to as C-Fortran conversion functions but handle serialization functions.
In the C ABI, handles are pointers and therefore applications can trivially serialize handles into the type intptr_t using a cast, but this does not support use cases where a language integer type is narrower than this.
Rationale.
While it is possible to implement this functionality outside of MPI,
e.g. using a lookup table or hash function,
it is possible to implement more efficiently within an MPI
implementation, particularly if the implementation is already
using a limited range of values for C handles.
An implementation may also store the integer associated with
a C handle, in which case the lookup is trivial.
( End of rationale.)
C binding
(MPI_Comm comm) MPI_Comm_toint
MPI_COMM_TOINT
The function MPI_Comm_toint translates a C communicator handle into a C integer. For all predefined handles, the integer value must be the same as the values listed in Section Language Bindings Summary. For user-defined handles, the implementation must return the same integer for every call to this function with the same handle, which does not conflict with the reserved range for predefined handles. It is erroneous to call this function with an invalid handle argument.
(int comm) MPI_Comm_fromint
MPI_COMM_FROMINT
The function MPI_Comm_fromint translates a C integer to the appropriate C communicator handle. Only an integer obtained from a previous call to MPI_Comm_toint may be passed to this function. It is erroneous to pass to this function an integer associated with a handle that has been freed, disconnected, or aborted (or that was derived from a session that has been finalized).
Similar functions are provided for the other types of opaque objects.
(int datatype) MPI_Type_fromint
MPI_TYPE_FROMINT
(MPI_Datatype datatype) MPI_Type_toint
MPI_TYPE_TOINT
(int group) MPI_Group_fromint
MPI_GROUP_FROMINT
(MPI_Group group) MPI_Group_toint
MPI_GROUP_TOINT
(int request) MPI_Request_fromint
MPI_REQUEST_FROMINT
(MPI_Request request) MPI_Request_toint
MPI_REQUEST_TOINT
(int file) MPI_File_fromint
MPI_FILE_FROMINT
(MPI_File file) MPI_File_toint
MPI_FILE_TOINT
(int win) MPI_Win_fromint
MPI_WIN_FROMINT
(MPI_Win win) MPI_Win_toint
MPI_WIN_TOINT
(int op) MPI_Op_fromint
MPI_OP_FROMINT
(MPI_Op op) MPI_Op_toint
MPI_OP_TOINT
(int info) MPI_Info_fromint
MPI_INFO_FROMINT
(MPI_Info info) MPI_Info_toint
MPI_INFO_TOINT
(int errhandler) MPI_Errhandler_fromint
MPI_ERRHANDLER_FROMINT
(MPI_Errhandler errhandler) MPI_Errhandler_toint
MPI_ERRHANDLER_TOINT
(int message) MPI_Message_fromint
MPI_MESSAGE_FROMINT
(MPI_Message message) MPI_Message_toint
MPI_MESSAGE_TOINT
(int session) MPI_Session_fromint
MPI_SESSION_FROMINT
(MPI_Session session) MPI_Session_toint
MPI_SESSION_TOINT
Within the context of the ABI, where the layout of the status object is known and representable directly in terms of C int, no serialization functionality is necessary.