4.12.10. Interlanguage Communication


Up: Language Interoperability Next: Error Handlers Previous: Constants

The type matching rules for communications in MPI are not changed: the datatype specification for each item sent should match, in type signature, the datatype specification used to receive this item (unless one of the types is MPI_PACKED). Also, the type of a message item should match the type declaration for the corresponding communication buffer location, unless the type is MPI_BYTE or MPI_PACKED. Interlanguage communication is allowed if it complies with these rules.


Example In the example below, a Fortran array is sent from Fortran and received in C.


! FORTRAN CODE 
REAL R(5) 
INTEGER TYPE, IERR, MYRANK 
INTEGER(KIND=MPI_ADDRESS_KIND) ADDR 

! create an absolute datatype for array R CALL MPI_GET_ADDRESS( R, ADDR, IERR) CALL MPI_TYPE_CREATE_STRUCT(1, 5, ADDR, MPI_REAL, TYPE, IERR) CALL MPI_TYPE_COMMIT(TYPE, IERR)

CALL MPI_COMM_RANK( MPI_COMM_WORLD, MYRANK, IERR) IF (MYRANK.EQ.0) THEN CALL MPI_SEND( MPI_BOTTOM, 1, TYPE, 1, 0, MPI_COMM_WORLD, IERR) ELSE CALL C_ROUTINE(TYPE) END IF


/* C code */ 

void C_ROUTINE(MPI_Fint *fhandle) { MPI_Datatype type; MPI_Status status;

type = MPI_Type_f2c(*fhandle);

MPI_Recv( MPI_BOTTOM, 1, type, 0, 0, MPI_COMM_WORLD, &status); }

MPI implementors may weaken these type matching rules, and allow messages to be sent with Fortran types and received with C types, and vice versa, when those types match. I.e., if the Fortran type INTEGER is identical to the C type int, then an MPI implementation may allow data to be sent with datatype MPI_INTEGER and be received with datatype MPI_INT. However, such code is not portable.



Up: Language Interoperability Next: Error Handlers Previous: Constants


Return to MPI-2 Standard Index

MPI-2.0 of July 18, 1997
HTML Generated on August 11, 1997